Usage
Put this in your Cargo.toml
:
[]
= "^0"
Or, if you want Serde support, include it like this:
[]
= { = "^0", = ["with-serde"] }
Overview
Date and Time Spans
Timespan
can be used to create a time zone aware span consisting of chrono::DateTime
s.
Currently the DateTimeSpan
supports serialization and deserialization for the chrono::Utc
,
chrono::Local
and chrono::FixedOffset
time zones. For support of other time zone types
please refer to the documentation.
When the with-serde
feature is enabled DateTimeSpan
has support for
serde
serialization and deserialization.
use DateTimeSpan;
use Utc;
let a: = "2017-01-01T15:10:00 +0200 - 2017-01-02T09:30:00 +0200"
.parse.unwrap;
assert!;
Individual Date Spans
A DateSpan
can be used to create a time zone aware span consisting of chrono::Date
s.
Currently the DateSpan
does not support serialization and deserialization from strings.
use DateSpan;
use Paris;
let a = from_utc_datespan;
let f = a.format;
assert!;
Naive Date and Time Spans
The NaiveDateSpan
, NaiveTimeSpan
and NaiveDateTimeSpan
are all not aware of time zones
and can be used for simple time spans.
All naive spans have full support for serialization and deserialization from strings.
When the with-serde
feature is enabled all naive spans have support for
serde
serialization and deserialization.
use NaiveDateSpan;
let a: NaiveDateSpan = "2017-04-15 - 2017-08-15".parse.unwrap;
let b = parse_from_str.unwrap;
let f = a.format;
assert!;
assert!;
use NaiveTimeSpan;
let a: NaiveTimeSpan = "17:30:00 - 19:15:00".parse.unwrap;
let b = parse_from_str.unwrap;
let f = a.format;
assert!;
assert!;
use NaiveDateTimeSpan;
let a: NaiveDateTimeSpan = "2017-02-20T11:30:00 - 2017-02-23T18:00:00".parse.unwrap;
let b = parse_from_str.unwrap;
let f = a.format;
assert!;
assert!;
How to Run the Examples
In order to run an example from the example
folder issue the following command.
The convert
Example
Convert from 10.30 to 14.00
to 10:30 - 14:00
:
The duration
Example
Get the duration of the time span from 10.30 to 14.00
:
The contains
Example
Get whether 11.20
is contained in the time span from 10.30 to 14.00
:
License
This project is licensed under the GPL-v3 license - see the LICENSE file for details.