mktime, how to handle dates before 01-01-1970 ?
M.-A. Lemburg
mal at egenix.com
Wed Oct 7 08:13:08 EDT 2009
Christian Heimes wrote:
> Ben Finney wrote:
>> If you're committed to changing the epoch anyway, I would recommend
>> using <URL:http://en.wikipedia.org/wiki/Astronomical_year_numbering>
>> (epoch at 4004 BCE) since it is widely used to unify dates referring to
>> human history.
>
> I prefer JDN or MJD (http://en.wikipedia.org/wiki/JDN) for dates long
> before or after the unix epoch. The conversion from JDN as float to a
> datetime object is trivial.
FWIW, mxDateTime can help you with all of those:
>>> import mx.DateTime
>>> mx.DateTime.DateTimeFrom('1.1.4004 BCE')
<mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b534a46a2f0>
>>> mx.DateTime.DateTimeFrom('1.1.4004 BCE').jdn
258994.5
>>> mx.DateTime.DateTimeFromJDN(258994.5)
<mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b534aeb72f0>
>>> mx.DateTime.DateTimeFrom('1.1.4004 BCE').mjd
-2141006.0
>>> mx.DateTime.DateTimeFromMJD(-2141006.0)
<mx.DateTime.DateTime object for '-4003-01-01 00:00:00.00' at 2b534a46a2f0>
The supported date range is limited by the number of days
that fit into a C long. Should be enough for most use cases :-)
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Oct 07 2009)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-list
mailing list