Re: Document A Project

new topic     » goto parent     » topic index » view thread      » older message » newer message

> > > global function dayOfWeek( integer pMonth, integer pDay, integer pYear )
> > > --  This function determines the day of the week given
> > > --  a date in the form Month, Day, Year. I believe this
> > > --  formula may be more accurate than Junko's, or I'd
> > > --  be using Junko's instead. :)
> > > --
> > > --  Step 1: Take the last two digits of the year and add 1/4.
> > > --  Step 2: Determine month code.
> > > --  Step 3: Add year, month code and day
> > > --  Step 4: Take remainder of seven.
> > > --
> > > --  The result is the day of the week (starting with Monday)
> > This line above needs a bit more detail to be helpful. Something like ...
> > 
> >   -- The result is an integer from 1 to 7, where 1 represents Monday,
> >   -- 2 is Tuesday, and so on until we get to 7 for Sunday.
> >  
> > >     integer lCode, lResult
> > > 
> > >     -- subtract 100 until pYear is less than 100
> > 
> > Okay, I read the code and see that this is what you are doing, but *why*
> > are you doing it? What are you trying to achieve by doing this?
> > 
> > How about this sort of thing instead ...
> > 
> >       -- The algorithm only needs the last two digits of the year
> >       -- so we remove the 'century' part, if any, of the supplied year.
> > >     while pYear > 100 do
> > >         pYear -= 100
> > >     end while
> > BTW, we could have done this in one line ...
> > 
> >       pYear = remainder(pYear, 100)
> > 
> > 
> > >     -- add 1/4 to the year
> > Again, I can read the code and you have accurately described what it is
> > doing, but why is it doing this?
> > 
> > >     pYear += floor( pYear / 4 )
> > > 
> > >     -- determine month code, MONTH_CODE
> > >     -- is declared else where in our code
> > Why? And how is it declared elsewhere? 
> > 
> > >     lCode = MONTH_CODE[ pMonth ]
> > > 
> > >     -- add the values
> > Duh! Yes, that's what the code does, but why?
> > 
> > >     lResult = pYear + lCode + pDay
> >  
> > >     -- get remainder of seven and add 1
> > Again this is an accurate description of what the code is doing. But I
> > don't have a clue why? How would I know if this code is right or not?
> > Why '7'? Why add one?
> > 
> >       -- Having calulated the number of days we now divide this into
> >       -- weeks and the left over amount is the offset into a week. We
> >       -- add one to convert the offset into an index, which is then
> >       -- returned to the caller. 
> > >     lResult = remainder( lResult, 7 ) + 1
> > > 
> > >     return lResult
> > > end function



Here's my version of the same thing, probably not documented so well but very
accurate. For the whole thing see my 'moredates' in the archives.



1 the remaining DAYS in this month

2 the remaining days in the remaining months of this year 3 the middle years

4 the days in months of the last year 5 the days in the last month global function get_day(sequence mydate)returns a weekday in the future sequence today,unknown integer totdays,a totdays=find(getday(),DAY) today=parse_date(getdate()) unknown=parse_date(mydate) if getdec(today[3]) > getdec(unknown[3]) then puts(1,mydate&" has passed") elsif getdec(today[3]) < getdec(unknown[3]) then --------------[1] deal with the remaining DAYS of this month-- adj_days_in_month(today[3]) totdays=totdays+DAYS_IN_MONTH[getdec(today[2])]-getdec(today[1]) --------------[2] deal with rest of this year MONTHS---------- adj_days_in_month(today[3]) for x=getdec(today[2])+1 to 12 dodeal with rest of this year totdays=totdays+DAYS_IN_MONTH[x] end for
[3] deal with the middle YEARS (if nescessary)------ for x = getdec(today[3])+1 to getdec(unknown[3])-1 dodeal with middle years a=find(sprintf("%02d",x),LEAPYEAR) if a then totdays=totdays+366 else totdays=totdays+365 end if end for --------------[4] deal with the last months 0f the last year---- adj_days_in_month(unknown[3]) for x=1 to getdec(unknown[2]) -1 dodeal with the months of the last year totdays=totdays+DAYS_IN_MONTH[x] end for
[5] deal with the last days of the last month-- totdays=totdays+getdec(unknown[1])
elsif getdec(today[3]) = getdec(unknown[3]) then if getdec(today[2]) > getdec(unknown[2]) then puts(1,mydate&" has passed") abort(0) elsif getdec(today[2]) < getdec(unknown[2]) then -------------- deal with the remaining DAYS of this month-- adj_days_in_month(today[3]) totdays=totdays+DAYS_IN_MONTH[getdec(today[2])]-getdec(today[1]) --------------deal with the months------- for x=getdec(today[2])+1 to getdec(unknown[2])-1 do totdays=totdays+DAYS_IN_MONTH[x] end for -------------- deal with the last days of the last month-- totdays=totdays+getdec(unknown[1]) elsif getdec(today[2]) = getdec(unknown[2]) then ------------ deal with the remaining DAYS of this month-- totdays=totdays+getdec(unknown[1])-getdec(today[1]) end if end if while totdays>700 do totdays=totdays-700 end while while totdays>70 do totdays=totdays-70 end while while totdays>7 do totdays=totdays-7 end while return LONGDAY[totdays] end function

don cole SF }}}

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu