Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
another date challenge
#11
Aga:
I guess what you consider interesting is a description of the DayofWeek routine so here it goes. I don't know who invented it but it gave me a good headache to figure how does it work.

Code:
FUNCTION DayofWeek (y, m, D)
  '0=monday
  DIM P, Q
  IF m > 2 THEN
    P = m - 3
    Q = y
  ELSE
    P = m + 9
    Q = y - 1
  END IF
DayofWeek = (D + 1 + Q + Q \ 4 - Q \ 100 + Q \ 400 + CINT(2.6 * P)) MOD 7
END FUNCTION

It uses modular arithmetics to add offsets modulo 7 from a theoretical (gregorian) march 1th of the year zero. If that day existed it was a wednedsday. And it uses a shifted year (Q variable) starting at march 1. The monhts are also shifted, month 0 is march and month 11 is february.

If you divide 365 by 7 you get a remainder of 1, so if you don't count leap years, every year advances a date by 1 position in the week. So we have a +Q in the formula. the +Q\4-Q\100+\400 part provide for the leap year's additional offsets.

Then it comes the serious part, the reason why we use a shifted year.
CINT(2.6*P) provides for the month of year offset. The effect of the fp operation plus rounding makes this factor add 3 days (31-28) for april (month 1), 5 days for may, 8 days for june... and so on, including the irregularity of august and september that require 3 days for each. February has been noved to the end of the year so its different behavior in leap years must not be considered in this step.

Then the formula adds the Day of month (+D) and a 1 to center the things and make the result of 0 a monday .

Hope it helps...

Moneo:
In my last post I was obviously not speaking about the same soccer game as you. In fact i found about the Barça- America in the net after re-reading yout post . I'm not very interested in soccer, you see...

And for the explanation of the DayofWeek routine, my memory failed, we spoke about it at Pete's site, not at Foronet.



Quote:
Antoni
Reply


Messages In This Thread
another date challenge - by Agamemnus - 12-11-2006, 11:04 PM
another date challenge - by DrV - 12-12-2006, 03:44 AM
another date challenge - by Agamemnus - 12-13-2006, 01:02 AM
another date challenge - by DrV - 12-14-2006, 12:41 AM
Re: another date challenge - by Moneo - 12-14-2006, 06:36 AM
another date challenge - by Agamemnus - 12-16-2006, 01:23 AM
another date challenge - by Antoni Gual - 12-16-2006, 01:47 AM
another date challenge - by Moneo - 12-18-2006, 08:48 AM
another date challenge - by Antoni Gual - 12-18-2006, 10:26 PM
another date challenge - by Agamemnus - 12-19-2006, 12:07 AM
another date challenge - by Antoni Gual - 12-19-2006, 02:07 AM
another date challenge - by Agamemnus - 12-25-2006, 06:13 AM
another date challenge - by Antoni Gual - 12-25-2006, 03:30 PM
another date challenge - by Moneo - 12-26-2006, 01:00 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)