Expand description
§compact-reltime
This is a small and simple libraray crate providing compact, human-readable, string formatting for approximated durations of time. The compact format represents a duration in terms of one or two distinct time units which are abbreviated by a single character. The precision of the string format is 1 second for short durations and generally decreases as the duration increases.
Duration strings generated by this crate have the following format:
xxuyyvWhere xx and yy are small integers, and u and v are single-character abbreviations of one
of the following units of time:
| Units | Abbreviation |
|---|---|
| Seconds | s |
| Minutes | m |
| Hours | h |
| Days | d |
| Weeks | w |
| Months | M |
| Years | y |
For example, a duration of 3,204,898 seconds would be formatted as 5w2d (5 weeks and 2 days), and
a duration of 324 seconds would be formatted as 5m24s.
§Limitations
This crate does not support durations greater than 99y11M. This is to ensure the format is always less than 7 characters in length. It also does not presently support languages other than English or durations with sub-second precision.
§Usage
The simplest and most straightforward way to use this crate is to directly construct a Reltime
value from a number of seconds, then display or render its string representation via Display:
use compact_reltime::Reltime;
let my_duration = Reltime::new(3204898).unwrap();
let my_string = my_duration.to_string(); // my_duration implments Display
assert_eq!(my_string, "5w2d");Structs§
- Formatted
Reltime - A formatted time duration
- Reltime
- A duration that formats with human-friendly units and precision via
Display. - TooLong
- Error type signaling that a
Reltimewhich exceeds the supported duration was attempted to be initialized.
Enums§
- Units
- Possible units for a component of a relative time.
Constants§
- MAX_
DURATION - The maximum duration supported by the crate in seconds; 99 years and 11 months
Type Aliases§
- Thresh
Spec - A type for constructing threshold tables for
Reltime::format_with_timetable. A value of this type,xmeans that a duration less thanx.0seconds will be docomposed into components with major unitsx.1and minor unitsx.2, unless anotherThreshSpecvalue with a lower.0component is also greater than the duration.