Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Parsing ISO date/time strings - where did the parser go?

Reply
Thread Tools

Parsing ISO date/time strings - where did the parser go?

 
 
John Nagle
Guest
Posts: n/a
 
      09-09-2012
On 9/8/2012 5:20 PM, John Gleeson wrote:
>
> On 2012-09-06, at 2:34 PM, John Nagle wrote:
>> Yes, it should. There's no shortage of implementations.
>> PyPi has four. Each has some defect.
>>
>> PyPi offers:
>>
>> iso8601 0.1.4 Simple module to parse ISO 8601 dates
>> iso8601.py 0.1dev Parse utilities for iso8601 encoding.
>> iso8601plus 0.1.6 Simple module to parse ISO 8601 dates
>> zc.iso8601 0.2.0 ISO 8601 utility functions

>
>
> Here are three more on PyPI you can try:
>
> iso-8601 0.2.3 Flexible ISO 8601 parser...
> PySO8601 0.1.7 PySO8601 aims to parse any ISO 8601 date...
> isodate 0.4.8 An ISO 8601 date/time/duration parser and formater
>
> All three have been updated this year.


There's another one inside feedparser, and there used to be
one in the xml module.

Filed issue 15873: "datetime" cannot parse ISO 8601 dates and times
http://bugs.python.org/issue15873

This really should be handled in the standard library, instead of
everybody rolling their own, badly. Especially since in Python 3.x,
there's finally a useful "tzinfo" subclass for fixed time zone
offsets. That provides a way to directly represent ISO 8601 date/time
strings with offsets as "time zone aware" date time objects.

John Nagle
 
Reply With Quote
 
 
 
 
Roy Smith
Guest
Posts: n/a
 
      09-09-2012
In article <k2h3n2$213$(E-Mail Removed)>, John Nagle <(E-Mail Removed)>
wrote:

> This really should be handled in the standard library, instead of
> everybody rolling their own, badly.


+1
 
Reply With Quote
 
 
 
 
Mark Lawrence
Guest
Posts: n/a
 
      09-09-2012
On 09/09/2012 11:15, Roy Smith wrote:
> In article <k2h3n2$213$(E-Mail Removed)>, John Nagle <(E-Mail Removed)>
> wrote:
>
>> This really should be handled in the standard library, instead of
>> everybody rolling their own, badly.

>
> +1
>


I'll second that given "There should be one-- and preferably only one
--obvious way to do it".

--
Cheers.

Mark Lawrence.

 
Reply With Quote
 
Roy Smith
Guest
Posts: n/a
 
      09-09-2012
In article <(E-Mail Removed)>,
Thomas Jollans <(E-Mail Removed)> wrote:

> The ISO date/time format is dead simple and well-defined.


Well defined, perhaps. But nobody who has read the standard could call
it "dead simple". ISO-8601-2004(E) is 40 pages long.

Of course, that fact that it's complicated enough to generate 40 pages
worth of standards document just argues that much more strongly for it
being in the standard lib (so there can be one canonical, well-tested,
way to do it).
 
Reply With Quote
 
Pete Forman
Guest
Posts: n/a
 
      09-12-2012
John Nagle <(E-Mail Removed)> writes:

> I want to parse standard ISO date/time strings such as
>
> 2012-09-09T18:00:00-07:00
>
> into Python "datetime" objects.


Consider whether RFC 3339 might be a more suitable format.

It is a subset of ISO 8601 extended format. Some of the restrictions are

Year must be 4 digits
Fraction separator is period, not comma
All components including time-offset are mandatory, except for time-secfrac
time-minute in time-offset is not optional, must use ±hh:mm or Z

Some latitude is allowed

T may be replaced by e.g. space

Extra feature

time-offset of -00:00 means UTC but local time is unknown

--
Pete Forman
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
I did the run, cmd thing, and my video actually did mess up. The Maitch Computer Support 0 04-25-2005 11:37 PM
cisco t1 isdn call to DID or DID no ring tone optimus Cisco 1 12-31-2003 04:35 PM



Advertisments