[Zope] - Some DateTime behaviors I just don't understand

skip@calendar.com (Skip Montanaro) skip@calendar.com (Skip Montanaro)
Wed, 6 Jan 1999 22:00:59 -0500


I tried:

    dt = DateTime.DateTime(time.time())
    dt.timeTime()

and got just what I expected:

    915677129.19

I then tried

    dt = DateTime.DateTime(0.0)
    dt.timeTime()

and got a traceback:

    Traceback (innermost last):
      File "<stdin>", line 1, in ?
      File "DateTime/DateTime.py", line 874, in timeTime
	raise self.DateTimeError,'No time module compatible time to return'
    DateTimeError: No time module compatible time to return

Surely 0.0 is a valid time module compatible time:

    time.gmtime(0.0)
    (1970, 1, 1, 0, 0, 0, 3, 1, 0)

Can I not initialize a DateTime object to the Unix epoch?  I tried several
multiples of 10.0 and didn't avoid the traceback until I tried

    dt = DateTime.DateTime(100000.0)

which is somewhat more than one day more recent than gmtime(0.0).

There's apparently some magnitude-dependent interpretation of single numeric
initializers, but the documentation file in the package is unclear on how it
distinguishes between the two interpretations:

    A DateTime object is returned that represents either the gmt value of
    the time.time() float represented in the local machine's timezone, or
    that number of days after January 1, 1901. Note that the number of days
    after 1901 need to be expressed from the viewpoint of the local
    machine's timezone. A negative argument will yield a date-time value
    before 1901.

While horsing around some more, I got some other strange behavior as well:

    >>> time.gmtime(24*60*60)
    (1970, 1, 2, 0, 0, 0, 4, 2, 0)
    >>> dt = DateTime.DateTime(24*60*60)
    >>> dt.timeTime()
    86400
    >>> dt = DateTime.DateTime(24*60*50)
    >>> dt.timeTime()
    72000
    >>> dt = DateTime.DateTime(24*60*40)
    >>> dt.timeTime()
    57600
    >>> dt = DateTime.DateTime(24*60*30.0)
    Traceback (innermost last):
      File "<stdin>", line 1, in ?
      File "DateTime/DateTime.py", line 513, in __init__
	s=(_j-int(_j))*86400.0
    OverflowError: float too large to convert
    >>> dt.timeTime()
    57600
    >>> dt = DateTime.DateTime(24*60*30)  
    Traceback (innermost last):
      File "<stdin>", line 1, in ?
      File "DateTime/DateTime.py", line 513, in __init__
	s=(_j-int(_j))*86400.0
    OverflowError: float too large to convert

Why would I be getting overflow errors as the numbers got smaller?

Skip Montanaro	   | Mojam: "Uniting the World of Music" http://www.mojam.com/
skip@calendar.com  | Musi-Cal: http://concerts.calendar.com/
518-372-5583