Struct hourglass::Datetime [] [src]

pub struct Datetime<'a> {
    // some 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);

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]

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

Project the current Datetime in another Timezone.

fn date(&self) -> (i32, i32, i32)

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

fn time(&self) -> (i32, i32, i32, i32)

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

fn unix(&self) -> i64

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

fn format(&self, fmt: &str) -> String

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)

Panics if the format is invalid.

fn rfc3339(&self) -> String

Format Datetime according to RFC 3339 format.

fn rfc2822(&self) -> String

Format Datetime according to RFC 2822 format.

Trait Implementations

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

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

fn clone(&self) -> Datetime<'a>

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

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

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

This method returns an Ordering between self and other. Read more

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

type Output = Datetime<'a>

The resulting type after applying the + operator

fn add(self, rhs: Deltatime) -> Self::Output

The method for the + operator

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

type Output = Datetime<'a>

The resulting type after applying the - operator

fn sub(self, rhs: Deltatime) -> Self::Output

The method for the - operator

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

fn fmt(&self, fmt: &mut Formatter) -> Result

Formats the value using the given formatter.