Expand description
stringify_interval generates a user-friendly string from a chrono::Duration
, like “1 day, 5 hours and 20 minutes”. Years and months can be displayed, but they will need some date as a reference point, because the exact length of a year or month can vary.
It can be configured to show different units depending on the size of the interval, and to customize the strings used to compose the output.
let text = stringify_interval::without_date(
chrono::Duration::seconds(1_234_567),
&DisplayConfigConstant::default(),
&Text::default(),
);
assert_eq!(text, Ok(String::from("14 days, 6 hours and 56 minutes")));
Modules§
Structs§
- Display
Config - The display settings for each unit, including years and months.
- Display
Config Constant - The display settings for each constant unit (so no years or months).
- Display
Range - The range of values a unit should be displayed at, expressed in that unit. It implements
From<Range<u64>>
andFrom<RangeFrom<u64>>
. - Display
Settings - For an individual unit, the display range, the number of digits it should be padded to, and whether it should display even when it’s zero.
- Text
- All the strings that may be used to compose the final output. This owns the
String
s, so if it’s performance-sensitive, you will want to reuse an instance ofText
. - Threshold
Map - A map that stores values and thresholds that determine what value belongs to any given number.
Functions§
- with_
date - Stringify an interval with a configurable format. Years and months can be included, and they will be calculated with the given date as a reference point.
- with_
lazy_ date - Stringify an interval with a configurable format. Years and months can be included, and they will be calculated with the date yielded by the given closure as a reference point.
- with_
now - Stringify an interval with a configurable format. Years and months can be included, and they will be calculated with the current system time as a reference point.
- without_
date - Stringify an interval with a configurable format. Years and months cannot be included.