1. [DOS]: Help with a date() problem
- Posted by Alex Caracatsanis <sunpsych at ncable.co?.a?> Nov 08, 2007
- 475 views
I'd appreciate some help coding for the following problem: I have a client who commenced a "self-improvement activity" at 00:01am on 1 July 2007. In order to give him "encouragement" for persisting with the activity, he would like to have a program that he can run each day, that will display: "It's now day <x> of your activiy! Keep going!", where <x> increments with each passing day. We'll assume that he persists every day without fail, and that he can run the program any number of times on any one day (so that if he ran the program at 6am, midday, and 10pm on 2 July 2007, he would see "It's now day 2 of your activity! Keep going!"). I thought of using date() like this...
constant DAY_ZERO = 181 -- represents 30 June 07, the 181st day of this year constant DAY_NUM = 8 sequence today integer dayNumber, daysOnActivity today = date() dayNumber = today[DAY_NUM] daysOnActivity = dayNumber - DAY_ZERO printf( 1, "It's now day %d of your activity!", daysOnActivity )
... but I'll have a problem from 1 Jan 08, which is day 1! Thanks for any suggestions. Alex Caracatsanis
2. Re: [DOS]: Help with a date() problem
- Posted by Derek Parnell <ddparnell at big?o?d.com> Nov 08, 2007
- 474 views
Alex Caracatsanis wrote: > > I'd appreciate some help coding for the following problem: Have at look at David Money's date routines. http://www.rapideuphoria.com/datetime2.zip -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell
3. Re: [DOS]: Help with a date() problem
- Posted by CChris <christian.cuvier at agricult?re.?ouv.fr> Nov 08, 2007
- 508 views
Alex Caracatsanis wrote: > > I'd appreciate some help coding for the following problem: > > I have a client who commenced a "self-improvement activity" at 00:01am > on 1 July 2007. In order to give him "encouragement" for persisting with the > activity, he would like to have a program that he can run each day, that > will display: "It's now day <x> of your activiy! Keep going!", where <x> > increments with each passing day. We'll assume that he persists every day > without fail, and that he can run the program any number of times on any one > day (so that if he ran the program at 6am, midday, and 10pm on 2 July 2007, > he would see "It's now day 2 of your activity! Keep going!"). > > I thought of using date() like this... > > }}} <eucode> > constant DAY_ZERO = 181 -- represents 30 June 07, the 181st day of this year > constant DAY_NUM = 8 > > sequence today > integer dayNumber, daysOnActivity > > today = date() > dayNumber = today[DAY_NUM] > daysOnActivity = dayNumber - DAY_ZERO > > printf( 1, "It's now day %d of your activity!", daysOnActivity ) > </eucode> {{{ > > ... but I'll have a problem from 1 Jan 08, which is day 1! > > Thanks for any suggestions. > > Alex Caracatsanis
function days_in_year(integer year) -- year = actual year - 1900 if and_bits(year,3) then return 365 elsif remainder(year,100) then return 366 -- extra day else -- secular years usually don't have an extra day, -- but quadrisecular years have return 365 + (remainder(year,400)=100) end if end function -- this is valid as long as dates are using the gregorian calendar function num_of_days (integer start_day,integer start_year,integer end_day,integer end_year) -- number of elapsed days, including both ends integer result -- start from Jan 1st of start_year result = end_day for i=start_year to end_year-1 do result += days_in_year(i) end for -- and then remove start_day return result - start_day + 1 end function constant DAY_ONE = 182, YEAR_ONE = 2007-- represent 01 July 07, the 182nd day of that year constant DATE_DAY_NUM = 8, DATE_YEAR = 1 sequence today integer dayNumber, daysOnActivity, this_year today = date() dayNumber = today[DATE_DAY_NUM] thisYear = today[DATE_YEAR] daysOnActivity = num_of_days(DAY_ONE,YEAR_ONE,dayNumber,thisYear) printf( 1, "It's now day %d of your activity!", daysOnActivity )
CChris