Re: a question about coding calendar dates
- Posted by _tom (admin) Dec 03, 2013
- 1397 views
Here's an idea to try.
"Unix" time is seconds since an arbitrary start date. Functions make is possible to convert to and from Unix time.
Using seconds should make it easier for you to calculate the exact duration for each prescription.
include std/console.e include std/datetime.e -- prescription details integer tabs = 75 -- tabs per issue integer reps = 2 -- refills allowed integer dailydose = 4 -- tabs per day -- today's date datetime today_cal = now() atom today_unix = to_unix( today_cal ) display( "\t today's date is:") display( today_cal ) display( "\n============\n" ) atom sec_in_day = 24 * 60 * 60 -- hours * minutes * seconds datetime refill_day_cal atom days_to_consumed atom usable_days_to_consumed atom seconds_to_consumed atom refill_day_unix sequence msg = { "initial issue", "first refill", "second refill", "third refill", $ } for dispense = 0 to reps do days_to_consumed = tabs*dispense / dailydose usable_days_to_consumed = floor( days_to_consumed ) seconds_to_consumed = usable_days_to_consumed * sec_in_day refill_day_unix = today_unix + seconds_to_consumed refill_day_cal = from_unix( refill_day_unix ) display( "\t" & msg[dispense+1] ) display( refill_day_cal ) end for atom consumed_all_tabs = (tabs* (reps+1) )/dailydose * sec_in_day atom max_time_prescription_unix = today_unix + consumed_all_tabs datetime max_time_cal = from_unix( max_time_prescription_unix ) display( "\n maximum duration of prescription") display( max_time_cal )