• 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 15:26:39 -0800

On Feb 20, 2010, at 3:04 PM, Mark J. Reed wrote:
> On Sat, Feb 20, 2010 at 5:51 PM, Nathan Vander Wilt
> <email@hidden> wrote:
>> The way the calculations are done does matter! How many seconds are there between the Unix epoch and 2007-June-30 17:05:00 PDT?
>
> Well, 1,183,248,323, but POSIX doesn't bother to count the 23 of them
> that were leap seconds
>
>> AppleScript:
>> property unixEpoch : (date "Thursday, January 1, 1970 12:00:00 AM") + (time to GMT)
>> log (date "Saturday, June 30, 2007 5:05:00 PM") - unixEpoch
>> --> (*1.1832519E+9*)
>>
>> Cocoa:
>> NSDate* date = [NSDate dateWithNaturalLanguageString:@"Saturday, June 30, 2007 5:05:00 PM"];
>> printf("%f\n", [date timeIntervalSince1970]);
>> --> 1183248300.000000
>>
>> So AppleScript says 1183251900 seconds, while Cocoa gives the correct answer of 1183248300 seconds.
>
> So when interpreting the date string, it looks like AppleScript is
> internally converting it to a POSIX timestamp using the current value
> of (time to GMT).  That is . . . unfortunate.


No, I think the problem is actually in the subtraction.

When I use change that  System Events property list hack I just posted with:
set theDate to date "Saturday, June 30, 2007 5:05:00 PM"

the result is:
2007-07-01T00:05:00Z
That is, it did correctly treat the date as PDT (GMT-7).

Whereas when I use current date, ie "Saturday, February 20, 2010 3:16:28 PM" the result is "2010-02-20T23:16:28Z". This is correct for PST (GMT-8).

And when I convert unixEpoch, the result is indeed "1970-01-01T00:00:00Z".

This implies that AppleScript must not be subtracting POSIX dates internally to do its calendar math, and strengthens my suspicion that AppleScript's date class stores local calendar YMD+S values internally and does elementary school calculations directly on the calendar values. The conversion to a POSIX time (or rather, a LongDateTime with a 1904 epoch) seems to only happen when AppleScript needs to send a date in an event to another application.

thanks,
-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: 
 >Issues subtracting Unix epoch from date (From: Nathan Vander Wilt <email@hidden>)
 >Re: Issues subtracting Unix epoch from date (From: "Mark J. Reed" <email@hidden>)
 >Re: Issues subtracting Unix epoch from date (From: Nathan Vander Wilt <email@hidden>)
 >Re: Issues subtracting Unix epoch from date (From: "Mark J. Reed" <email@hidden>)
 >Re: Issues subtracting Unix epoch from date (From: Nathan Vander Wilt <email@hidden>)
 >Re: Issues subtracting Unix epoch from date (From: "Mark J. Reed" <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