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



The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), when used with:
    • Microsoft Windows CE Toolkit for Visual C++ 6.0
  • Microsoft Windows CE Operating System, Versions 2.11

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.

MORE INFORMATION

Steps to reproduce the behavior

  1. From a device running Windows CE, click the Start menu, and click Settings, Control Panel, and World Clock.
  2. Select Home City as Singapore (Singapore) and click OK.
  3. Using the Windows CE MFC AppWizard (exe), create a dialog-based application.
  4. 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);
    						
  5. Build for H/PC Pro 2.11 and run the application on the device.
  6. Click the button on the dialog box.
An incorrect date appears in the MessageBox.

Modification Type:MinorLast Reviewed:3/9/2006
Keywords:kbBug kbLocalization kbpending KB240940