12-19-2006, 02:07 AM

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.

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.

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: