Creating a User-Defined Time Zone from an Existing Time Zone

This tutorial describes how a client uses CTzUserData to manage user data. CTzLocalizer enables a client to get existing localized time zone names.

The steps for a client to create a user-defined TZ from an existing TZ are described in the Procedure section.

  1. Include the header files that contain the CTzLocalizer and CTzUserData classes.
  2. Include a numeric time zone ID. This is supplied by the UI layer.
  3. Get the localized TZ names for the existing time zone (specified by the TZID) using CTzLocalizer::GetLocalizedTimeZoneL(TInt) .
  4. Create a user-defined TZ names object using CTzUserNames::NewL() .
  5. Connect to the TZ Server using RTz::Connect() .
  6. Get all the TZ rules for the existing time zone using RTz::GetTimeZoneRulesL() .
  7. Create the user-defined TZ using CTzUserData::CreateL() .

This is illustrated in the code example that follows.

       #include <tzlocalizer.h> // For CTzLocalizer etc.
#include <tz.h> // For CTzUserData etc.
#include <…>


// This numeric TZID would typically be supplied by the UI layer.
TInt existingTzId = 1234;

// Get localized TZ names for existing TZ.
CTzLocalizer* tzLocalizer = CTzLocalizer::NewL();
CTzLocalizedTimeZone* localizedTz = tzLocalizer-> GetLocalizedTimeZoneL( existingTzId );
CTzLocalizedCity* localizedCity = tzLocalizer-> GetDefaultCityL( localizedTz );
CTzLocalizedCityGroup* localizedGroup = tzLocalizer-> GetCityGroupL( localizedCity->GroupId() );

// Create user-defined TZ names object.
CTzUserNames* tzNames = CTzUserNames::NewL( localizedTz->StandardName(),
                                            localizedGroup ->Name() );

// Connect to TZ Server.
RTz tzServer;
User::LeaveIfError( tzServer.Connect() );

// Get the TZ rules for the existing TZ.
CTzId* tzId = CTzId::NewL( existingTzId );
TTime startTime( TDateTime( 0,EJanuary,0,0,0,0,0 ) );       // Get all the
TTime endTime( TDateTime( 9999,EDecember,30,23,59,59,0 ) ); // TZ rules.
CTzRules* tzRules = tzServer.GetTimeZoneRulesL( *tzId,
                                                ETzUtcTimeReference );

// Create user-defined TZ.
CTzUserData* tzUserData = CTzUserData::NewL( tzServer );
CTzId* userTzId = tzUserData->CreateL( *tzRules, *tzNames );

Related information
Subscribe and Respond to TZ Data Changes