Struct hourglass::Datetime [] [src]

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]

[src]

Project the current Datetime in another Timezone.

[src]

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

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

[src]

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

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

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

[src]

Format Datetime according to RFC 3339 format.

[src]

Format Datetime according to RFC 2822 format.

Trait Implementations

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

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

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

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

[src]

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

1.0.0
[src]

This method tests for !=.

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

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

[src]

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

1.0.0
[src]

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

1.0.0
[src]

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

1.0.0
[src]

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

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> Ord for Datetime<'a>
[src]

[src]

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

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

[src]

Formats the value using the given formatter.