font_types/longdatetime.rs
1//! a datetime type
2
3/// A simple datetime type.
4///
5/// This represented as a number of seconds since 12:00 midnight, January 1, 1904, UTC.
6#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8#[cfg_attr(feature = "bytemuck", derive(bytemuck::AnyBitPattern))]
9#[repr(transparent)]
10pub struct LongDateTime(i64);
11
12impl LongDateTime {
13 /// Create with a number of seconds relative to 1904-01-01 00:00.
14 pub const fn new(secs: i64) -> Self {
15 Self(secs)
16 }
17
18 /// The number of seconds since 00:00 1904-01-01, UTC.
19 ///
20 /// This can be a negative number, which presumably represents a date prior
21 /// to the reference date.
22 pub const fn as_secs(&self) -> i64 {
23 self.0
24 }
25
26 /// The representation of this datetime as a big-endian byte array.
27 pub const fn to_be_bytes(self) -> [u8; 8] {
28 self.0.to_be_bytes()
29 }
30}
31
32crate::newtype_scalar!(LongDateTime, [u8; 8]);
33//TODO: maybe a 'chrono' feature for constructing these sanely?