Re: Date computation
Re: Date computation
- Subject: Re: Date computation
- From: cheshirekat <email@hidden>
- Date: Fri, 7 Jan 2005 03:48:27 -0700
On Fri, Jan 7, 20051:18 AM, the following words from Michelle Steiner
email@hidden, emerged from a plethora of SPAM ...
>I'm trying to compute the date of the
>second Wednesday of the current month, and if the current date is later
>than or equal to that date, then compute the date of the second
>Wednesday of the following month.
I'm sure someone has beat me to this, or provided a faster, slicker
method than the below since I usually miss out on some of the fun puzzles.
property monthList : {January, February, March, April, May, June, July,
August, September, October, November, December}
to getNextMonth from the d
set the cMonth to (the month of (the d))
repeat with i from 1 to 12
if the monthList's item i is the cMonth then
if i is 12 then
return {(the monthList's item 1), true}
else
set the nextNum to i + 1
return {(the monthList's item nextNum), false}
end if
end if
end repeat
end getNextMonth
to getSecondWednesday from the cd
set foundIt to false
set the dayUp to the cd
repeat while foundIt is false
set the wkDay to (the weekday of the dayUp)
if the wkDay is Wednesday then
set foundIt to true
return (the dayUp + 7 * days)
else
set the dayUp to (the dayUp + 1 * days)
end if
end repeat
end getSecondWednesday
set the cDate to (the current date)
set {m, d, y} to {the month of the cDate, the day of the cDate, the year
of the cDate}
set the firstDay to (date (" " & m & " " & 1 & ", " & y))
set the secondWed to getSecondWednesday of me from (the firstDay)
if the cDate >= the secondWed then
set the nextMonth to getNextMonth from the cDate
set m to (the nextMonth's item 1)
if nextMonth's item 2 is true then
set ny to y as number
set y to ny + 1
end if
set the firstDay to (date (" " & m & " " & 1 & ", " & y))
set the secWedNextMth to getSecondWednesday of me from (the firstDay)
else
say "Not time yet"
end if
cheshirekat
--
Thus the living, lone and sobbing,
In the throes of anguish throbbing,
With the loathsome Furies robbing
Night and noon of peace and rest.
But beyond the groans and grating
Of abhorrent Life, is waiting
Sweet Oblivion, culminating
All the years of fruitless quest.
-- H.P. Lovecraft, Despair 1919
_______________________________________________
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