Re: Date computation
Re: Date computation
- Subject: Re: Date computation
- From: Nigel Garvey <email@hidden>
- Date: Fri, 7 Jan 2005 18:54:18 +0000
Michelle Steiner wrote on Fri, 7 Jan 2005 09:44:14 -0700:
>On Jan 7, 2005, at 3:56 AM, Nigel Garvey wrote:
>
>> set today to (current date)
>> copy today to b
>> set b's day to 14
>> set secondWednesday to b - (b - (date "Wednesday, 1 January 1000
>> 00:00:00")) mod weeks
>> if secondWednesday is less than or equal to today then
>> tell b to set {day, day} to {32, 14}
>> set secondWednesday to b - (b - (date "Wednesday, 1 January 1000
>> 00:00:00")) mod weeks
>> end if
>> return secondWednesday
>
>Slick, but I can't understand it; care to explain the maths, please?
>
>In reviewing the script, I realized that I failed to specify that if
>today is the second Wednesday, it should return the second Wednesday of
>next month. So what change needs to be made in the script.
Hi, Michelle. It does exactly that on my machine. (That's what the 'if'
block's for.) I don't understand why it's not working properly for you.
The principle is that 'b' is set to the fourteenth of the current month
(the end of the seven-day period in which the second Wednesday occurs).
Midnight on a known Wednesday in the past is subtracted from b and the
result is modulated by 'weeks' to leave the difference between midnight
on most recent Wednesday (ie. the second one of this month) and the
date/time of b. When this is subtracted from b, you're left with the
Wednesday midnight date/time.
If the result is less than or equal to 'today' (and they'll only be equal
if the script is run during the first second of the Wednesday concerned,
after which the result is *less* than 'today'), b is reset to the
fourteenth of the following month and the calculation is done again.
NG
_______________________________________________
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