Re: Issues subtracting Unix epoch from date
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 16:27:52 -0800
On Feb 20, 2010, at 4:12 PM, Deivy Petrescu wrote:
>
> On Feb 20, 2010, at 6:06 PM, Nathan Vander Wilt wrote:
>
>> On Feb 20, 2010, at 2:51 PM, Nathan Vander Wilt wrote:
>>> Here's an equivalent to what I need to do:
>>>
>>> 1. Get a date from an application (e.g. tell application "iPhoto" to get date of some photo)
>>> 2. Store a representation to disk, then exit script
>>> 3. Time passes, time zone offset may change.
>>> 4. Start script, load stored representation from disk
>>> 5. Set the *same* date (or a precise adjustment thereof) back to the application
>>>
>>> This is impossible to do with AppleScript's date model. (Or please show how I am wrong?)
>>
>>
>> -- Heh heh heh
>> copy (current date) to 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
>>
>>
>> This is pretty much ridiculous, but it does have the side effect of working. I haven't implemented it yet, but I'm presuming the reverse direction is possible as well. I am considering writing a faceless scriptable Cocoa app to do a more efficient conversion (and one that doesn't rely on a property list item's text to always be XML), but that may be a bit of a pain to deploy.
>>
>> hope this helps,
>> -natevw _______________________________________________
>
>
> Nate,
> you can substitute the code above by
>
> return ((current date) - (time to GMT)) as «class isot» as string
>
>
> Can't guarantee it will not break in the future.
Fascinating tip! So to create an ISO-8601 representation of a date, you can use:
((someDate - (time to GMT)) as «class isot» as string) & "Z"
I'm sure this will come in handy sometime, although I can't seem to convert in the reverse direction.
In this case, however, I need something I can ship in production code. Furthermore, Cocoa itself lacks public support for directly parsing ISO-8601 strings. The code on the other side will be much, much cleaner if I can just read/write the date as one number. A POSIX time would be ideal, but because of the date subtraction bug it's not straightforward in AppleScript.
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