开发者

Can't parse a 1904 date in ARPA format (email date)

I'm processing an IMAP m开发者_C百科ailbox 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


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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜