[DB-SIG] Date-time types
M.-A. Lemburg
lemburg@uni-duesseldorf.de
Thu, 11 Dec 1997 00:45:38 +0100
Before you all start to code your own version of DateTime(),
please wait a few more days and I'll announce the C module
I'm working on right now. It includes the basic type for
date/time representation and some other wrappers of important
functions like strptime() (or maybe a generic one written
from the BSD sources as basis).
It currently can do this:
>>> t = DateTime(729368, 55931.522913)
>>> print t # no specific format, just something to look at :-)
15:32:11 12/10/97 UTC
>>> t.hour
15
>>> t.minute
32
>>> t.second
11
>>> t.year
1997
>>> t.gmtime() # returns a tuple just like time.gmtime()
(1997, 12, 10, 15, 32, 11.522913, 2, 344, 0)
>>> t.strftime('%x %X %A')
'12/10/97 15:32:11 Wednesday'
>>> t.absdate, t.abstime
(729368, 55931.522913)
>>> import time
>>> time.mktime(t.gmtime())
881764331.0
>>> x = time.mktime(t.gmtime())
>>> time.localtime(x)
(1997, 12, 10, 15, 32, 11, 2, 344, 0)
>>> o = strptime('12/10/97 15:32:11','%x %X')
>>> repr(o)
'<DateTime object at 80d3c20>'
>>> o
15:32:11 12/10/97 UTC
>>> o = strptime('12/10/997 15:32:11','%x %X')
Traceback (innermost last):
File "<stdin>", line 1, in ?
DateTime.error: parsing error
Plus there is a C API to access these values in a comfortable
way too. More methods/funtions will be added as time goes...
Note that t.absdate corresponds to the "absolute" date
that Christian Egli uses in his classes, so these are
usable on top of this basic type.
Time calculation can easily be done using the provided
values t.absdate and t.abstime by code written in Python.
--
Marc-Andre Lemburg
_______________
DB-SIG - SIG on Tabular Databases in Python
send messages to: db-sig@python.org
administrivia to: db-sig-request@python.org
_______________