Re: Week of year - odd/even week
Re: Week of year - odd/even week
- Subject: Re: Week of year - odd/even week
- From: Nigel Garvey <email@hidden>
- Date: Fri, 1 Feb 2002 13:11:30 +0000
Emmanuel wrote on Fri, 1 Feb 2002 00:05:52 +0100:
>
Below I give the script to compute the first day of the first week of the
>
year which contains theDate.
>
>
------------------------------ tested (was included in Smile's distribution)
>
copy theDate to theFirst
>
set day of theFirst to 1
>
set month of theFirst to January
>
set time of theFirst to 0
>
repeat until (weekday of theFirst) is Thursday
>
set day of theFirst to 1 + (get day of theFirst)
>
end repeat
>
repeat until (weekday of theFirst) is Monday
>
set day of theFirst to 1 + (get day of theFirst)
>
end repeat
>
set theFirst to theFirst - 7 * 86400
>
------------------------------
... which can be simplified to:
copy theDate to theFourth
set day of theFourth to 4
set month of theFourth to January
set theFourth to theFourth - (theFourth - (date "Monday, 6 January 1000
00:00:00")) mod weeks
(If, like me, you think a week starts on a Sunday, change the date in the
fourth line to 5th January 1000.)
Telescoping in the formula for calculating the week number gives:
copy theDate to theFourth
set day of theFourth to 4
set month of theFourth to January
1 + (theDate - theFourth + (theFourth - (date "Monday, 6 January 1000
00:00:00")) mod weeks) div weeks
NG