[][src]Type Definition timespan::DateTimeSpan

type DateTimeSpan<T> = Span<ChronoDateTime<T>>;

The DateTimeSpan alias is a span consisting of chrono::DateTimes.

It can be used to represent datetime spans that depend on a specific time zone.

The DateTimeSpan can be formatted and parsed from a string. It can be used for serialization and deserialization with serde. The deserialization is currently only supported for the Utc, Local and FixedOffset time zones. The time zones provided by chrono-tz do not implement from_str and parse_from_str for chrono::DateTime<Tz> and can therefore not be deserialized.


use timespan::DateTimeSpan;
use chrono::Utc;

let a: DateTimeSpan<Utc> = "2017-01-01T15:10:00 +0200 - 2017-01-02T09:30:00 +0200"

    format!("{}", a.format("{start} to {end}", "%c", "%c")) ==
    "Sun Jan  1 13:10:00 2017 to Mon Jan  2 07:30:00 2017"


impl<T: TimeZone> DateTimeSpan<T>[src]

pub fn from_local_datetimespan(
    span: &NaiveDateTimeSpan,
    tz: &T
) -> Result<Self, Error>

Create a DateTimeSpan from a NaiveDateTimeSpan with the time zone set to the local time zone.

Currently the result handling of the internally used TimeZone::from_local_datetime is not implemented properly. Therefore only date spans with a single local time zone can be created. Ambigious local time zones will lead to Error::LocalAmbigious.

To avoid this from_utc_datetimespan should be prefered.

pub fn from_utc_datetimespan(span: &NaiveDateTimeSpan, tz: &T) -> Self[src]

Create a DateTimeSpan from a NaiveDateTimeSpan with the time zone set to UTC.


use timespan::DateTimeSpan;
use chrono_tz::America::Puerto_Rico;

let a = DateTimeSpan::from_utc_datetimespan(
    &"2017-03-12T12:00:00 - 2017-03-15T14:00:00".parse().unwrap(),

assert!(format!("{}", a) == "2017-03-12 08:00:00 AST - 2017-03-15 10:00:00 AST");

Trait Implementations

impl FromStr for DateTimeSpan<Tz>[src]

Parses a Span from a string in the format {start} - {end}.

type Err = Error

The associated error which can be returned from parsing.