pub struct LongDateTime(/* private fields */);Expand description
The OpenType LongDateTime type.
LongDateTime is stored as a number of seconds since 1904-01-01T00:00:00Z, and covers a
riduculously large range of dates, extending to 278 billions of years before the formation of
the universe (~13.8 billion BCE), and into the far-far future.
chrono crate: -262_143-01-01 00:00:00 UTC ..= +262_142-12-31 23:59:59 UTC
LongDateTime: -292_277_022_723-01-25 08:29:52 UTC ..= +292_277_026_530-12-04 15:30:07 UTCNeedless to say, LongDateTime’s formatting as civil time probably won’t be accurate for really
far away dates, since the Earth did not spin before the universe came into existence, and also
because this implementation does not account for variable length of day, which will likely grow
more than tenfold before an overflow occurs (if the Earth is still somehow not destroyed).
§Formatting
LongDateTime’s formatting impls mirror those of chrono::DateTime.
Display formats LongDateTime as a human-readable timestamp.
use ttf_view::types::LongDateTime;
// You can also use .to_string()
let dt = LongDateTime::from_epoch_seconds(-1535200423);
assert_eq!(format!("{}", dt), "1855-05-08 11:26:17 UTC");
let dt = LongDateTime::from_epoch_seconds(3478852446);
assert_eq!(format!("{}", dt), "2014-03-28 11:54:06 UTC");Debug formats LongDateTime as an RFC 3339 and ISO 8601 timestamp.
use ttf_view::types::LongDateTime;
let dt = LongDateTime::from_epoch_seconds(-1535200423);
assert_eq!(format!("{:?}", dt), "1855-05-08T11:26:17Z");
let dt = LongDateTime::from_epoch_seconds(3478852446);
assert_eq!(format!("{:?}", dt), "2014-03-28T11:54:06Z");You can also format the date-time components yourself with ymd_hms_utc.
use ttf_view::types::LongDateTime;
let dt = LongDateTime::from_epoch_seconds(0xfffffe407c80);
let (y, M, d, h, m, s) = dt.ymd_hms_utc();
assert_eq!(format!("Happy new year {}!", y), "Happy new year 8921490!");Implementations§
Source§impl LongDateTime
impl LongDateTime
Sourcepub const EPOCH: DateTime<Utc>
pub const EPOCH: DateTime<Utc>
The point of reference from which LongDateTime counts seconds.
assert_eq!(LongDateTime::EPOCH.to_string(), "1904-01-01 00:00:00 UTC");Sourcepub const MIN: Self
pub const MIN: Self
The smallest representable LongDateTime.
§Examples
assert_eq!(LongDateTime::MIN.to_string(), "-292277022723-01-25 08:29:52 UTC");Sourcepub const MAX: Self
pub const MAX: Self
The largest representable LongDateTime.
§Examples
assert_eq!(LongDateTime::MAX.to_string(), "+292277026530-12-04 15:30:07 UTC");Sourcepub const fn new(datetime: DateTime<Utc>) -> Self
pub const fn new(datetime: DateTime<Utc>) -> Self
Creates a LongDateTime from chrono::DateTime<Utc>. Truncates sub-seconds.
Always succeeds, since chrono::DateTime’s range is a subset of LongDateTime’s.
§Examples
use chrono::{DateTime, Utc};
use ttf_view::types::LongDateTime;
let dt: DateTime<Utc> = "2026-09-06 11:11:36.562 UTC".parse().unwrap();
assert_eq!(LongDateTime::new(dt).to_string(), "2026-09-06 11:11:36 UTC");Sourcepub const fn datetime(&self) -> Option<DateTime<Utc>>
pub const fn datetime(&self) -> Option<DateTime<Utc>>
Returns a chrono::DateTime<Utc> representing this LongDateTime value.
Returns None if it’s out of chrono::DateTime’s range.
§Examples
use chrono::{DateTime, Utc};
use ttf_view::types::LongDateTime;
let long = LongDateTime::from_epoch_seconds(0xFFFFFFFF);
assert_eq!(long.to_string(), "2040-02-06 06:28:15 UTC");
assert_eq!(long.datetime().unwrap().to_string(), "2040-02-06 06:28:15 UTC");
// chrono::DateTime is limited to ±262000 years.
let long = LongDateTime::from_epoch_seconds(0xFFFFFFFFFFFFFF);
assert_eq!(long.to_string(), "+2283416158-11-23 12:52:15 UTC");
assert_eq!(long.datetime(), None);Sourcepub const fn from_epoch_seconds(secs: i64) -> Self
pub const fn from_epoch_seconds(secs: i64) -> Self
Creates a LongDateTime from the number of seconds since EPOCH
(1904-01-01 00:00:00 UTC).
§Examples
use ttf_view::types::LongDateTime;
assert_eq!(LongDateTime::from_epoch_seconds(-1535200423).to_string(), "1855-05-08 11:26:17 UTC");
assert_eq!(LongDateTime::from_epoch_seconds(3478852446).to_string(), "2014-03-28 11:54:06 UTC");Sourcepub const fn epoch_seconds(self) -> i64
pub const fn epoch_seconds(self) -> i64
Returns the number of seconds from EPOCH (1904-01-01 00:00:00 UTC)
to this LongDateTime’s value.
§Examples
use chrono::{DateTime, Utc};
use ttf_view::types::LongDateTime;
let dt: DateTime<Utc> = "1855-05-08 11:26:17 UTC".parse().unwrap();
assert_eq!(LongDateTime::new(dt).epoch_seconds(), -1535200423);
let dt: DateTime<Utc> = "2014-03-28 11:54:06 UTC".parse().unwrap();
assert_eq!(LongDateTime::new(dt).epoch_seconds(), 3478852446);Sourcepub const fn ymd_hms_utc(&self) -> (i64, u8, u8, u8, u8, u8)
pub const fn ymd_hms_utc(&self) -> (i64, u8, u8, u8, u8, u8)
Returns this LongDateTime’s date-time components in UTC time zone
(year, month, day, hour, minute, second).
§Examples
use ttf_view::types::LongDateTime;
let dt = LongDateTime::from_epoch_seconds(0xfffffe407c80);
let (y, M, d, h, m, s) = dt.ymd_hms_utc();
assert_eq!(format!("Happy new year {}!", y), "Happy new year 8921490!");Sourcepub const fn from_be_bytes(bytes: [u8; 8]) -> Self
pub const fn from_be_bytes(bytes: [u8; 8]) -> Self
Creates a LongDateTime from big-endian bytes.
§Examples
use ttf_view::types::LongDateTime;
let raw = [0xFF, 0xFF, 0xFF, 0xFF, 0xA4, 0x7E, 0xB3, 0x59];
assert_eq!(LongDateTime::from_be_bytes(raw).to_string(), "1855-05-08 11:26:17 UTC");
let raw = [0x00, 0x00, 0x00, 0x00, 0xCF, 0x5B, 0x13, 0x5E];
assert_eq!(LongDateTime::from_be_bytes(raw).to_string(), "2014-03-28 11:54:06 UTC");Sourcepub const fn to_be_bytes(self) -> [u8; 8]
pub const fn to_be_bytes(self) -> [u8; 8]
Returns this LongDateTime’s big-endian bytes.
§Examples
use chrono::{DateTime, Utc};
use ttf_view::types::LongDateTime;
let dt: DateTime<Utc> = "1855-05-08 11:26:17 UTC".parse().unwrap();
let raw = [0xFF, 0xFF, 0xFF, 0xFF, 0xA4, 0x7E, 0xB3, 0x59];
assert_eq!(LongDateTime::new(dt).to_be_bytes(), raw);
let dt: DateTime<Utc> = "2014-03-28 11:54:06 UTC".parse().unwrap();
let raw = [0x00, 0x00, 0x00, 0x00, 0xCF, 0x5B, 0x13, 0x5E];
assert_eq!(LongDateTime::new(dt).to_be_bytes(), raw);Trait Implementations§
Source§impl Clone for LongDateTime
impl Clone for LongDateTime
impl Copy for LongDateTime
Source§impl Debug for LongDateTime
Formats LongDateTime as an RFC 3339 and ISO 8601 timestamp. See more above
impl Debug for LongDateTime
Formats LongDateTime as an RFC 3339 and ISO 8601 timestamp. See more above
Source§impl Default for LongDateTime
impl Default for LongDateTime
Source§impl Display for LongDateTime
Formats LongDateTime as a human-readable timestamp. See more above
impl Display for LongDateTime
Formats LongDateTime as a human-readable timestamp. See more above