Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Using the ITimeZone interface

This section includes sample code for the following scenarios using the ITimeZone interface:

  • Get active timezone
  • Set active timezone

Get active timezone

Sample code for obtaining the active timezone is shown below (proper error handling is left as an exercise for the user).

ISettings* piSettings = 0;
 ITimeZone* piTimeZone = 0;
 int nErr;
   
// Assumption: piEnv is a valid IEnv pointer
nErr = IEnv_CreateInstance(piEnv, AEECLSID_TimeZone, (void **)&piTimeZone);
if (AEE_SUCCESS != nErr) {
      // Handle error here.
}

nErr = IEnv_CreateInstance(piEnv, AEECLSID_SettingsReg, (void **)&piSettings);
if (AEE_SUCCESS != nErr) {
      // Handle error here.
}

// Assumption: 'name' is a character buffer with sufficient allocated 
// space to hold the output from     
// ISetting_Get()
nErr = ISettings_Get(piSettings, "/timezone/active/tzid", name, nameLen,
            &nameLenReq);
if (AEE_SUCCESS != nErr) {
      // Handle error here.
}

// Use the 'name' in any ITimeZone API to obtain information
// about the timezone.
// Assumption: latitude and longitude are defined properly
nErr = ITimeZone_GetLocation(piTimeZone, name, &latitude, &longitude);
if (AEE_SUCCESS != nErr) {
      // Handle error here.
}

 //Release the objects we created
   IQI_RELEASEIF(piSettings);
   IQI_RELEASEIF(piTimeZone);

Set active timezone

To set the active timezone to "Los Angeles," the following "Set" sample code is used instead of the "Get" operation above.

nErr = ISettings_Set(piSettings, "/timezone/active/tzid",
            “America/Los Angeles”);
if (AEE_SUCCESS != nErr) {
      // Handle error here.
}