Microsoft KB Archive/240940

= BUG: CTime class methods return an incorrect date for some time zones for Windows CE Version 2.11 =

Article ID: 240940

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft Foundation Class Library 4.2, when used with:
 * Microsoft Windows CE Toolkit for Visual C++ 6.0
 * Microsoft Windows CE 2.11 for the Handheld PC

-



This article was previously published under Q240940



SYMPTOMS
The following code returns an incorrect date when the time zone is set to a non-United States time, such as Singapore, Australia, Japan, or England: CTime ctCur = CTime::GetCurrentTime; CString csMsg; csMsg.Format(_T("%d / %d / %d"), ctCur.GetYear, ctCur.GetMonth, ctCur.GetDay); AfxMessageBox(csMsg); This behavior occurs only on devices running Windows CE version 2.11. This behavior cannot be reproduced on the emulation or earlier versions of Windows CE 2.0 or 2.01.



CAUSE
The data type (time_t) of the wce_GetTZBias function's parameter pTZBiasSecs is not correct. The date type (time_t) is defined as "unsigned long". However, *pTZBiasSec can be negative. For example, if Beijing time is GMT-8, *pTZBiasSec should be -8*60*60. static void wce_GetTZBias(time_t* pTZBiasSecs = NULL, int* pDSTBiasSecs = NULL) Thus, when the set time zone has a negative BiasSec, wce_GetTZBias returns a large number for pTZBiasSecs. Because it changed a negative int to an unsigned int, the wrong Date is returned for some time zones when calling CTime::GetCurrentTime or CTime::GetYear.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.



Steps to reproduce the behavior
 From a device running Windows CE, click the Start menu, and click Settings, Control Panel, and World Clock. Select Home City as Singapore (Singapore) and click OK. Using the Windows CE MFC AppWizard (exe), create a dialog-based application.  Add a button to the dialog box and in the handler for the button's BN_CLICKED message add the following code:

CTime ctCur = CTime::GetCurrentTime; CString csMsg; csMsg.Format(_T("%d / %d / %d"), ctCur.GetYear, ctCur.GetMonth, ctCur.GetDay); AfxMessageBox(csMsg);  Build for H/PC Pro 2.11 and run the application on the device. Click the button on the dialog box.</li></ol>

An incorrect date appears in the MessageBox.

Additional query words: CTime, GetYear, GetTZBias, GetLocalTm, wce_GetTZBias

Keywords: kbbug kblocalization kbpending KB240940

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.