Re: Date computation
Re: Date computation
- Subject: Re: Date computation
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 07 Jan 2005 12:43:22 -0800
On 1/7/05 12:01 PM, "Michelle Steiner" <email@hidden> wrote:
>> It doesn't matter how many weeks have passed since that "known
>> Wednesday" in
>> 1900 - dividing (the number of seconds resulting from subtracting that
>> Wednesday date from any other date) by 'weeks' (i.e. 7 * 24 * 60 * 60
>> seconds) will be the mod remainder: the number of seconds since the
>> most
>> recent Wednesday midnight.
>
> That part is not getting through. "b" is the 14th of the month, and
> we're subtracting a known Wednesday (BTW, we could just as easily use
> Dec 31, 2003, the most recent Wednesday known to be in the past), so
> where do we get the most recent Wednesday from?
set secondWednesday to b - (b - (date "Wednesday, 1 January 1000
00:00:00")) mod weeks
The known Wednesday is subtracted from the second b . That leaves a very
large number of seconds representing the number of seconds since the known
Wednesday. Dividing that (div) by 'weeks' (7 * 24 * 60 * 60 seconds) would
give us the number of weeks since that known Wednesday (which we don't care
about) up to the _most recent Wednesday_ (which we do care about), with the
remainder left over (mod) being the number of seconds since this most recent
Wednesday. So subtracting that remainder of seconds from b again (the first
b), gives us the most recent Wednesday. All this depends on the fact that
the whole number division by 'weeks' will necessarily be a whole number of
weeks after the known Wednesday. We don't care how many weeks, but we do
care that the "ending point" IS a whole number of weeks, and so must
represent a Wednesday too.
It seems that the order of prioritization of arithmetic operators
(subtraction vs. mod) means that the statement is the same as:
set secondWednesday to b - ((b - (date "Wednesday, 1 January 1000
00:00:00")) mod weeks)
which might make it just a bit clearer. I'm sorry if I'm getting pedantic,
but I'm not sure which bit you're missing, so I'm probably not explaining it
too well.
I imagine that Nigel was using a saved routine where he'll sometimes want to
get a date in the 20th century rather than your particular request for
today. I'm not sure that the computer tales any longer to go back to 1900
than to 2003 when doing its subtraction and division.
>
>>>>> tell b to set {day, day} to {32, 14}
>>>
>>> And I certainly don't understand that.
>>
>>
>> That looks like a typical Nigel trick. I think that if you try to set
>> the
>> day of any date to 32 AppleScript gives you the 1st of the succeeding
>> month
>> - it saves a LOT of computation.
>
> Now, *that* did get through. It's brilliant, even if obscure and
> esoteric. Thanks.
>
> However, it sets it to the first only if the current month has 31 days;
> it sets it to the 2nd from a 30-day month; to the third from Feb in a
> leap year, and to 4 in all other Febs.
True. I got that wrong that when I said "1st of the month" previously.
> But those differences won't
> make a difference, because the goal is to set the month to the next
> month; the day doesn't matter, because it's going to be set to 14 right
> afterwards.
Right.
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden