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
//! Temporal validation utilities for timestamp sequences.
//!
//! Orderbook timestamps are in nanoseconds, trade timestamps in milliseconds,
//! and other datasets might be in microseconds or seconds.
//! This module provides a canonical representation (nanoseconds) and conversion
//! utilities to normalize heterogeneous timestamp sources.
use ;
/// Nanoseconds per microsecond.
pub const NS_PER_US: u64 = 1_000;
/// Nanoseconds per millisecond.
pub const NS_PER_MS: u64 = 1_000_000;
/// Nanoseconds per second.
pub const NS_PER_S: u64 = 1_000_000_000;
/// Supported temporal resolutions for timestamp data.
/// Convert a timestamp from the given resolution to nanoseconds.
///
/// # Examples
///
/// ```
/// use atelier_data::temporal::{TimeResolution, to_nanos};
///
/// let ts_ms: u64 = 1_672_304_484_932;
/// let ts_ns = to_nanos(ts_ms, TimeResolution::Milliseconds);
/// assert_eq!(ts_ns, ts_ms * 1_000_000);
/// ```
/// Convert a nanosecond timestamp to the target resolution as `f64`.
///
/// Returns a floating-point value to preserve sub-unit precision
/// (e.g. fractional microsecond or milliseconds).
///
/// # Examples
///
/// ```
/// use atelier_data::temporal::{TimeResolution, from_nanos};
///
/// let ts_ns: u64 = 1_500_000; // 1.5 ms
/// let ts_ms = from_nanos(ts_ns, TimeResolution::Milliseconds);
/// assert!((ts_ms - 1.5).abs() < 1e-10);
/// ```