[admin edit] These posts split from topic Looking for way to set alarm to ToDo (list) / external app?
I have been assuming, wrongly, that Tinderbox, like some other applications, stores an ISO date-time string that doesn’t change just because I change the time zone in Date & Time Preferences on the Mac.
Created
for a sample note, for example, changes from “2019-07-03T16:01:26+08:00” to “2019-07-03T04:01:26-04:00” when I switch the time zone from Taipei to Boston. These are equivalent, of course, as shown by converting both to coordinated universal time. (I assume a similar conversion to UTC is easily done in JavaScript, perhaps built-in).
AppleScript to convert to UTC (click to reveal)
to convertToAsDateUTC(isoDate)
set text item delimiters to {"-", "T", "+"}
set asDate to current date -- a "placeholder" date; actual values substituted in below
tell isoDate's text items to set {asDate's year, asDate's month, asDate's day} to {item 1, item 2, item 3}
tell isoDate's text item 4 to set asDate's time to hours * (word 1) + minutes * ((word 2) + (word 3) / 60)
set asDate to asDate + hours * (isoDate's text 20 thru 22) * -1 # time zone offset
end convertToAsDateUTC
-- TEST -----------------------------------------------------------
set strDate1 to "2019-07-03T16:01:26+08:00"
set strDate2 to "2019-07-03T04:01:26-04:00"
set asDate1 to convertToAsDateUTC(strDate1)
set asDate2 to convertToAsDateUTC(strDate2)
return {asDate1, asDate2}
That I think means the time zone in which a note was created, if important, needs to be tracked in other ways and the original local date and time, if important, needs to be reconstructed. Fair enough, now that I think I understand it.
But as @ComplexPoint suggests, summer time and its effect on historical dates is a knotty problem. How does JavaScript deal with that? Can both AppleScript and JavaScript access NSDate and NSCalendar?