Okay, group, I'm opening this up for discussion...
Is my routine wrong, or is the test flawed?
This test works fine at my house, U.S. Mountain Standard Time.
When I change my Windows time zone to Brisbane, it fails here like it does
for Mark.
The test is:
<Python>
def testDateObjectFromCOMDate(self):
cmd=self.tc.DateObjectFromCOMDate(37435.7604282)
t1=time.gmtime(time.mktime((2002,6,28,12,14,1,
4,31+28+31+30+31+28,-1)))
t2=time.gmtime(time.mktime((2002,6,28,12,16,1,
4,31+28+31+30+31+28,-1)))
assert t1<cmd<t2, '"%s" should be about 2002-6-28
12:15:01'%repr(cmd)
</Python>
The code under test is:
<Python>
> def DateObjectFromCOMDate(self,comDate):
> 'Returns ticks since 1970'
> if isinstance(comDate,datetime.datetime):
> return comDate.timetuple()
> elif isinstance(comDate,DateTime):
> fcomDate = comDate.ToOADate()
> else:
> fcomDate = float(comDate)
> secondsperday=86400 # 24*60*60
> #ComDate is number of days since 1899-12-31, gmtime epoch is
> 1970-1-1 = 25569 days
> t=time.gmtime(secondsperday*(fcomDate-25569.0))
> return t
> #year,month,day,hour,minute,second,weekday,julianday,daylightsaving=t
>
</Python>
I don't want to re-invent the wheel here. Does one of you gurus have better
code?
--
Vernon
On Tue, Feb 3, 2009 at 9:32 PM, Mark Hammond <[email protected]>wrote:
> Thanks Vernon,
>
> I seem to be having issues with 2.x which I can't put down to the pywin32
> changes - the failures relate to use of the time module.
>
>
>
> Default Date Converter is <adodbapi.pythonDateTimeConverter object at
> 0x0294B530>
>
> ...............F.................................
>
> ======================================================================
>
> FAIL: testDateObjectFromCOMDate (__main__.TestPythonTimeConverter)
>
> ----------------------------------------------------------------------
>
> Traceback (most recent call last):
>
> File "adodbapitest.py", line 671, in testDateObjectFromCOMDate
>
> assert t1<cmd<t2, '"%s" should be about 2002-6-28 12:15:01'%repr(cmd)
>
> AssertionError: "time.struct_time(tm_year=2002, tm_mon=6, tm_mday=28,
> tm_hour=18, tm_min=15, tm_sec=0, tm_wday=4, tm_yday=179, tm_isdst=0)" should
> be about 2002-6-28 12:15:01
>
>
>
> ----------------------------------------------------------------------
>
> Ran 49 tests in 1.281s
>
>
>
> FAILED (failures=1)
>
> Changed dateconverter to
>
> <adodbapi.pythonTimeConverter object at 0x029C31F0>
>
> ...............F.................................
>
> ======================================================================
>
> FAIL: testDateObjectFromCOMDate (__main__.TestPythonTimeConverter)
>
> ----------------------------------------------------------------------
>
> Traceback (most recent call last):
>
> File "adodbapitest.py", line 671, in testDateObjectFromCOMDate
>
> assert t1<cmd<t2, '"%s" should be about 2002-6-28 12:15:01'%repr(cmd)
>
> AssertionError: "time.struct_time(tm_year=2002, tm_mon=6, tm_mday=28,
> tm_hour=18, tm_min=15, tm_sec=0, tm_wday=4, tm_yday=179, tm_isdst=0)" should
> be about 2002-6-28 12:15:01
>
>
>
> ----------------------------------------------------------------------
>
>
>
> I suspect it is timezone related: FYI:
>
>
>
> >>> import adodbapi
>
> >>> tc=adodbapi.pythonTimeConverter()
>
> >>> tc.DateObjectFromCOMDate(37435.7604282)
>
> time.struct_time(tm_year=2002, tm_mon=6, tm_mday=28, tm_hour=18, tm_min=15,
> tm_sec=0, tm_wday=4, tm_yday=179, tm_isdst=0)
>
> >>> time.gmtime(time.mktime(_))
>
> time.struct_time(tm_year=2002, tm_mon=6, tm_mday=28, tm_hour=8, tm_min=15,
> tm_sec=0, tm_wday=4, tm_yday=179, tm_isdst=0)
>
>
>
> If you get the same result as me in that last line I think the fix should
> be easy…
>
>
_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32