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
impl Timezone
Sourcepub fn new(name: &str) -> Result<Timezone, String>
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.
Sourcepub fn default() -> Result<Timezone, String>
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.
Sourcepub fn localtime(&self, time: TimeT) -> Result<Tm, String>
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).
Sourcepub fn mktime(&self, tm: &Tm) -> Result<TimeT, String>
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.
Sourcepub fn time2posix(&self, time: TimeT) -> TimeT
pub fn time2posix(&self, time: TimeT) -> TimeT
Convert from leap-second to POSIX time_ts.
See libtz_sys::time2posix_z for details.
Sourcepub fn posix2time(&self, time: TimeT) -> TimeT
pub fn posix2time(&self, time: TimeT) -> TimeT
Convert from POSIX to leap-second time_ts.
See libtz_sys::posix2time_z for details.