mktime, how to handle dates before 01-01-1970 ?

Christian Heimes lists at cheimes.de
Wed Oct 7 09:02:51 EDT 2009


M.-A. Lemburg schrieb:
> 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 :-)

Nice ... :) I didn't know that mxDateTime has support for Julian Date.

Christian



More information about the Python-list mailing list