xtd - Reference Guide 0.2.0
xtd::time_zone_info Class Reference

#include <time_zone_info.h>

Definition

Represents any time zone in the world.

class core_export_ time_zone_info : public xtd::icomparable<time_zone_info>, public xtd::iequatable<time_zone_info>, public xtd::object
Inheritance
xtd::objectxtd::time_zone_info
Implements
xtd::icomparable <>, xtd::iequatable <>
Namespace
xtd
Library
xtd.core
Remarks
A time zone is a geographical region in which the same time is used.
The time_zone_info class offers significant enhancements over the TimeZone class, which provides only limited functionality.
The TimeZone class recognizes only the local time zone, and can convert times between Coordinated Universal Time (UTC) and local time. A time_zone_info object can represent any time zone, and methods of the time_zone_info class can be used to convert the time in one time zone to the corresponding time in any other time zone. The members of the time_zone_info class support the following operations:
  • Retrieving a time zone that is already defined by the operating system.
  • Enumerating the time zones that are available on a system.
  • Converting times between different time zones.
  • Creating a new time zone that is not already defined by the operating system.
  • Serializing a time zone for later retrieval.
Note
An instance of the time_zone_info class is immutable. Once an object has been instantiated, its values cannot be modified.

Classes

class  adjustement_rule
 Provides information about a time zone adjustment, such as the transition to and from daylight saving time. More...
 
class  transition_time
 Provides information about a specific time change, such as the change from daylight saving time to standard time or vice versa, in a particular time zone. More...
 

Properties

ticks base_utc_offset () const
 Gets the time difference between the current time zone's standard time and Coordinated Universal Time (UTC). More...
 
const ustringdaylight_name () const
 Gets the display name for the current time zone's daylight saving time. More...
 
const ustringdisplay_name () const
 Gets the general display name that represents the time zone. More...
 
const ustringid () const
 Gets the time zone identifier. More...
 
const ustringstandard_name () const
 Gets the display name for the time zone's standard time. More...
 
bool supports_daylight_saving_time () const
 Gets a value indicating whether the time zone has any daylight saving time rules.*. More...
 
static const time_zone_infolocal ()
 Gets a time_zone_info object that represents the local time zone. More...
 
static const time_zone_infoutc ()
 Gets a time_zone_info object that represents the Coordinated Universal Time (UTC) zone. More...
 

Methods

int32_t compare_to (const time_zone_info &tzi) const noexcept override
 Compares the current instance with another object of the same type. More...
 
int32_t compare_to (const object &obj) const noexcept override
 Compares the current instance with another object of the same type. More...
 
bool equals (const time_zone_info &tzi) const noexcept override
 Indicates whether the current object is equal to another object of the same type. More...
 
bool equals (const object &obj) const noexcept override
 Determines whether the specified object is equal to the current object. More...
 
std::vector< adjustement_ruleget_adjustement_rules () const
 
bool is_daylight_saving_time (const xtd::date_time &date_time) const
 
xtd::ustring to_string () const noexcept override
 Returns a sxd::ustring that represents the current object. More...
 
static xtd::date_time convert_time_to_utc (const xtd::date_time &date_time)
 Converts the specified date and time to Coordinated Universal Time (UTC). More...
 
static const std::list< time_zone_info > & get_system_time_zones ()
 Returns a sorted collection of all the time zones about which information is available on the local system. More...
 
static xtd::date_time convert_time (const xtd::date_time &date_time, const xtd::time_zone_info &destination_time_zone)
 
static xtd::date_time convert_time (const xtd::date_time &date_time, const xtd::time_zone_info &source_time_zone, const xtd::time_zone_info &destination_time_zone)
 
static xtd::date_time convert_time_by_system_time_zone_id (const xtd::date_time &date_time, const xtd::ustring &destination_time_zone_id)
 
static xtd::date_time convert_time_by_system_time_zone_id (const xtd::date_time &date_time, const xtd::time_zone_info &source_time_zone_id, const xtd::time_zone_info &destination_time_zone_id)
 
static xtd::date_time convert_from_utc (const xtd::date_time &date_time, const xtd::time_zone_info &destination_time_zone)
 
static xtd::date_time convert_to_utc (const xtd::date_time &date_time, const xtd::time_zone_info &source_time_zone)
 
static xtd::date_time convert_to_utc (const xtd::date_time &date_time)
 
static const time_zone_infotime_find_system_time_zone_by_id (const ustring &id)
 Retrieves a time_zone_info object from the registry based on its identifier. More...
 

Additional Inherited Members

- Public Member Functions inherited from xtd::icomparable< time_zone_info >
- Public Member Functions inherited from xtd::iequatable< time_zone_info >
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance. More...
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Member Function Documentation

◆ base_utc_offset()

ticks xtd::time_zone_info::base_utc_offset ( ) const
inline

Gets the time difference between the current time zone's standard time and Coordinated Universal Time (UTC).

Returns
TimeSpan An object that indicates the time difference between the current time zone's standard time and Coordinated Universal Time (UTC).
Remarks
The time span returned by the BaseUtcOffset property can range from 14 hours (for a time zone that is 14 hours ahead of Coordinated Universal Time (UTC)) to -14 hours (for a time zone that is 14 hours behind UTC). Time zones that are ahead of UTC have a positive offset; time zones that are behind UTC have a negative offset.
The BaseUtcOffset value is represented as a whole number of minutes. It cannot include a fractional number of minutes.
Note
Because BaseUtcOffset is a property of the time_zone_info object rather than the time_zone_info.AdjustmentRule object, the time_zone_info class applies a single offset from UTC to all of a time zone's adjustments. To reflect a time zone that has modified its offset from UTC, you must create a new time zone using the CreateCustomTimeZone method.
The BaseUtcOffset property differs from the GetUtcOffset method in the following ways:
  • The BaseUtcOffset property returns the difference between UTC and the time zone's standard time; the GetUtcOffset method returns the difference between UTC and the time zone's time at a particular point in time.
  • The GetUtcOffset method reflects the application of any adjustment rules to the time zone; the BaseUtcOffset property does not.

◆ compare_to() [1/2]

int32_t xtd::time_zone_info::compare_to ( const time_zone_info obj) const
overridevirtualnoexcept

Compares the current instance with another object of the same type.

Parameters
objAn object to compare with this instance.
Returns
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
Value Condition
Less than zero This instance is less than obj.
Zero This instance is equal to obj.
Greater than zero This instance is greater than obj.

Implements xtd::icomparable< time_zone_info >.

◆ compare_to() [2/2]

int32_t xtd::time_zone_info::compare_to ( const object obj) const
overridevirtualnoexcept

Compares the current instance with another object of the same type.

Parameters
objAn object to compare with this instance.
Returns
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
Value Condition
Less than zero This instance is less than obj.
Zero This instance is equal to obj.
Greater than zero This instance is greater than obj.

Reimplemented from xtd::icomparable< time_zone_info >.

◆ convert_time_to_utc()

static xtd::date_time xtd::time_zone_info::convert_time_to_utc ( const xtd::date_time date_time)
static

Converts the specified date and time to Coordinated Universal Time (UTC).

Parameters
dateTimeThe date and time to convert.
Returns
date_time The Coordinated Universal Time (UTC) that corresponds to the dateTime parameter. The xtd::date_time value's Kind property is always set to xtd::date_timeKind.Utc.
Exceptions
ArgumentNullExceptiondateTime is null.
ArgumentExceptiontime_zone_info::Local().IsInvalidxtd::date_time(dateTime) returns true.

◆ daylight_name()

const ustring& xtd::time_zone_info::daylight_name ( ) const
inline

Gets the display name for the current time zone's daylight saving time.

Returns
string The display name for the time zone's daylight saving time.
Remarks
The display name is localized based on the culture installed with the Windows operating system.
A DaylightName property whose value is not ustring.Empty or null does not necessarily indicate that the time zone supports daylight saving time. To determine whether the time zone supports daylight saving time, check the value of its SupportsDaylightSavingTime property.
In most cases, the DaylightName property of time zones defined in the registry is not ustring.Empty or null. However, the DaylightName property of custom time zones can be set to ustring.Empty. This occurs when custom time zones are created by the time_zone_info.CreateCustomTimeZone(ustring, TimeSpan, ustring, ustring) or the time_zone_info.CreateCustomTimeZone(ustring, TimeSpan, ustring, ustring, ustring, time_zone_info.AdjustmentRule[], Boolean) overload and the disableDaylightSavingTime parameter is true. Therefore, your code should never assume that the value of the DaylightName property is not null or empty.
The DaylightName property is equivalent to the DaylightName property of the TimeZone class.

◆ display_name()

const ustring& xtd::time_zone_info::display_name ( ) const
inline

Gets the general display name that represents the time zone.

Returns
string The time zone's general display name.
Remarks
The display name is localized based on the culture installed with the Windows operating system.
Time zone display names for Windows system time zones follow a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. For Coordinated Universal Time, the GMT acronym with no offset is enclosed in parentheses. This is followed by a string that identifies the time zone or one or more of the cities, regions, or countries in the time zone. For example:
(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London
(GMT+02:00) Athens, Beirut, Istanbul, Minsk
(GMT-02:00) Mid-Atlantic
(GMT-07:00) Mountain Time (US & Canada)

◆ equals() [1/2]

bool xtd::time_zone_info::equals ( const time_zone_info ) const
overridevirtualnoexcept

Indicates whether the current object is equal to another object of the same type.

Parameters
objAn object to compare with this object.
Returns
true if the current object is equal to the other parameter; otherwise, false.

Implements xtd::iequatable< time_zone_info >.

◆ equals() [2/2]

bool xtd::time_zone_info::equals ( const object obj) const
overridevirtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.
Examples
The following code example compares the current instance with another object.

Reimplemented from xtd::object.

◆ get_system_time_zones()

static const std::list<time_zone_info>& xtd::time_zone_info::get_system_time_zones ( )
static

Returns a sorted collection of all the time zones about which information is available on the local system.

Returns
An read-only Array of time_zone_info objects.

◆ id()

const ustring& xtd::time_zone_info::id ( ) const
inline

Gets the time zone identifier.

Returns
string The time zone identifier.
Remarks
The time zone identifier is a key string that uniquely identifies a particular time zone. It can be passed as a parameter to the FindSystemTimeZoneById method to retrieve a particular time zone from the registry.

◆ local()

static const time_zone_info& xtd::time_zone_info::local ( )
static

Gets a time_zone_info object that represents the local time zone.

Returns
time_zone_info An object that represents the local time zone.

◆ standard_name()

const ustring& xtd::time_zone_info::standard_name ( ) const
inline

Gets the display name for the time zone's standard time.

Returns
The display name of the time zone's standard time.
Remarks
The display name is localized based on the culture installed with the Windows operating system.
The StandardName property is identical to the StandardName property of the TimeZone class.
The value of the StandardName property is usually, but not always, identical to that of the Id property.

◆ supports_daylight_saving_time()

bool xtd::time_zone_info::supports_daylight_saving_time ( ) const
inline

Gets a value indicating whether the time zone has any daylight saving time rules.*.

Returns
bool true if the time zone supports daylight saving time; otherwise, false.
Remarks
The value of the SupportsDaylightSavingTime property for the local time zone returned by the time_zone_info.Local property reflects the setting of the Control Panel Date and Time application's checkbox that defines whether the system automatically adjusts for daylight saving time. If it is unchecked, or if no checkbox is displayed for a time zone, the value of this property is false.

◆ time_find_system_time_zone_by_id()

static const time_zone_info& xtd::time_zone_info::time_find_system_time_zone_by_id ( const ustring id)
static

Retrieves a time_zone_info object from the registry based on its identifier.

Parameters
idThe time zone identifier, which corresponds to the Id property.
Returns
An object whose identifier is the value of the id parameter.
Exceptions
ArgumentNullExceptionThe id parameter is null.
TimeZoneNotFoundExceptionThe time zone identifier specified by id was not found. This means that a registry key whose name matches id does not exist, or that the key exists but does not contain any time zone data.

◆ to_string()

xtd::ustring xtd::time_zone_info::to_string ( ) const
overridevirtualnoexcept

Returns a sxd::ustring that represents the current object.

Returns
A string that represents the current object.
Examples
The following code example demonstrates what to_string returns.

Reimplemented from xtd::object.

◆ utc()

static const time_zone_info& xtd::time_zone_info::utc ( )
static

Gets a time_zone_info object that represents the Coordinated Universal Time (UTC) zone.

Returns
time_zone_info An object that represents the Coordinated Universal Time (UTC) zone.

The documentation for this class was generated from the following file: