Skip to main content

av_core/
units.rs

1//! Unit-conversion constants shared workspace-wide.
2//!
3//! Every crate that mixes seconds/milliseconds or dollars/micro-dollars must
4//! use these names rather than open-coding the conversion factors — a
5//! misplaced `1_000` vs `1_000_000` was a real class of bug in earlier
6//! rounds of this review.
7
8/// Milliseconds per second.
9pub const MS_PER_SEC: u64 = 1_000;
10
11/// Milliseconds per hour.
12pub const MS_PER_HOUR: u64 = 3_600 * MS_PER_SEC;
13
14/// Milliseconds per day.
15pub const MS_PER_DAY: u64 = 24 * MS_PER_HOUR;
16
17/// Seconds per day.
18pub const SECS_PER_DAY: u64 = 24 * 3_600;
19
20/// USD micro-units per dollar. All internal cost bookkeeping stays in
21/// micro-USD (`u64`) to keep every arithmetic step in exact integers; only
22/// wire-facing serialization converts to floating point.
23pub const USD_MICROS_PER_DOLLAR: u64 = 1_000_000;
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    #[test]
30    fn factors_agree_with_first_principles() {
31        assert_eq!(MS_PER_SEC, 1_000);
32        assert_eq!(MS_PER_HOUR, 3_600_000);
33        assert_eq!(MS_PER_DAY, 86_400_000);
34        assert_eq!(SECS_PER_DAY, 86_400);
35        assert_eq!(USD_MICROS_PER_DOLLAR, 1_000_000);
36    }
37}