Re: Conversion of ISO Date String to AppleScript Date
Re: Conversion of ISO Date String to AppleScript Date
- Subject: Re: Conversion of ISO Date String to AppleScript Date
- From: Ed Stockly <email@hidden>
- Date: Sat, 04 Mar 2017 21:41:06 -0800
> On Mar 4, 2017, at 9:02 PM, Ed Stockly <email@hidden> wrote:
>
> Any other dates I should worry about?)
Yes. There are other dates to worry about.
To try to answer my question I ran this script, and it failed miserably. For some reason the runDate variable was inheriting the value of the myDate variable inside the handler.
What’s up with that? I rewrote it, and that returned a list of 70 dates over the next 10 years, each the 31st day of a month.
My faith in AppleScript dates is truly shaken.
——— This script returns an empty list
set badDates to {}
set ISOdateString to "2017-04-04 11:15:15"
set runDate to date "Friday, December 30, 2016 at 12:00:00 AM"
set goodDate to my AppleScriptISODate(ISOdateString, runDate)
repeat with x from 1 to 365 * 3
set runDate to runDate + 1 * days
set appleScriptDate to my AppleScriptISODate(ISOdateString, runDate)
if appleScriptDate is not goodDate then set the end of badDates to appleScriptDate
end repeat
return badDates
on AppleScriptISODate(ISOdateString, mydate)
set {theYear, theMonth, theDay, theHour, theMin, theSec} to words of ISOdateString
set {year of mydate, month of mydate, day of mydate, hours of mydate, minutes of mydate, seconds of mydate} to {theYear as integer, theMonth as integer, theDay as integer, theHour as integer, theMin as integer, theSec as integer}
return mydate
end AppleScriptISODate
——————————— this script returns a list of 70 items
set badDates to {}
set ISOdateString to "2017-04-04 11:15:15"
set runDate to date "Friday, December 30, 2016 at 12:00:00 AM"
copy runDate to myDate
set goodDate to my AppleScriptISODate(ISOdateString, myDate)
repeat with x from 1 to 365 * 10
set runDate to runDate + 1 * days
copy runDate to myDate
set appleScriptDate to my AppleScriptISODate(ISOdateString, myDate)
if appleScriptDate is not goodDate then set the end of badDates to runDate
end repeat
return badDates
on AppleScriptISODate(ISOdateString, myDate)
set {theYear, theMonth, theDay, theHour, theMin, theSec} to words of ISOdateString
set {year of myDate, month of myDate, day of myDate, hours of myDate, minutes of myDate, seconds of myDate} to {theYear as integer, theMonth as integer, theDay as integer, theHour as integer, theMin as integer, theSec as integer}
return myDate
end AppleScriptISODate
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden