1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! Human-readable duration formatting.
//!
//! This module focuses on compact and long-form duration rendering and shares
//! its locale configuration with relative-time formatting.
//!
//! # Quick start
//!
//! ```rust
//! use core::time::Duration;
//! use humfmt::{duration, duration_with, DurationOptions};
//!
//! assert_eq!(duration(Duration::from_secs(3661)).to_string(), "1h 1m");
//!
//! // Long-form with 3 units
//! let opts = DurationOptions::new().long_units().max_units(3);
//! assert_eq!(
//! duration_with(Duration::from_secs(3665), opts).to_string(),
//! "1 hour 1 minute 5 seconds"
//! );
//! ```
//!
//! # Edge case behaviour
//!
//! | Input | Default output | Notes |
//! |---:|---|---|
//! | `0s` | `"0s"` | Zero duration |
//! | `900ms` | `"900ms"` | Below 1s |
//! | `1500ms` | `"1s 500ms"` | Compound |
//! | `90s` | `"1m 30s"` | Two units (default cap) |
//! | `3661s` | `"1h 1m"` | Seconds truncated |
//! | `90061s` | `"1d 1h"` | Days included |
//!
//! # Output control
//!
//! - **`max_units(n)`** — limits how many non-zero units are rendered (default: 2,
//! max: 7). The formatter renders the largest units first.
//! - **`long_units()`** — switches from compact labels (`h`, `m`, `s`) to long-form
//! (`hour`, `minute`, `second`).
//! - **Locale** — affects unit labels and pluralization (e.g. Russian: `"1 час"`,
//! `"2 часа"`, `"5 часов"`).
pub use DurationDisplay;
pub use DurationOptions;
pub use DurationLike;
use crate;
/// Creates a human-readable duration formatter using default options.
///
/// # Examples
///
/// ```rust
/// let value = core::time::Duration::from_secs(3661);
/// assert_eq!(humfmt::duration(value).to_string(), "1h 1m");
/// ```
/// Creates a human-readable duration formatter with custom options.
///
/// # Examples
///
/// ```rust
/// use humfmt::DurationOptions;
///
/// let value = core::time::Duration::from_millis(1500);
/// let out = humfmt::duration_with(value, DurationOptions::new().long_units());
/// assert_eq!(out.to_string(), "1 second 500 milliseconds");
/// ```