Timezone

Struct Timezone 

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

A Timezone holds the storage for the libtz C library. Create one with Timezone::new (to specify a specific timezone) or Timezone::default (to use the default system timezone, which it looks for in /etc/localtime).

§Example:

use libtz::Timezone;
let tz = Timezone::new("America/Los_Angeles").expect("timezone alloc");
let time = 127810800;
let tm = tz.localtime(time).expect("localtime");
assert_eq!(tz.mktime(&tm).expect("mktime"), time);

Implementations§

Source§

impl Timezone

Source

pub fn new(name: &str) -> Result<Timezone, String>

Create a Timezone for the specified timezone name. The name can be something like America/New_York, US/Pacific, UTC, PST, etc. It can even specify a custom time conversion function. See libtz_sys::tzalloc for more details.

Source

pub fn default() -> Result<Timezone, String>

Create a Timezone based on the TZ environment variable. If TZ is not set, use the tzfile stored in /etc/localtime. If that doesn’t exist it will return an error.

Source

pub fn localtime(&self, time: TimeT) -> Result<Tm, String>

Convert system time to a local time Tm.

The localtime function corrects for the time zone and any time zone adjustments (such as Daylight Saving Time in the United States).

Source

pub fn mktime(&self, tm: &Tm) -> Result<TimeT, String>

Convert local time Tm to system time.

The mktime function converts the broken-down time, expressed as local time, in the structure pointed to by tm into a calendar time value with the same encoding as that of the values returned by the time function. The original values of the tm_wday and tm_yday components of the structure are ignored, and the original values of the other components are not restricted to their normal ranges. (A positive or zero value for tm_isdst causes mktime to presume initially that daylight saving time respectively, is or is not in effect for the specified time.

A negative value for tm_isdst causes the mktime function to attempt to divine whether daylight saving time is in effect for the specified time; in this case it does not use a consistent rule and may give a different answer when later presented with the same argument.) On successful completion, the values of the tm_wday and tm_yday components of the structure are set appropriately, and the other components are set to represent the specified calendar time, but with their values forced to their normal ranges; the final value of tm_mday is not set until tm_mon and tm_year are determined. The mktime function returns the specified calendar time; If the calendar time cannot be represented, it returns an error.

Source

pub fn time2posix(&self, time: TimeT) -> TimeT

Convert from leap-second to POSIX time_ts.

See libtz_sys::time2posix_z for details.

Source

pub fn posix2time(&self, time: TimeT) -> TimeT

Convert from POSIX to leap-second time_ts.

See libtz_sys::posix2time_z for details.

Trait Implementations§

Source§

impl Drop for Timezone

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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