Re: parsing Unix date
Re: parsing Unix date
- Subject: Re: parsing Unix date
- From: Joshua See <email@hidden>
- Date: Fri, 9 Jan 2004 13:48:10 -0600
On Jan 9, 2004, at 8:48 AM, Michael Grant wrote:
set d to (do shell script "date") --> "Fri Jan 9 01:00:02 CST 2004"
date d --> date "Friday, January 9, 2004 9:01:00 AM"
What's wrong with this picture?
More to the point, how can I transform a Unix date to an AppleScript
date more accurately?
Cut back a bit on the ambiguity so AS knows what part of the date is
which:
date (do shell script "date '+%B %d, %C%y %H:%M:%S'")
The bad news is that this will probably need to be customized for
non-US systems.
On Jan 9, 2004, at 9:41 AM, Craig Sutherland wrote:
For the specific script this came up in, I was able to substitute the
current date function in AppleScript for the Unix date command, but
there will be times when I won't have that option, such as parsing
e-mail headers.
Actually, email date headers are standardized rigorously enough so that
you should be able to just throw them at date and get it right, needing
only to correct the time zone. In psuedocode:
tell application "foo mail client"
set d to every paragraph of (source of current message)
set d to first item of d whose contents starts with "Date:"
set tz to ((text -5 thru -3 of d) as integer) * hours
set d to (date d) - tz + (time to GMT)
end tell
As has been noted on this list, there are bad headers using non-english
month names out there, but those are rare and going to be a headache no
matter what you do. Extra padding characters on the date line may also
be a problem. I didn't use last word because it would lose the + or -.
Lastly, this doesn't handle time zones set in fractions of an hour off
GMT, since I don't know of any.
On Jan 9, 2004, at 8:48 AM, Michael Grant signed:
2. If it's stupid but it works, it's not stupid.
I wouldn't go that far. Functionality and stupidity are non exclusive
in cyberspace or realspace.
--
Sincerely,
Joshua See
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.