Enum scan_rules::scanner::std::Iso8601Duration
[−]
[src]
pub enum Iso8601Duration {}
Parses an ISO 8601 format duration into a std::time::Duration
.
Specifically, it supports the following syntax:
PT[nH][nM][nS]
Each n
is either an integer or a fractional value using .
or ,
as the decimal point. It supports durations down to nanosecond precision using fractional seconds. Each component may have an arbitrarily large value (e.g. PT2H76M
).
duration-iso8601-dates
feature
By default, durations involving date components (years, months, weeks, and days) are not enabled. This is because the Duration
type stores nanoseconds. It is impossible to convert date components into seconds. As a simple example, consider that "1 month", depending on context, could reasonably be converted into the equivalent of 28 days, 29 days, 30 days, 31 days, 30 days and 8 hours, 30 days 8 hours and 30 minutes, or some other value offset by plus or minus one leap second in order to account for changes in the Earth's rotational and/or orbital speeds.
The only correct way to store such durations is in their fully decomposed, component form. Rust does not support this, thus they are disabled.
However, parsing such durations may occasionally be useful in limited contexts. Provided you understand the above drawbacks, support for these durations can be enabled with the duration-iso8601-dates
feature. It uses the following conversions:
- 1 year = 365.25 days (one fourth of 3×365 + 366 days)
- 1 month = 30 days, 10 hours, 30 minutes (one twelfth of 365.25 days)
- 1 week = 7 days
- 1 day = 24 hours
With this feature, the following additional syntaxes are enabled:
P[nY][nM][nD][T[nH][nM][nS]]
- a fuller form of the above syntax.Pyyyy-mm-ddThh:mm:ss
,PyyyymmddThhmmss
- shorthand for a "full" date duration; note that the individual components may not exceed their "conventional" maximum value; e.g. you cannot have 25 hours.PnW
- number of weeks.
Trait Implementations
impl<'a> ScanFromStr<'a> for Iso8601Duration
[src]
type Output = Duration
The type that the implementation scans into. This does not have to be the same as the implementing type, although it typically will be. Read more
fn scan_from<I: ScanInput<'a>>(s: I) -> Result<(Self::Output, usize), ScanError>
Perform a scan on the given input. Read more
fn wants_leading_junk_stripped() -> bool
Indicates whether or not the scanner wants its input to have leading "junk", such as whitespace, stripped. Read more