glib

Struct TimeZone

Source
pub struct TimeZone { /* private fields */ }
Expand description

A GTimeZone represents a time zone, at no particular point in time.

The GTimeZone struct is refcounted and immutable.

Each time zone has an identifier (for example, ‘Europe/London’) which is platform dependent. See GLib::TimeZone::new() for information on the identifier formats. The identifier of a time zone can be retrieved using identifier().

A time zone contains a number of intervals. Each interval has an abbreviation to describe it (for example, ‘PDT’), an offset to UTC and a flag indicating if the daylight savings time is in effect during that interval. A time zone always has at least one interval — interval 0. Note that interval abbreviations are not the same as time zone identifiers (apart from ‘UTC’), and cannot be passed to GLib::TimeZone::new().

Every UTC time is contained within exactly one interval, but a given local time may be contained within zero, one or two intervals (due to incontinuities associated with daylight savings time).

An interval may refer to a specific period of time (eg: the duration of daylight savings time during 2010) or it may refer to many periods of time that share the same properties (eg: all periods of daylight savings time). It is also possible (usually for political reasons) that some properties (like the abbreviation) change between intervals without other properties changing.

GLib type: Shared boxed type with reference counted clone semantics.

Implementations§

Source§

impl TimeZone

Source

pub fn as_ptr(&self) -> *mut GTimeZone

Return the inner pointer to the underlying C value.

Source

pub unsafe fn from_glib_ptr_borrow(ptr: &*mut GTimeZone) -> &Self

Borrows the underlying C value.

Source§

impl TimeZone

Source

pub fn new(identifier: Option<&str>) -> TimeZone

👎Deprecated: Since 2.68

A version of g_time_zone_new_identifier() which returns the UTC time zone if @identifier could not be parsed or loaded.

If you need to check whether @identifier was loaded successfully, use g_time_zone_new_identifier().

§Deprecated since 2.68

Use g_time_zone_new_identifier() instead, as it provides error reporting. Change your code to handle a potentially None return value.

§identifier

a timezone identifier

§Returns

the requested timezone

Source

pub fn from_identifier(identifier: Option<&str>) -> Option<TimeZone>

Available on crate feature v2_68 only.

Creates a #GTimeZone corresponding to @identifier. If @identifier cannot be parsed or loaded, None is returned.

@identifier can either be an RFC3339/ISO 8601 time offset or something that would pass as a valid value for the TZ environment variable (including None).

In Windows, @identifier can also be the unlocalized name of a time zone for standard time, for example “Pacific Standard Time”.

Valid RFC3339 time offsets are "Z" (for UTC) or "±hh:mm". ISO 8601 additionally specifies "±hhmm" and "±hh". Offsets are time values to be added to Coordinated Universal Time (UTC) to get the local time.

In UNIX, the TZ environment variable typically corresponds to the name of a file in the zoneinfo database, an absolute path to a file somewhere else, or a string in “std offset [dst [offset],start[/time],end[/time]]” (POSIX) format. There are no spaces in the specification. The name of standard and daylight savings time zone must be three or more alphabetic characters. Offsets are time values to be added to local time to get Coordinated Universal Time (UTC) and should be "[±]hh[[:]mm[:ss]]". Dates are either "Jn" (Julian day with n between 1 and 365, leap years not counted), "n" (zero-based Julian day with n between 0 and 365) or "Mm.w.d" (day d (0 <= d <= 6) of week w (1 <= w <= 5) of month m (1 <= m <= 12), day 0 is a Sunday). Times are in local wall clock time, the default is 02:00:00.

In Windows, the “tzn[+|–]hh[:mm[:ss]][dzn]” format is used, but also accepts POSIX format. The Windows format uses US rules for all time zones; daylight savings time is 60 minutes behind the standard time with date and time of change taken from Pacific Standard Time. Offsets are time values to be added to the local time to get Coordinated Universal Time (UTC).

g_time_zone_new_local() calls this function with the value of the TZ environment variable. This function itself is independent of the value of TZ, but if @identifier is None then /etc/localtime will be consulted to discover the correct time zone on UNIX and the registry will be consulted or GetTimeZoneInformation() will be used to get the local time zone on Windows.

If intervals are not available, only time zone rules from TZ environment variable or other means, then they will be computed from year 1900 to 2037. If the maximum year for the rules is available and it is greater than 2037, then it will followed instead.

See RFC3339 §5.6 for a precise definition of valid RFC3339 time offsets (the time-offset expansion) and ISO 8601 for the full list of valid time offsets. See The GNU C Library manual for an explanation of the possible values of the TZ environment variable. See Microsoft Time Zone Index Values for the list of time zones on Windows.

You should release the return value by calling g_time_zone_unref() when you are done with it.

§identifier

a timezone identifier

§Returns

the requested timezone, or None on failure

Source

pub fn local() -> TimeZone

Creates a #GTimeZone corresponding to local time. The local time zone may change between invocations to this function; for example, if the system administrator changes it.

This is equivalent to calling g_time_zone_new() with the value of the TZ environment variable (including the possibility of None).

You should release the return value by calling g_time_zone_unref() when you are done with it.

§Returns

the local timezone

Source

pub fn from_offset(seconds: i32) -> TimeZone

Available on crate feature v2_58 only.

Creates a #GTimeZone corresponding to the given constant offset from UTC, in seconds.

This is equivalent to calling g_time_zone_new() with a string in the form [+|-]hh[:mm[:ss]].

It is possible for this function to fail if @seconds is too big (greater than 24 hours), in which case this function will return the UTC timezone for backwards compatibility. To detect failures like this, use g_time_zone_new_identifier() directly.

§seconds

offset to UTC, in seconds

§Returns

a timezone at the given offset from UTC, or UTC on failure

Source

pub fn utc() -> TimeZone

Creates a #GTimeZone corresponding to UTC.

This is equivalent to calling g_time_zone_new() with a value like “Z”, “UTC”, “+00”, etc.

You should release the return value by calling g_time_zone_unref() when you are done with it.

§Returns

the universal timezone

Source

pub fn find_interval(&self, type_: TimeType, time_: i64) -> i32

Finds an interval within @self that corresponds to the given @time_. The meaning of @time_ depends on @type_.

If @type_ is TimeType::Universal then this function will always succeed (since universal time is monotonic and continuous).

Otherwise @time_ is treated as local time. The distinction between TimeType::Standard and TimeType::Daylight is ignored except in the case that the given @time_ is ambiguous. In Toronto, for example, 01:30 on November 7th 2010 occurred twice (once inside of daylight savings time and the next, an hour later, outside of daylight savings time). In this case, the different value of @type_ would result in a different interval being returned.

It is still possible for this function to fail. In Toronto, for example, 02:00 on March 14th 2010 does not exist (due to the leap forward to begin daylight savings time). -1 is returned in that case.

§type_

the #GTimeType of @time_

§time_

a number of seconds since January 1, 1970

§Returns

the interval containing @time_, or -1 in case of failure

Source

pub fn abbreviation(&self, interval: i32) -> GString

Determines the time zone abbreviation to be used during a particular @interval of time in the time zone @self.

For example, in Toronto this is currently “EST” during the winter months and “EDT” during the summer months when daylight savings time is in effect.

§interval

an interval within the timezone

§Returns

the time zone abbreviation, which belongs to @self

Source

pub fn identifier(&self) -> GString

Available on crate feature v2_58 only.

Get the identifier of this #GTimeZone, as passed to g_time_zone_new(). If the identifier passed at construction time was not recognised, UTC will be returned. If it was None, the identifier of the local timezone at construction time will be returned.

The identifier will be returned in the same format as provided at construction time: if provided as a time offset, that will be returned by this function.

§Returns

identifier for this timezone

Source

pub fn offset(&self, interval: i32) -> i32

Determines the offset to UTC in effect during a particular @interval of time in the time zone @self.

The offset is the number of seconds that you add to UTC time to arrive at local time for @self (ie: negative numbers for time zones west of GMT, positive numbers for east).

§interval

an interval within the timezone

§Returns

the number of seconds that should be added to UTC to get the local time in @self

Source

pub fn is_dst(&self, interval: i32) -> bool

Determines if daylight savings time is in effect during a particular @interval of time in the time zone @self.

§interval

an interval within the timezone

§Returns

true if daylight savings time is in effect

Source§

impl TimeZone

Source

pub fn adjust_time(&self, type_: TimeType, time: i64) -> (i32, i64)

Finds an interval within @self that corresponds to the given @time_, possibly adjusting @time_ if required to fit into an interval. The meaning of @time_ depends on @type_.

This function is similar to g_time_zone_find_interval(), with the difference that it always succeeds (by making the adjustments described below).

In any of the cases where g_time_zone_find_interval() succeeds then this function returns the same value, without modifying @time_.

This function may, however, modify @time_ in order to deal with non-existent times. If the non-existent local @time_ of 02:30 were requested on March 14th 2010 in Toronto then this function would adjust @time_ to be 03:00 and return the interval containing the adjusted time.

§type_

the #GTimeType of @time_

§time_

a pointer to a number of seconds since January 1, 1970

§Returns

the interval containing @time_, never -1

Trait Implementations§

Source§

impl Clone for TimeZone

Source§

fn clone(&self) -> Self

Makes a clone of this shared reference.

This increments the strong reference count of the reference. Dropping the reference will decrement it again.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TimeZone

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<TimeZone> for Value

Source§

fn from(s: TimeZone) -> Self

Converts to this type from the input type.
Source§

impl HasParamSpec for TimeZone

Source§

type ParamSpec = ParamSpecBoxed

Source§

type SetValue = TimeZone

Preferred value to be used as setter for the associated ParamSpec.
Source§

type BuilderFn = fn(_: &str) -> ParamSpecBoxedBuilder<'_, TimeZone>

Source§

fn param_spec_builder() -> Self::BuilderFn

Source§

impl Hash for TimeZone

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for TimeZone

Source§

fn cmp(&self, other: &TimeZone) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for TimeZone

Source§

fn eq(&self, other: &TimeZone) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for TimeZone

Source§

fn partial_cmp(&self, other: &TimeZone) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StaticType for TimeZone

Source§

fn static_type() -> Type

Returns the type identifier of Self.
Source§

impl Eq for TimeZone

Source§

impl Send for TimeZone

Source§

impl StructuralPartialEq for TimeZone

Source§

impl Sync for TimeZone

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoClosureReturnValue for T
where T: Into<Value>,

Source§

impl<T> Property for T
where T: HasParamSpec,

Source§

type Value = T

Source§

impl<T> PropertyGet for T
where T: HasParamSpec,

Source§

type Value = T

Source§

fn get<R, F>(&self, f: F) -> R
where F: Fn(&<T as PropertyGet>::Value) -> R,

Source§

impl<T> StaticTypeExt for T
where T: StaticType,

Source§

fn ensure_type()

Ensures that the type has been registered with the type system.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSendValue for T
where T: Send + ToValue + ?Sized,

Source§

fn to_send_value(&self) -> SendValue

Returns a SendValue clone of self.
Source§

impl<T> TransparentType for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T> TryFromClosureReturnValue for T
where T: for<'a> FromValue<'a> + StaticType + 'static,

Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<'a, T, C, E> FromValueOptional<'a> for T
where T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,