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
82
83
mod accuracy;
mod complete;
mod days;
mod delta;
mod digits_format;
pub mod none_wrapper;
mod possible_time_save;
mod regular;
mod short;
pub mod timer;
pub use self::accuracy::Accuracy;
pub use self::complete::Complete;
pub use self::days::Days;
pub use self::delta::Delta;
pub use self::digits_format::DigitsFormat;
pub use self::possible_time_save::PossibleTimeSave;
pub use self::regular::Regular;
pub use self::short::Short;
use crate::TimeSpan;
use std::cmp::min;
use std::fmt::Display;
pub trait TimeFormatter<'a> {
type Inner: Display;
fn format<T>(&'a self, time: T) -> Self::Inner
where
T: Into<Option<TimeSpan>>;
}
const EPSILON: f64 = 0.000_000_1;
pub const DASH: &str = "—";
pub const MINUS: &str = "−";
pub const ASCII_MINUS: &str = "-";
pub const PLUS: &str = "+";
fn extract_tenths(seconds: f64) -> u8 {
min(9, ((seconds.abs() % 1.0) * 10.0 + EPSILON).floor() as u8)
}
fn extract_hundredths(seconds: f64) -> u8 {
min(99, ((seconds.abs() % 1.0) * 100.0 + EPSILON).floor() as u8)
}
fn extract_milliseconds(seconds: f64) -> u16 {
min(
999,
((seconds.abs() % 1.0) * 1000.0 + EPSILON).floor() as u16,
)
}