Re: monthNumber (was: Create a folder with today's date...)
Re: monthNumber (was: Create a folder with today's date...)
- Subject: Re: monthNumber (was: Create a folder with today's date...)
- From: Nigel Garvey <email@hidden>
- Date: Mon, 11 Feb 2002 13:47:47 +0000
Richard Morton wrote on Mon, 11 Feb 2002 14:55:11 +1100:
>
French Vanilla is still faster, though not dramatically.
>
>
My current version of it uses the mod suggested by someone (I know I have
>
it written down somewhere...) here last year.
It was Richard Hartman. :-)
>
I don't think it makes
>
much difference to the speed, but it's slightly smaller:
>
>
on monthNum from dateObj
>
copy dateObj to dateTemp
>
set month of dateTemp to January
>
return (1 + (dateObj - dateTemp) div 2.5E+6)
>
end monthNum
The original return line (using Richard M's variable names) was:
return 1 + (dateObj - dateTemp + 1314864) div 2629728
Emmanuel's brilliant insight was to calculate the number of seconds from
the beginning of the year to the beginning of the month, add in half of
one twelfth of a solar year to get safely inside the calendar month (away
from the uncertainties at the border caused by the different month
lengths), then divide by one twelfth of a solar year and add 1 to get the
month number.
Richard H's modification gets rid of an addition by simply dividing the
time to the beginning of the month by the length of the shortest month
(28 * days = 2419200 seconds). In fact, you can use any number between 28
* days and 29.5 * days (2548800 seconds), the latter being the average
length of a short February and the month before it. Richard M's figure is
the roundest number in that range. ;-)
Another way to lose an addition from Emmanuel's original line would be to
add in one and a half twelfths of a solar year instead of just half a
twelfth. This would save having to add the 1 at the end:
return (dateObj - dateTemp + 3944592) div 2629728
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.