[Zope3-dev] datetimeutils: add localize datetime?

Sidnei da Silva sidnei at awkly.org
Tue Feb 1 07:00:20 EST 2005


On Tue, Feb 01, 2005 at 06:43:10AM -0500, Stephan Richter wrote:
| > My questions:
| > does something like this exist already? 
| > If not, anyone mind if I check it into datetimeutils? 
| 
| The right way to do it would be to import a timezone package based on 
| datetime, and implement the necessary lines in zope.i18n.format (around line 
| 105 for parsing and lines 575-586 for formatting). You can see that the code 
| should not be too hard as long as the timezone can give us the following 
| representations: "+000", "+00:00", "UTC" and "Greenwich Time". Of course, 
| there needs to be a function that can give us the timezone for any of the 
| given strings.

Can't we just use the DateUtil module?
https://moin.conectiva.com.br/DateUtil

It looks like it extensible enough to handle the funkiest date
strings, and has full support for timezones, even reading timezone
info from .ics (iCalendar) files and from timezone files on
the operating system.

Some examples from the docs:

>>> s = "Today is 25 of September of 2003, exactly " \
...     "at 10:49:41 with timezone -03:00."
>>> parse(s, fuzzy=True)
datetime.datetime(2003, 9, 25, 10, 49, 41,
                  tzinfo=tzoffset(None, -10800))

Other random formats:

>>> parse("Wed, July 10, '96")
datetime.datetime(1996, 7, 10, 0, 0)

>>> parse("1996.07.10 AD at 15:08:56 PDT", ignoretz=True)
datetime.datetime(1996, 7, 10, 15, 8, 56)

>>> parse("Tuesday, April 12, 1952 AD 3:30:42pm PST", ignoretz=True)
datetime.datetime(1952, 4, 12, 15, 30, 42)

>>> parse("November 5, 1994, 8:15:30 am EST", ignoretz=True)
datetime.datetime(1994, 11, 5, 8, 15, 30)

>>> parse("3rd of May 2001")
datetime.datetime(2001, 5, 3, 0, 0)

>>> parse("5:50 A.M. on June 13, 1990")
datetime.datetime(1990, 6, 13, 5, 50)

-- 
Sidnei da Silva <sidnei at awkly.org>
http://awkly.org - dreamcatching :: making your dreams come true
http://www.enfoldsystems.com
http://plone.org/about/team#dreamcatcher

One tree to rule them all,
One tree to find them,
One tree to bring them all,
and to itself bind them.
	-- Gavin Koch <gavin at cygnus.com>


More information about the Zope3-dev mailing list