[][src]Struct hourglass::Datetime

pub struct Datetime<'a> { /* fields omitted */ }

A precise point in time along associated to a Timezone.

The Datetime cannot be created on its own as it depends on a Timezone. hourglass does not expose a naive flavor of Datetime. To build a Datetime, instanciate a Timezone first and call the desired method.

let paris = hourglass::Timezone::new("Europe/Paris").unwrap();
let midnight_in_paris = paris.datetime(2015, 12, 25, 0, 0, 0, 0).unwrap();

let utc = hourglass::Timezone::utc();
let t = midnight_in_paris.project(&utc);

assert_eq!(t.date(), (2015, 12, 24));
assert_eq!(t.time(), (23, 0, 0, 0));

Methods

impl<'a> Datetime<'a>[src]

pub fn project<'b>(&self, tz: &'b Timezone) -> Datetime<'b>[src]

Project the current Datetime in another Timezone.

pub fn date(&self) -> (i32, i32, i32)[src]

Return the date component of the Datetime expressed in the associated Timezone. The tuple holds the year, month and day in this order.

pub fn time(&self) -> (i32, i32, i32, i32)[src]

Return the time component of the Datetime expressed in the associated Timezone. The tuple holds the hour, minute, second and nanosecond in this order.

pub fn unix(&self) -> i64[src]

Return the unix timestamp. This is the number of unix seconds since 1970-01-01T00:00:00Z.

pub fn to_timespec(&self) -> Timespec[src]

Convert the Datetime to a Timespec, disregarding the Timezone. The associated Timezone does not have any impact on the resulting Timespec. Therefore, as long as two Datetime with different Timezone match the same point in time, their resulting Timespec will be equal.

pub fn format(&self, fmt: &str) -> Result<String, FmtError>[src]

Format the Datetime according to the provided format. The following control characters are implemented:

  • %%: the '%' character
  • %Y: year (2006)
  • %m: month (01)
  • %d: day of the month (02)
  • %e: day of the month (2)
  • %H: hour (15)
  • %M: minute (04)
  • %S: second (05)
  • %3: millisecond (123)
  • %6: microsecond (123456)
  • %9: nanosecond (123456789)
  • %x: UTC offset (+02:00 or -05:00)
  • %z: UTC offset (+0200 or -0500)
  • %Z: timezone abbreviation (CET)
  • %w: weekday (1)
  • %a: abbreviated weekday name (Mon)
  • %A: full weekday name (Monday)
  • %b: abbreviated month name (Jan)
  • %B: full month name (January)
  • %C: century (20)

Returns a FmtError if the format is invalid.

pub fn rfc3339(&self) -> String[src]

Format Datetime according to RFC 3339 format.

pub fn rfc2822(&self) -> String[src]

Format Datetime according to RFC 2822 format.

Trait Implementations

impl<'a> PartialOrd<Datetime<'a>> for Datetime<'a>[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> Copy for Datetime<'a>[src]

impl<'a> PartialEq<Datetime<'a>> for Datetime<'a>[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<'a> Clone for Datetime<'a>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'a> Ord for Datetime<'a>[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl<'a> Eq for Datetime<'a>[src]

impl<'a> Debug for Datetime<'a>[src]

impl<'a> Add<Deltatime> for Datetime<'a>[src]

type Output = Datetime<'a>

The resulting type after applying the + operator.

impl<'a> Sub<Deltatime> for Datetime<'a>[src]

type Output = Datetime<'a>

The resulting type after applying the - operator.

impl<'a> Sub<Datetime<'a>> for Datetime<'a>[src]

type Output = Deltatime

The resulting type after applying the - operator.

Auto Trait Implementations

impl<'a> Send for Datetime<'a>

impl<'a> Sync for Datetime<'a>

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]