ferroid/
time.rs

1use core::time::Duration;
2
3/// Custom epoch: Wednesday, January 1, 2025 00:00:00 UTC
4pub const CUSTOM_EPOCH: Duration = Duration::from_millis(1_735_689_600_000);
5
6/// Twitter epoch: Thursday, November 4, 2010 1:42:54.657 UTC
7pub const TWITTER_EPOCH: Duration = Duration::from_millis(1_288_834_974_657);
8
9/// Discord epoch: Thursday, January 1, 2015 00:00:00 UTC
10pub const DISCORD_EPOCH: Duration = Duration::from_millis(1_420_070_400_000);
11
12/// Instagram epoch: Saturday, January 1, 2011 00:00:00 UTC
13pub const INSTAGRAM_EPOCH: Duration = Duration::from_millis(1_293_840_000_000);
14
15/// Mastodon epoch: Thursday, January 1, 1970 00:00:00 UTC
16pub const MASTODON_EPOCH: Duration = Duration::from_millis(0);
17
18/// A trait for time sources that return a monotonic or wall-clock timestamp.
19///
20/// This abstraction allows you to plug in a real system clock, a monotonic
21/// timer, or a mocked time source in tests.
22///
23/// The timestamp type `T` is generic (typically `u64` or `u128`), and the unit
24/// is expected to be **milliseconds** relative to a configurable origin.
25///
26/// # Example
27///
28/// ```
29/// use ferroid::TimeSource;
30///
31/// struct FixedTime;
32/// impl TimeSource<u64> for FixedTime {
33///     fn current_millis(&self) -> u64 {
34///         1234
35///     }
36/// }
37///
38/// let time = FixedTime;
39/// assert_eq!(time.current_millis(), 1234);
40/// ```
41pub trait TimeSource<T> {
42    /// Returns the current time in milliseconds since the configured epoch.
43    fn current_millis(&self) -> T;
44}