views:

66

answers:

2

I'm processing an IMAP mailbox and running into trouble parsing the dates using the mxDateTime package. In particular, early dates like "Fri, 1 Jan 1904 00:43:25 -0400" is causing trouble:

>>> import mx.DateTime
>>> import mx.DateTime.ARPA
>>> mx.DateTime.ARPA.ParseDateTimeUTC("Fri, 1 Jan 1904 00:43:25 -0400").gmtoffset()
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
Error: cannot convert value to a time value
>>> mx.DateTime.ARPA.ParseDateTimeUTC("Thu, 1 Jan 2009 00:43:25 -0400").gmtoffset()
<mx.DateTime.DateTimeDelta object for '-08:00:00.00' at 1497b60>
>>> 

Note that an almost identical date from 2009 works fine. I can't find any description of date limitations in mxDateTime itself. Any ideas why this might be?

Thx,

Ramon

+2  A: 

Is it possible that the mxDateTime object only handles datetimes which fall after the Unix Epoch?

Amber
Theortically now; one of the claimed features of this package is that it handles this. From the docs intro at http://www.egenix.com/products/python/mxBase/mxDateTime/mxDateTime.pdf: "Apart from handling dates before the Unix epoch (1.1.1970) they also correctly work with dates beyond the Unix time limit (currently with Unixtime values being commonly encoded using 32bit integers, the limit is reached in 2038) and thus is Year 2000 and Year 2038 safe."
Ramon
Well, never hurts to check - try passing it a date in 1970, and then 1969?
Amber
Looks like that was it: >>> mx.DateTime.ARPA.ParseDateTimeUTC("Thu, 1 Jan 1970 00:43:25 -0400").gmtoffset() <mx.DateTime.DateTimeDelta object for '-08:00:00.00' at 1497b60> >>> mx.DateTime.ARPA.ParseDateTimeUTC("Wed, 1 Jan 1969 00:43:25 -0400").gmtoffset() Traceback (most recent call last): File "<interactive input>", line 1, in <module> Error: cannot convert value to a time value
Ramon
(I can't get markup to work in these replies -- are replies plain text only?)
Ramon
There's some markup that works in comments - **bold** (enclosing text in double asterisks: `**bold**`), *italic* (single asterisks: `*italic*`), and `code` (backticks `\`code\``).
Amber
A: 

Figured it out with the help of the eGenix folks. It is an Epoch problem, but you can work around it by manually extracting the timezone offset and then re-applying explicitly:

>>> s = "Wed, 1 Jan 1969 00:43:25 -0400"
>>> delta = ParseDateTime(s) - ParseDateTimeUTC(s)
Traceback (most recent call last):
 File "<interactive input>", line 1, in <module>
 NameError: name 'ParseDateTime' is not defined
>>> delta = mx.DateTime.ARPA.ParseDateTime(s) - mx.DateTime.ARPA.ParseDateTimeUTC(s)
>>> mx.DateTime.ARPA.str(mx.DateTime.ARPA.ParseDateTime(s), delta)
'Wed, 01 Jan 1969 00:43:25 -0400'
>>>

Thanks everyone!

Ramon