Type Definition timespan::DateSpan

source ·
pub type DateSpan<T> = Span<Date<T>>;
Expand description

The DateSpan alias is a span consisting of chrono::Dates.

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

The DateSpan can be formatted to a string. It can only be used for serialization when using serde as deserialization is not supported.

Example

use timespan::DateSpan;
use chrono_tz::Europe::Paris;

let a = DateSpan::from_utc_datespan(
    &"1789-06-17 - 1799-11-10".parse().unwrap(),
    &Paris,
);

let f = a.format(
    "The french revolution lasted from the {start} to the {end}.",
    "%eth of %B %Y",
    "%eth of %B %Y",
);
assert!(
    format!("{}", f) ==
    "The french revolution lasted from the 17th of June 1789 to the 10th of November 1799."
);

Implementations

Create a DateSpan from a NaiveDateSpan with the time zone set to the local time zone.

Currently the result handling of the internally used TimeZone::from_local_date 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_datespan should be prefered.

Create a DateSpan from a NaiveDateSpan with the time zone set to UTC.

As a DateSpan cannot be parsed from a string this method is the preferred way of creating a DateSpan.

Example
use timespan::DateSpan;
use chrono_tz::Europe::Berlin;

let a = DateSpan::from_utc_datespan(
    &"2017-05-21 - 2017-05-27".parse().unwrap(),
    &Berlin,
);

assert!(format!("{}", a) == "2017-05-21CEST - 2017-05-27CEST");