Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Using TLocale


Initialization

The TLocale class is used to set and get the system’s locale information. The operating system maintains the locale information internally. On construction, a TLocale object is initialized with the system information for all locale items:

TLocale locale; // locale object
TInt code=locale.CountryCode(); // get country code
TChar thouSep=locale.ThousandsSeparator(); // get thousands separator
// ... etc

[Top]


Changing locale information

If you wish to have an application change the locale information used by that application alone, it may do so with one of the setter calls. Subsequent requests for locale information will return the newly-set values. The system wide settings will not be affected however:

locale.SetThousandsSeparator(TChar('.')); // change setting
// ...
TChar thouSep=locale.ThousandsSeparator(); // get current value

If you wish the changes to affect all other applications, TLocale::Set() should be called to set the locale settings of the entire system:

locale.SetThousandsSeparator(TChar('.')); // change setting
locale.Set(); // transfer settings to the system copy

Normally, this would not be carried out from within an application program, but from within a shell.

If the system settings have changed, and you wish to have your application use the new ones, use Refresh():

locale.Refresh(); // refresh our values from system settings
TChar thouSep=locale.GetThousandsSeparator(); // get current value

[Top]


Workdays

In the following example, on return, result indicates whether Monday is a workday: —

TBool result=locale.Workdays()&(1<<EMonday);

For a list of day name constants, see the TDay enumeration.

[Top]


DaylightSaving

In the following example, on return, result indicates whether daylight saving is in operation in the Southern daylight saving zone: —

TUint daylightSaving=locale.DaylightSaving();
TBool result=daylightSaving&EDstSouthern;

Use QueryHomeHasDaylightSavingOn() rather than DaylightSaving() to get whether daylight saving is in effect for the home city. This is because the daylight saving setting for the home city may differ from that of the zone in which home is located. See the example below.

[Top]


Setting and retrieving daylight saving settings

The following code demonstrates how to set and retrieve daylight saving settings.

First, the daylight saving zone for the home city is set to be the Southern hemisphere, and then daylight saving in the Southern hemisphere is set. In this case, home daylight saving is automatically set also (result1 returns true): —

locale.SetHomeDaylightSavingZone(EDstSouthern);
locale.SetDaylightSaving(EDstSouthern);
TBool result1=locale.QueryHomeHasDaylightSavingOn();
  // result1 returns true

If the user wants to unset daylight saving for the home city, while daylight saving remains in effect in the Southern hemisphere, this can only be done by removing home from the Southern daylight saving zone: —

locale.SetHomeDaylightSavingZone(EDstNone);
  // remove home from Southern daylight saving zone

Now, Southern daylight saving remains set (result2 returns true) but home daylight saving is now unset (result3 returns false): —

TUint daylightSaving=locale.DaylightSaving();
TBool result2=(daylightSaving&EDstSouthern)
  // result2 returns true
TBool result3=locale.QueryHomeHasDaylightSavingOn();
  // result3 returns false