Re: The latest AS date and AS Editor bugs
Re: The latest AS date and AS Editor bugs
- Subject: Re: The latest AS date and AS Editor bugs
- From: Shane Stanley <email@hidden>
- Date: Thu, 13 Jun 2013 09:51:47 +1000
On 13/06/2013, at 6:38 AM, Nigel Garvey <email@hidden> wrote:
The thing is, of course, that AS dates don't (yet) support time zones or (as required for your argument) daylight saving times.
They're using time zones in so far as the underlying values are all effectively GMT and offset by the user's time zone -- it's just daylight savings they are fudging.
Your script's date mathematics are correct according to the long-standing spec, but there's the anomaly that the system borrowed to format the date strings to local preferences _does_ now include time zone.
Well we should know what that system is, courtesy of the 10.6 AS Release Notes: CFDateFormatterCreateDateFromString. That means they are producing an NSDate and converting that to/from an AS date. The real problem, therefore, is likely to be in the conversion between AS date and NSDate.This is either something which slipped past the AppleScript people responsible or they were gambling that no-one would use dates earlier than December 1847 or include the time zone in their medium date strings.
Yep. If you leave out the time zone, you might think the result was wrong and be tempted to throw in the DST difference to "correct" it. That would, I think, give the result we see. If the returned date was displayed using a formatter fixed to the non-DST time difference -- which is how the dates seem to be created -- there would be no difference for the "correction". Yes indeed. But one-liners are possible:
tell (current date) to set {knownMonday, year, its month, day, time} to {it, 1000, 1, 6, 0}
Nice. FWIW, if anyone wants to play with it in AppleScriptObjC, these two handlers seem to do the conversion:
on makeNSDateFrom_(theASDate) set refDate to date "Friday, 1 January 1904 0:00:00 +1000" as date set theDiff to theASDate - refDate - 3.061152E+9 - (time to GMT) + (current application's NSTimeZone's localTimeZone()'s daylightSavingTimeOffset()) as real set newDate to current application's NSDate's dateWithTimeIntervalSinceReferenceDate_(theDiff) return newDate end makeNSDateFrom_
on makeASDateFrom_(theNSDate) set refDate to date "Friday, 1 January 1904 0:00:00 +1000" as date set theDiff to theNSDate's timeIntervalSinceReferenceDate() return refDate + theDiff div 1 - 3.061152E+9 + (time to GMT) - (current application's NSTimeZone's localTimeZone()'s daylightSavingTimeOffset()) as real end makeASDateFrom_
|
_______________________________________________
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