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§

  • The display settings for each unit, including years and months.
  • The display settings for each constant unit (so no years or months).
  • The range of values a unit should be displayed at, expressed in that unit. It implements From<Range<u64>> and From<RangeFrom<u64>>.
  • 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.
  • All the strings that may be used to compose the final output. This owns the Strings, so if it’s performance-sensitive, you will want to reuse an instance of Text.
  • A map that stores values and thresholds that determine what value belongs to any given number.

Functions§

  • 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.
  • 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.
  • 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.
  • Stringify an interval with a configurable format. Years and months cannot be included.