In addition to providing access to the various Outlook folder objects, the IPOutlookApp interface has two support functions that are used for handling time zone information. The first function, IPOutlookApp::GetTimeZoneInformationFromIndex(), uses the standard Windows CE TIME_ZONE_INFORMATION structure to retrieve time zone information. The function is defined as follows: HRESULT IPOutlookApp::GetTimeZoneInformationFromIndex(int cTimezone, TIME_ZONE_INFORMATION *ptzInfo); The Pocket Outlook Object Model also provides the ITimeZone interface, which is used for retrieving information about daylight savings time for a particular time zone. To get a pointer to the ITimeZone object, you can use the following function: HRESULT IPOutlookApp::GetTimeZoneFromIndex(int cTimezone, ITimeZone **ppTz); The first parameter is the index to the time zone that you are interested in, and is followed by a pointer to a pointer value that will be filled in with the ITimeZone interface. Table 10.3 describes the properties supported by the ITimeZone interface.
The following short code example shows how you can get time zone information for Pacific Standard Time: // Get the time zone information for PST ITimeZone *pTimeZone = NULL; hr = pOlApp->GetTimeZoneFromIndex(4, &pTimeZone); if(FAILED(hr)) OutputDebugString(TEXT("Could not get the calendar folder")); else { TCHAR tchDaylightStart[256] = TEXT("\0"); TCHAR tchStandardStart[256] = TEXT("\0"); // Figure out daylight savings time BSTR bstrName = NULL; SYSTEMTIME stDaylight; VARIANT_BOOL vbDate; hr = pTimeZone->get_DaylightName(&bstrName); if(FAILED(hr)) return FALSE; // PST uses a relative date, but let's just make sure pTimeZone->get_IsDaylightAbsoluteDate(&vbDate); if(vbDate == VARIANT_FALSE) { DATE pDaylight = NULL; LONG lDayOfWeek = 0, lMonth = 0, lDayInstance = 0; // Get the date if(FAILED(pTimeZone->get_DaylightDayOfWeekMask (&lDayOfWeek))) return FALSE; if(FAILED(pTimeZone->get_DaylightInstance (&lDayInstance))) return FALSE; if(FAILED(pTimeZone->get_DaylightMonthOfYear(&lMonth))) return FALSE; // Get the time if(FAILED(pTimeZone->get_DaylightDate(&pDaylight))) return FALSE; // Fill out the structure: memset(&stDaylight, 0, sizeof(SYSTEMTIME)); VariantTimeToSystemTime(pDaylight, &stDaylight); wsprintf(tchDaylightStart, TEXT("%s\r\nDaylight Savings Time will begin:\r\nWeek: %d\r\nDay of Week: %d\r\nMonth: %d\r\nat %d:%d"), bstrName, lDayOfWeek, lDayInstance, lMonth, stDaylight.wHour, stDaylight.wMinute); } else { // Place absolute date handler stuff here } // MessageBox MessageBox(NULL, tchDaylightStart, TEXT("Daylight"), MB_OK); // Free resources SysFreeString(bstrName); } if(pTimeZone) pTimeZone->Release(); |