Re: Month as Integer, redux
Re: Month as Integer, redux
- Subject: Re: Month as Integer, redux
- From: Nigel Garvey <email@hidden>
- Date: Sun, 8 Apr 2001 01:52:15 +0100
SeaSoft Systems wrote on Sat, 7 Apr 2001 11:07:02 -0700:
>
>> set theDate to the current date
>
>> copy theDate to b
>
>> set the month of b to January
>
>> set monthNum to (1 + (theDate - b + 1314864) div 2629728)
>
>>
>
>> There's something clever going on there, but my math sucks. So hopefully
>
>> someone else can explain this little gem.
>
>
>
>
Having no real life to speak of, I reviewed this and can offer a
>
slightly simpler solution (in the long tradition of incrementally
>
improving on every offering, however brilliant and well-executed). My
>
small modification replaces the "set monthNum..." statement above by:
>
>
set monthNum to (1 + (theDate - b) div N)
>
>
Interestingly, this works for any integer N in the range [2419200 <=
>
N <= 2505600], so you can pick one that suits your fancy. Proof of
>
this is left as an exercise for interested readers who also have no
>
life. (Hint: consider the number of seconds in the shortest month).
Aha! (theDate - b) is always an exact number of days - ie. the number of
days before the month of theDate in the year of theDate
Jan 0
Feb 31
Mar 59 or 60
Apr 90 or 91
May 120 or 121
Jun 151 or 152
Jul 181 or 182
Aug 212 or 213
Sep 243 or 244
Oct 273 or 274
Nov 304 or 305
Dec 334 or 335
All of these numbers div 28 or 29 days (or any fraction in between) yield
the appropriate month number -1.
So what do we call this version? "Vanille Douce de Mer"?
NG