ferroid/
time.rs

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