pub enum Scale {
Seconds,
Minutes,
Hours,
Days,
Weeks,
Months,
Years,
}Expand description
Timescale
This enum represents various “scales” of time, and with the exception of Scale::Years and Scale::Months they are precisely defined as a number of seconds.
For Scale::Years and Scale::Months such a precise definition is obviously not available.
Nonetheless, it is often useful to treat them as a concrete number of seconds, such as when formatting a time Span not anchored to a particular Point in time.
For a human to comprehend a long length of time, it’s better to express it in terms of years and months, instead of just weeks, which is the highest precisely defined Scale, even if that is somewhat ill-defined.
To do this, the Scale must be expressed as a fixed number of seconds (a Span).
There are a few different values that could reasonably be chosen for the length of Scale::Years and Scale::Months respectively.
This library simply copies helper types of std::chrono::duration provided in C++ since C++20.
Accordingly, “years is equal to 365.2425 days (the average length of a Gregorian year)” and “months is equal to 30.436875 days (exactly 1/12 of years)”.
Conveniently, both of these work out to an integral number of seconds.
| Scale | unit | seconds |
|---|---|---|
| Years | y | 31556952 |
| Months | mo | 2629746 |
| Weeks | w | 604800 |
| Days | d | 86400 |
| Hours | h | 3600 |
| Minutes | m | 60 |
| Seconds | s | 1 |
All this is not to say that a Scale represents just a specific number of seconds.
For instance, the Calendar::date_floor and Calendar::frames functions use it with “calendar semantics”.
Variants§
Implementations§
Trait Implementations§
source§impl Ord for Scale
impl Ord for Scale
source§impl PartialEq for Scale
impl PartialEq for Scale
source§impl PartialOrd for Scale
impl PartialOrd for Scale
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more