• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Issues subtracting Unix epoch from date
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issues subtracting Unix epoch from date


  • Subject: Re: Issues subtracting Unix epoch from date
  • From: Nathan Vander Wilt <email@hidden>
  • Date: Sat, 20 Feb 2010 17:00:11 -0800

On Feb 20, 2010, at 4:04 PM, Shane Stanley wrote:
On 21/2/10 7:10 AM, "Nathan Vander Wilt" <email@hidden> wrote:

But I'm getting the impression that within an AppleScript script itself, dates
are stored (and *calculated*!) internally just as the class is writable
externally: four numbers YMD+S and some elementary calendar assumptions.
(Thanks Shane for corroborating on this.)

No, that's not so. It's stored as the number of seconds since some date
(January 1, 1904, rings a bell). It just has no concept of time zone, so you
need to treat it accordingly.


With the information from you and Deivy, I tested things further:

=== SCRIPT ===
property unixEpoch : (date "Thursday, January 1, 1970 12:00:00 AM") + (time to GMT)

to internalISO8601(theDate)
((theDate - (time to GMT)) as «class isot» as string) & "Z"
end internalISO8601

to externalISO8601(theDate)
tell application "System Events"
local thePlist, theXML
make new property list item with properties {value:theDate}
set thePlist to text of result
make new XML data with properties {text:thePlist}
set theXML to result
get the first XML element of the first XML element of theXML
get value of result
end tell
end externalISO8601

set summerDate to date "Saturday, June 30, 2007 5:05:00 PM"
set winterDate to date "Saturday, February 20, 2010 1:00:00 AM"
log internalISO8601(unixEpoch) -- > (*1970-01-01T00:00:00Z*)
log externalISO8601(unixEpoch) --> (*1970-01-01T00:00:00Z*)
log internalISO8601(winterDate) --> (*2010-02-20T09:00:00Z*)
log externalISO8601(winterDate) --> (*2010-02-20T09:00:00Z*)
log internalISO8601(summerDate) --> (*2007-07-01T01:05:00Z*) *** wrong!
log externalISO8601(summerDate) --> (*2007-07-01T00:05:00Z*) *** right!!
log summerDate - unixEpoch --> (*1.1832519E+9*) *** wrong...ish
=== /SCRIPT ===


So Mark *is* right when he says that AppleScript converts dates to a POSIX timestamp using just the current value of Standard Addition's (time to GMT).

*BUT* it also seems to correct this issue when sending the date to an external app like System Events or iPhoto. I wonder if this is consistent across previous versions of OS X.

o_O,
-natevw
 _______________________________________________
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

References: 
 >Re: Issues subtracting Unix epoch from date (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Issues subtracting Unix epoch from date
  • Next by Date: Re: Issues subtracting Unix epoch from date
  • Previous by thread: Re: Issues subtracting Unix epoch from date
  • Next by thread: Re: Issues subtracting Unix epoch from date
  • Index(es):
    • Date
    • Thread