Re: parsing Unix date
Re: parsing Unix date
- Subject: Re: parsing Unix date
- From: Nigel Garvey <email@hidden>
- Date: Mon, 12 Jan 2004 14:33:23 +0000
Joshua See wrote on Sun, 11 Jan 2004 23:44:18 -0600:
>
<sigh>I should have known better. At least nobody called my whose
>
clause on the carpet. The will also fix any potential problems with
>
padding characters on the date header line.
>
>
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 1 thru 2 of last word of d) as integer) * hours
>
set tz to tz + ((text 3 thru 4 of last word of d) as integer) * minutes
>
-- Watch the wrapping.
>
set tz to tz * (character (((length of last word of d) + 1) * -1) of d
>
& "1")
>
set d to (date d) - tz + (time to GMT)
>
end tell
I've been thinking how e-mail header date to AS date might be done on any
machine, no matter how it was configured for date order or language. If
the convention for e-mail headers is that they're in English (is it?),
then the "Date" long header might be converted like this:
set dateLine to "Date: Sat, 10 Jan 2004 22:00:16 -0800"
-- Start with a "1st January" date object
set dateSent to date "1 1"
-- Set the year first, in case its a leap year
set dateSent's year to dateLine's word 5 as integer
-- Add enough days to hit the appropriate month
set dateSent to dateSent + (offset of dateLine's word 4 in
"JanFebMarAprMayJunJulAugSepOctNovDec") div 3 * 32 * days
-- Set the day and time
set dateSent's day to dateLine's word 3 as integer
set dateSent's time to (dateLine's word 6) * hours + (dateLine's word
7) * minutes + (dateLine's word 8)
Adjusting for the time zone difference presents a small problem though.
Looking through the long headers for some of my recent incoming mail,
most dates either end with a sign and four digits, as above, or with a
sign and four digits followed by the time zone initials in brackets:
"Date: Sat, 10 Jan 2004 22:00:16 -0800 (PST)". These are easily handled:
set c to (count dateLine's text 1 thru word 9)
get (dateLine's text (c - 4) thru c) as integer
get result div 100 * hours + result mod 100 * minutes
set myTime to dateSent + ((time to GMT) - result)
But some recent date headers just have "GMT" at the end: "Date: Sun, 11
Jan 2004 06:00:16 GMT". The affected messages are all newsletters and
don't necessarily originate in the UK. I don't know why this is or if
it's peculiar to mail received in the UK or to my ISP, and I can't see
any way to deduce the time zone of origin in these cases. :-\
NG
_______________________________________________
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.