[PythonCE] PyTime/DATE Variant/time module
Mark Hammond
mhammond@skippinet.com.au
Tue, 16 Jul 2002 12:01:08 +1000
> From: pythonce-admin@python.org [mailto:pythonce-admin@python.org]On
> Behalf Of Doug Marien
> Sent: Tuesday, 16 July 2002 5:36 AM
> To: pythonce@python.org
> Subject: [PythonCE] PyTime/DATE Variant/time module
>
>
> I noticed some odd behavior when extending the IContact interface for
> PocketOutlook with the DATE variants. Basically, the year/month
> values are
> correct, but when the time module attempts to make the 1900 correction for
> the year and the +1 for the month, it throws off the real time.
>
> Starting with this code:
>
> DATE daAnniversary;
> HRESULT hr = (self->pContact)->get_Anniversary(&daAnniversary);
> return PyWinObject_FromDATE(daAnniversary);
>
> PyWinObject_FromDATE() comes from pywintypes which will return a PyTime
> object. When converting that to an integer (calling PyTime::asLong), the
> year/month correction throws off the value returned which in turn
> throws off
> the time conversion routines.
>
> From what I can tell, all the time routines work just fine without the
> year/month correction. Are they needed with CE?
I have no idea if they are really needed for CE, but I would be quite
surprised if they were not needed for normal Windows, but were for CE. But
I have been surprised before ;)
The MSDN docs seem to state quite clearly that they are needed.
struct tm docs say:
tm_mon Month (0 – 11; January = 0)
tm_year Year (current year minus 1900)
SYSTEMTIME docs say:
wMonth - Specifies the current month; January = 1, February = 2, and so on.
wYear - Specifies the current year.
These docs imply that the pywintypes code is correct.
> If it is required, then in PyCE_TimeStructToSystemTime, the check for
> whether the year is less than 100 will fail for anything after the year
> 2000.
Possibly - I don't seem to have the latest sources for
PyCE_TimeStructToSystemTime() handy to check. Certainly it is more likely
that bugs exist in that CE specific code than in the shared win32 sources.
The likeliness increases IIRC that I wrote PyCE_TimeStructToSystemTime() ;)
Mark.