Skip to main content

LongDateTime

Struct LongDateTime 

Source
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 UTC

Needless 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");

Implementations§

Source§

impl LongDateTime

Source

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");
Source

pub const MIN: Self

The smallest representable LongDateTime.

§Examples
assert_eq!(LongDateTime::MIN.to_string(), "-292277022723-01-25 08:29:52 UTC");
Source

pub const MAX: Self

The largest representable LongDateTime.

§Examples
assert_eq!(LongDateTime::MAX.to_string(), "+292277026530-12-04 15:30:07 UTC");
Source

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");
Source

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);
Source

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");
Source

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);
Source

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");
Source

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

Source§

fn clone(&self) -> LongDateTime

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LongDateTime

Source§

impl Debug for LongDateTime

Formats LongDateTime as an RFC 3339 and ISO 8601 timestamp. See more above

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LongDateTime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for LongDateTime

Formats LongDateTime as a human-readable timestamp. See more above

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for LongDateTime

Source§

impl From<DateTime<Utc>> for LongDateTime

Source§

fn from(value: DateTime<Utc>) -> Self

Converts to this type from the input type.
Source§

impl Hash for LongDateTime

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for LongDateTime

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for LongDateTime

Source§

fn eq(&self, other: &LongDateTime) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for LongDateTime

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for LongDateTime

Source§

impl TryFrom<LongDateTime> for DateTime<Utc>

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(value: LongDateTime) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.