xtd 0.2.0
Loading...
Searching...
No Matches
xtd::time_zone_info Class Reference
Inheritance diagram for xtd::time_zone_info:
xtd::icomparable< time_zone_info > xtd::iequatable< time_zone_info > xtd::object xtd::interface xtd::comparison_operators< type_t, comparable_t > xtd::interface xtd::equality_operators< type_t, equatable_t >

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
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.h:21
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:22
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
Represents any time zone in the world.
Definition time_zone_info.h:38
#define core_export_
Define shared library export.
Definition core_export.h:13
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...
 

Public Properties

ticks base_utc_offset () const noexcept
 Gets the time difference between the current time zone's standard time and Coordinated Universal Time (UTC).
 
const stringdaylight_name () const noexcept
 Gets the display name for the current time zone's daylight saving time.
 
const stringdisplay_name () const noexcept
 Gets the general display name that represents the time zone.
 
const stringid () const noexcept
 Gets the time zone identifier.
 
const stringstandard_name () const noexcept
 Gets the display name for the time zone's standard time.
 
bool supports_daylight_saving_time () const noexcept
 Gets a value indicating whether the time zone has any daylight saving time rules.*.
 

Public Methods

int32 compare_to (const time_zone_info &tzi) const noexcept override
 Compares the current instance with another object of the same type.
 
bool equals (const time_zone_info &tzi) const noexcept override
 Indicates whether the current object is equal to another object of the same type.
 
std::vector< adjustement_ruleget_adjustement_rules () const noexcept
 Retrieves an array of xtd::time_zone_info::adjustment_rule objects that apply to the current xtd::time_zone_info object.
 
bool is_daylight_saving_time (const xtd::date_time &date_time) const noexcept
 Indicates whether a specified date and time falls in the range of daylight saving time for the time zone of the current xtd::time_zone_info object.
 
xtd::string to_string () const noexcept override
 Returns a xtd::string that represents the current object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 

Public Static Properties

static const time_zone_infolocal () noexcept
 Gets a time_zone_info object that represents the local time zone.
 
static const time_zone_infoutc () noexcept
 Gets a time_zone_info object that represents the Coordinated Universal Time (UTC) zone.
 

Public Static Methods

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).
 
static const std::list< time_zone_info > & get_system_time_zones () noexcept
 Returns a sorted collection of all the time zones about which information is available on the local system.
 
static xtd::date_time convert_time (const xtd::date_time &date_time, const xtd::time_zone_info &destination_time_zone)
 Converts a time to the time in a particular 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)
 Converts a time from one time zone to another.
 
static xtd::date_time convert_time_by_system_time_zone_id (const xtd::date_time &date_time, const xtd::string &destination_time_zone_id)
 Converts a time to the time in another time zone based on the time zone's identifier.
 
static xtd::date_time convert_time_by_system_time_zone_id (const xtd::date_time &date_time, const xtd::string &source_time_zone_id, const xtd::string &destination_time_zone_id)
 Converts a time from one time zone to another based on time zone identifiers.
 
static xtd::date_time convert_from_utc (const xtd::date_time &date_time, const xtd::time_zone_info &destination_time_zone)
 Converts a Coordinated Universal Time (UTC) to the time in a specified time zone.
 
static xtd::date_time convert_to_utc (const xtd::date_time &date_time, const xtd::time_zone_info &source_time_zone)
 Converts the time in a specified time zone to Coordinated Universal Time (UTC).
 
static xtd::date_time convert_to_utc (const xtd::date_time &date_time)
 Converts the specified date and time to Coordinated Universal Time (UTC).
 
static time_zone_info time_find_system_time_zone_by_id (const string &id)
 Retrieves a time_zone_info object from the registry based on its identifier.
 

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.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Member Function Documentation

◆ base_utc_offset()

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

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.

◆ daylight_name()

const string & xtd::time_zone_info::daylight_name ( ) const
noexcept

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 string.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 string.Empty or null. However, the DaylightName property of custom time zones can be set to string.Empty. This occurs when custom time zones are created by the time_zone_info.CreateCustomTimeZone(string, TimeSpan, string, string) or the time_zone_info.CreateCustomTimeZone(string, TimeSpan, string, string, string, 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 string & xtd::time_zone_info::display_name ( ) const
noexcept

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)

◆ id()

const string & xtd::time_zone_info::id ( ) const
noexcept

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.

◆ standard_name()

const string & xtd::time_zone_info::standard_name ( ) const
noexcept

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
noexcept

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.

◆ local()

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

Gets a time_zone_info object that represents the local time zone.

Returns
time_zone_info An object that represents the local time zone.

◆ utc()

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

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.

◆ compare_to()

int32 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 >.

◆ equals() [1/3]

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 >.

◆ get_adjustement_rules()

std::vector< adjustement_rule > xtd::time_zone_info::get_adjustement_rules ( ) const
noexcept

Retrieves an array of xtd::time_zone_info::adjustment_rule objects that apply to the current xtd::time_zone_info object.

Returns
An array of objects for this time zone.

◆ is_daylight_saving_time()

bool xtd::time_zone_info::is_daylight_saving_time ( const xtd::date_time date_time) const
noexcept

Indicates whether a specified date and time falls in the range of daylight saving time for the time zone of the current xtd::time_zone_info object.

Parameters
date_timeA date and time value.
Returns
true if the date_time parameter is a daylight saving time; otherwise, false.

◆ to_string()

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

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.
Examples
The following code example demonstrates what to_string returns.
#include <xtd/xtd>
using namespace xtd;
namespace examples {
namespace object_test {
class object1 : public object {
};
}
}
auto main() -> int {
ptr<object> obj1 = new_ptr<examples::object_test::object1>();
console::write_line(obj1->to_string());
ptr<object> obj2 = new_ptr<date_time>(1971, 1, 5, 23, 5, 0);
console::write_line(obj2->to_string());
ptr<object> obj3 = new_ptr<boolean_object>();
console::write_line(obj3->to_string());
}
// This code produces the following output :
//
// examples::object_test::object1
// Tue Jan 5 23:05:00 1971
// false
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.h:27
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10

Reimplemented from xtd::object.

◆ 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.

◆ get_system_time_zones()

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

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.

◆ convert_time() [1/2]

static xtd::date_time xtd::time_zone_info::convert_time ( const xtd::date_time date_time,
const xtd::time_zone_info destination_time_zone 
)
static

Converts a time to the time in a particular time zone.

Parameters
date_timeThe date and time to convert.
destination_time_zoneThe time zone to convert dateTime to.
Returns
The date and time in the destination time zone.
Exceptions
xtd::argument_exceptionThe value of the date_time parameter represents an invalid time.

◆ convert_time() [2/2]

static xtd::date_time xtd::time_zone_info::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

Converts a time from one time zone to another.

Parameters
date_timeThe date and time to convert.
source_time_zoneThe time zone of date_time.
destination_time_zoneThe time zone to convert date_time to.
Returns
The date and time in the destination time zone that corresponds to the dateTime parameter in the source time zone.
Exceptions
xtd::argument_exceptionThe xtd::date_time::kind property of the date_time parameter is xtd::date_time_kind::local, but the source_time_tone parameter does not equal xtd::date_time_kind::local.
-or-
The xtd::date_time::kind property of the date_time parameter is xtd::date_time_kind::utc, but the source_time_zone parameter does not equal xtd::date_time_kind::utc.
-or-
The date_time parameter is an invalid time (that is, it represents a time that does not exist because of a time zone's adjustment rules).

◆ convert_time_by_system_time_zone_id() [1/2]

static xtd::date_time xtd::time_zone_info::convert_time_by_system_time_zone_id ( const xtd::date_time date_time,
const xtd::string destination_time_zone_id 
)
static

Converts a time to the time in another time zone based on the time zone's identifier.

Parameters
date_timeThe date and time to convert.
destination_time_zone_idThe identifier of the destination time zone.
Returns
The date and time in the destination time zone.

◆ convert_time_by_system_time_zone_id() [2/2]

static xtd::date_time xtd::time_zone_info::convert_time_by_system_time_zone_id ( const xtd::date_time date_time,
const xtd::string source_time_zone_id,
const xtd::string destination_time_zone_id 
)
static

Converts a time from one time zone to another based on time zone identifiers.

Parameters
date_timeThe date and time to convert.
source_time_zone_idThe identifier of the source time zone.
destintion_time_zone_idThe identifier of the destination time zone.
Returns
The date and time in the destination time zone that corresponds to the dateTime parameter in the source time zone.

◆ convert_from_utc()

static xtd::date_time xtd::time_zone_info::convert_from_utc ( const xtd::date_time date_time,
const xtd::time_zone_info destination_time_zone 
)
static

Converts a Coordinated Universal Time (UTC) to the time in a specified time zone.

Parameters
date_timeThe Coordinated Universal Time (UTC).
destination_time_zoneThe time zone to convert dateTime to.
Returns
The date and time in the destination time zone. Its xtd::date_time::kind property is xtd::date_time_kind::utc if destination_time_zone is xtd::date_time_kind::utc; otherwise, its xtd::date_time::kind property is xtd::date_time_kind::unspecified.

◆ convert_to_utc() [1/2]

static xtd::date_time xtd::time_zone_info::convert_to_utc ( const xtd::date_time date_time,
const xtd::time_zone_info source_time_zone 
)
static

Converts the time in a specified time zone to Coordinated Universal Time (UTC).

Parameters
date_timeThe date and time to convert.
source_time_zoneThe time zone of dateTime.
Returns
The Coordinated Universal Time (UTC) that corresponds to the date_time parameter. The xtd::date_time object's xtd::date_time::kind property is always set to xtd::date_time_kind::utc.

◆ convert_to_utc() [2/2]

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

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

Parameters
date_timeThe date and time to convert.
Returns
The Coordinated Universal Time (UTC) that corresponds to the date_time parameter. The xtd::date_time value's xtd::date_time::kind property is always set to xtd::date_time_kind::utc.

◆ time_find_system_time_zone_by_id()

static time_zone_info xtd::time_zone_info::time_find_system_time_zone_by_id ( const string 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.

◆ equals() [2/3]

virtual bool xtd::object::equals ( const object obj) const
virtualnoexcept

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.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto object1 = new_ptr<object>();
auto object2 = new_ptr<object>();
auto object3 = object2;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
object3 = object1;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
}
// This code produces the following output :
//
// false
// false
// true
// true

Reimplemented from xtd::object.

◆ equals() [3/3]

template<typename object_a_t , typename object_b_t >
static bool xtd::object::equals ( const object_a_t &  object_a,
const object_b_t &  object_b 
)
inlinestaticnoexcept

Determines whether the specified object instances are considered equal.

Parameters
object_aThe first object to compare.
object_bThe second object to compare.
Returns
true if object_a is the same instance as object_b or if both are null references or if object_a(object_b) returns true. otherwise, false.
Examples
The following code example compares different objects.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
string s1 = "Tom";
string s2 = "Carol";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "Tom";
s2 = "Tom";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "";
s2 = "Tom";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "Carol";
s2 = "";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "";
s2 = "";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
}
// This code produces the following output :
//
// object::equals("Tom", "Carol") => false
// object::equals("Tom", "Tom") => true
// object::equals("", "Tom") => false
// object::equals("Carol", "") => false
// object::equals("", "") => true
virtual bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.

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