IntroductionISO 8601 describes a standard way to store date time strings, removing ambiguity and dealing with different time zones. The most common form is YYYY-MM-DD HH:MM:SS+TZ, e.g. 2007-01-20 15:30:23+00:00. ISO 8601 date strings are used in many file formats and communication protocols, due to its unambiguous nature and its property of naturally sorting by date. InstallationTo install simple use easy_install: $ easy_install iso8601 Basic UsageUsage is quite simple, just give it a string and it will return a datetime object: >>> import iso8601
>>> iso8601.parse_date("2007-01-25T12:00:00Z")
datetime.datetime(2007, 1, 25, 12, 0, tzinfo=<iso8601.iso8601.Utc object at 0x5b1e10>)
>>> PlansI don't really plan to do a huge amount with this module. Apart from adding new variations of ISO 8601 as I need them I could add some date generation (possibly a create_date() which takes a datetime object). I'd definitely add any patches people send if they come with tests, having a complete ISO 8601 parser would be useful. The only gotcha is I suspect my current regex approach will only sanely scale to a small set of variants.
|
I wrote a module to parse an arbitrary date/time-like string to ISO 8601 format. Seems like with the help of your module, handling date/time converting is an easy thing now. Example:
iso8601.parse_date(formattime.ToLocal?('yesterday')) Out22?: datetime.datetime(2007, 7, 21, 0, 0, tzinfo=<iso8601.iso8601.Utc object at 0xf7dd9ecc>)
iso8601.parse_date(formattime.ToUTC('+25d')) Out23?: datetime.datetime(2007, 8, 16, 7, 0, tzinfo=<iso8601.iso8601.Utc object at 0xf7dd9ecc>)