pub enum TimeUnit {
NanoSecond,
MicroSecond,
MilliSecond,
Second,
Minute,
Hour,
Day,
Week,
Month,
Year,
}
Expand description
The time units used to define possible time units in the input string
The parser calculates the final Duration
based on the parsed number and time unit. Each
TimeUnit
has an inherent Multiplier
and a default id. The Multiplier
influences the
final value of the Duration
and is seconds based. See also the documentation of
Multiplier
§Examples
use fundu_core::time::Multiplier;
use fundu_core::time::TimeUnit::*;
assert_eq!(NanoSecond.default_identifier(), "ns");
assert_eq!(Second.default_identifier(), "s");
assert_eq!(Hour.default_identifier(), "h");
assert_eq!(NanoSecond.multiplier(), Multiplier(1, -9));
assert_eq!(MilliSecond.multiplier(), Multiplier(1, -3));
assert_eq!(Second.multiplier(), Multiplier(1, 0));
assert_eq!(Hour.multiplier(), Multiplier(60 * 60, 0));
Variants§
NanoSecond
Represents the lowest possible time unit. The default id is given by
DEFAULT_ID_NANO_SECOND
= ns
MicroSecond
The default id is given by DEFAULT_ID_MICRO_SECOND
= Ms
MilliSecond
The default id is given by DEFAULT_ID_MILLI_SECOND
= ms
Second
The default if no time unit is given. The default id is given by DEFAULT_ID_SECOND
=
s
Minute
The default id is given by DEFAULT_ID_MINUTE
= m
Hour
The default id is given by DEFAULT_ID_HOUR
= h
Day
The default id is given by DEFAULT_ID_DAY
= d
Week
The default id is given by DEFAULT_ID_WEEK
= w
Month
The default id is given by DEFAULT_ID_MONTH
= M
Year
Represents the hightest possible time unit. The default id is given by DEFAULT_ID_YEAR
= y
Implementations§
Source§impl TimeUnit
impl TimeUnit
Sourcepub const fn default_identifier(&self) -> &'static str
pub const fn default_identifier(&self) -> &'static str
Return the default identifier
Sourcepub const fn multiplier(&self) -> Multiplier
pub const fn multiplier(&self) -> Multiplier
Return the base Multiplier
of this TimeUnit
.
This multiplier is always seconds based so for example:
NanoSecond: Multiplier(1, -9)
Second: Multiplier(1, 0)
Year: Multiplier(31557600, 0)