1. 'stardate' functions (minor update)
- Posted by Ad Rienks <Ad_Rienks at COMPUSERVE.COM> Mar 26, 1997
- 1020 views
- Last edited Mar 27, 1997
-- This is a minor update to the function day2month() I posted earlier -- In line 38 there should be an exit; after the month is found no need to search on -- 'stardate' functions: requested by Joseph Martin -- kwisoft (c) 1997 global constant MONTHS = -- SNIP -<code I found somewhere; sorry to the poster; I don't know who it was> global function isyearleap(integer year) -- Returns 1 if year is a leap year, 0 otherwise. -- Source: "Practical Algorithms for Programmers" -- By: Andrew Binstock and John Rex if not remainder(year,4) = 0 then -- If year not divisible by 4 return 0 -- it's not leap. elsif year < 1582 then -- All years divisible by 4 were return 1 -- leap prior to 1582. elsif remainder(year,100) != 0 then -- If year divisible by 4, return 1 -- but not by 100, its leap. elsif not remainder(year,400) = 0 then -- If year divisible by 100, return 0 -- but not by 400, it's not leap. else return 1 -- If divisible by 400, it's leap. end if end function -- isyearleap -- SNIP ---------------------------------------------------------------- global function day2month(integer day, integer year) sequence result, total_days result = {"ERROR", 0} -- display if input incorrect total_days = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365} if isyearleap(year) then total_days[3..13] = total_days [ 3..13]+ 1 end if for month = 1 to 12 do if day > total_days[month] and day <= total_days[month+1] then result = {MONTHS[month], day - total_days[month]} exit -- leaves the loop if month is found end if end for return result end function -- day2month --------------------------------------------------------------------------- ---- -- test it -- -------------- integer day, year day = 85 year = 1997 printf(1, "Today it is %s %d, %d\n", day2month(day, year) & year) puts(1, "\nPress a key.....\n") while get_key() = -1 do end while --------------------------------------------------------------------------- ---------------------- -- any questions? email me at: AdRienks at compuserve.com -- Good day!