472,125 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,125 software developers and data experts.

Comparing RFC1123 based Dates

I would like to parse RFC 1123 date format and compare two dates. I
find that
datetime module does not specifically confirms to any RFC. Any
suggestions as how I can handle the RFC 1123 date format using
standard libraries before I go to re based parsing?

Thanks,
Senthil

Aug 5 '07 #1
3 3169
Phoe6 wrote:
I would like to parse RFC 1123 date format and compare two dates. I
find that
datetime module does not specifically confirms to any RFC. Any
suggestions as how I can handle the RFC 1123 date format using
standard libraries before I go to re based parsing?
Well,
>>import time
timeobj = time.strptime("Thu, 01 Dec 1994 16:00:00 GMT","%a, %d %b %Y %H:%M:%S %Z")
was easy.

Thanks,
Senthil

Aug 5 '07 #2
In article <11**********************@e16g2000pri.googlegroups .com>,
Phoe6 <or*******@gmail.comwrites:
Phoe6 wrote:
I would like to parse RFC 1123 date format and compare two dates. I
find that
datetime module does not specifically confirms to any RFC. Any
suggestions as how I can handle the RFC 1123 date format using
standard libraries before I go to re based parsing?

Well,
>import time
timeobj = time.strptime("Thu, 01 Dec 1994 16:00:00 GMT","%a, %d %b %Y %H:%M:%S %Z")

was easy.
Well, it might have been easy, but it's got several gotchas (in
both Python and C), including:

- The zone field (%Z) only corresponds for the GMT and UT timezones,
which are obsolete (see RFC 2822). There is no support for
the recommended +/-time-offset form.

- The day-of-week (%a) and month (%b) fields in strptime and
strftime are subject to the process's locale, whereas the RFC
time forms are not. Those are hardwired to names that happen
to correspond to the C, POSIX, and probably most of the en_*
locales, but not to others that would be used by billions of
people. Thus anyone using your program who doesn't happen to
reside in one of the English-speaking countries (or does and
is using a native locale) is likely to encounter problems when
using your program.

- The day-of-week field is optional.

- Comments are allowed (but deprecated) in the whitespace fields
of the time format. (On the other hand, I've never seen this
is normal e-mail.)

I find the use of strptime and strftime difficult enough to manage
with Internet date/times that I restrict my use of them to programs
that are limited to processing date/times. Even then, I then
explicitly set the locale (LC_TIME) to the "C" locale. Otherwise,
I use ad hoc code that explicitly recognizes the RFC-defined forms.

--
.. Douglas Wells . Connection Technologies .
.. Internet: -sp9804- -at - contek.com- .
Aug 5 '07 #3
Phoe6 wrote:
I would like to parse RFC 1123 date format and compare two dates. I
find that
datetime module does not specifically confirms to any RFC. Any
suggestions as how I can handle the RFC 1123 date format using
standard libraries before I go to re based parsing?
I realise you want to stick to the standard library. If you decide you
can't however, you should definitely take a look at mx.DateTime, as the
mx.DateTime.ARPA submodule provides exactly what you require.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Aug 5 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Harlan Dorado | last post: by
2 posts views Thread by Duppypog | last post: by
2 posts views Thread by Manny Chohan | last post: by
19 posts views Thread by Dennis | last post: by
12 posts views Thread by colincolehour | last post: by
4 posts views Thread by cheryl | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.