Skip to main content

GregorianTime

Struct GregorianTime 

Source
pub struct GregorianTime { /* private fields */ }
Expand description

UTC Civil calendar and time-of-day components of a Dt.

Implementations§

Source§

impl GregorianTime

Source

pub fn to_str(&self, fmt: &str) -> Result<String, DtErr>

Source

pub fn to_ascii_str(&self, fmt: &str) -> Result<AsciiStr<STRFTIME_SIZE>, DtErr>

No-allocation formatting.

Source§

impl GregorianTime

Source

pub const fn new( unix_attosec: i128, yr: i64, mo: u8, day: u8, hr: u8, min: u8, sec: u8, attos: u64, iso_yr: i64, iso_wk: u8, iso_wkday: Weekday, day_of_yr: u16, wkday: u8, wk_of_yr_sun: u8, wk_of_yr_mon: u8, ) -> Self

Creates a new GregorianTime with all fields specified. This isn’t the recommended way to make a GregorianTime. It’s safer to use Dt::to_gregorian_time().

Source

pub const fn unix_attosec(&self) -> i128

UNIX attoseconds since 1970 epoch

Source

pub const fn unix_timestamp(&self) -> (i64, u64)

Returns the Unix timestamp since 1970-01-01 00:00:00 UTC as a tuple of (whole_seconds, attoseconds).

  • whole_seconds can be negative (for dates before 1970).
  • The fractional part (attoseconds) is always in the range 0..=999_999_999_999_999_999.
Source

pub const fn yr(&self) -> i64

Gregorian year (proleptic Gregorian calendar, supports negative years and year 0).

Source

pub const fn mo(&self) -> u8

Gregorian month in the range [1, 12].

Source

pub const fn day(&self) -> u8

Gregorian day of the month in the range [1, 31].

Source

pub const fn hr(&self) -> u8

Hour of the day in the range [0, 23].

Source

pub const fn min(&self) -> u8

Minute in the range [0, 59].

Source

pub const fn sec(&self) -> u8

Second in the range [0, 60] (60 only during UTC leap seconds).

Source

pub const fn attos(&self) -> u64

Fractional part of the second expressed in attoseconds (0 ≤ attos < 10¹⁸).

Source

pub const fn iso_yr(&self) -> i64

ISO 8601 week year.

Source

pub const fn iso_wk(&self) -> u8

ISO 8601 week number in the range [1, 53].

Source

pub const fn iso_wkday(&self) -> Weekday

ISO 8601 weekday (Monday-based Weekday enum).

Source

pub const fn day_of_yr(&self) -> u16

Ordinal day of the year (1-based).

Source

pub const fn wkday_sun(&self) -> u8

Weekday number (0 = Sunday … 6 = Saturday).

Source

pub const fn wkday_mon(&self) -> u8

ISO 8601 weekday (0 = Monday … 6 = Sunday).

Source

pub const fn wk_of_yr_sun(&self) -> u8

Sunday based week of year (Range: 0..=53).

Source

pub const fn wk_of_yr_mon(&self) -> u8

Monday based week of year (Range: 0..=53).

Source

pub const fn offset_sec(&self) -> Option<i32>

Source

pub const fn tz(&self) -> Option<&AsciiStr<49>>

Source

pub const fn tz_abbrev(&self) -> Option<&AsciiStr<49>>

Source

pub const fn to_dt(&self) -> Dt

Reconstructs a Dt from these UTC civil components.

Round-tripping with Dt::to_gregorian_time.

Source§

impl GregorianTime

Source

pub const WIRE_VERSION: u8 = 1

Current wire format version.

Source

pub const WIRE_SIZE: usize = 158

Size of the canonical wire representation in bytes (158 bytes).

Source

pub fn to_wire_bytes(&self) -> [u8; 158]

Serializes this GregorianTime into a fixed 158-byte buffer.

§Wire Format (Version 1)
  • Byte 0: Version (WIRE_VERSION)
  • Bytes 1..17: unix_attosec (i128)
  • Bytes 17..25: yr (i64)
  • Bytes 25..30: mo, day, hr, min, sec (u8 × 5)
  • Bytes 30..38: attos (u64)
  • Bytes 38..46: iso_yr (i64)
  • Bytes 46..48: iso_wk + iso_wkday (u8 × 2)
  • Bytes 48..50: day_of_yr (u16)
  • Byte 50: wkday (u8)
  • Bytes 51..53: wk_of_yr_sun + wk_of_yr_mon (u8 × 2)
  • Bytes 53..58: offset_sec (tag byte + i32)
  • Bytes 58..108: tz (tag byte + AsciiStr<49>)
  • Bytes 108..158: tz_abbrev (tag byte + AsciiStr<49>)
Source

pub fn from_wire_bytes(bytes: &[u8]) -> Option<Self>

Deserializes a GregorianTime from exactly 158 bytes of wire data.

Returns None if the version is unknown or any field is invalid.

§Security

Safe for untrusted input. Fixed-size format with strict validation. No allocation or unsafe code used.

Trait Implementations§

Source§

impl Clone for GregorianTime

Source§

fn clone(&self) -> GregorianTime

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 Debug for GregorianTime

Source§

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

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

impl<'de> Deserialize<'de> for GregorianTime

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for GregorianTime

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for GregorianTime

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Tsify for GregorianTime

Source§

const DECL: &'static str = "/**\n * UTC Civil calendar and time-of-day components of a [`Dt`].\n */\nexport interface GregorianTime {\n /**\n * UNIX attoseconds counting from 1970 epoch\n */\n unix_attosec: number;\n /**\n * Gregorian year (proleptic Gregorian calendar, supports negative years and year 0).\n */\n yr: number;\n /**\n * Gregorian month in the range [1, 12].\n */\n mo: number;\n /**\n * Gregorian day of the month in the range [1, 31].\n */\n day: number;\n /**\n * Hour of the day in the range [0, 23].\n */\n hr: number;\n /**\n * Minute in the range [0, 59].\n */\n min: number;\n /**\n * Second in the range [0, 60] (60 only during UTC leap seconds).\n */\n sec: number;\n /**\n * Fractional part of the second expressed in attoseconds (u64).\n */\n attos: number;\n /**\n * ISO 8601 week year.\n */\n iso_yr: number;\n /**\n * ISO 8601 week number in the range [1, 53].\n */\n iso_wk: number;\n /**\n * ISO 8601 weekday enum e.g. Monday/Tuesday/...\n */\n iso_wkday: Weekday;\n /**\n * Ordinal day of the year (1-based).\n */\n day_of_yr: number;\n /**\n * Weekday number (0 = Sunday \u{2026} 6 = Saturday).\n */\n wkday: number;\n /**\n * Sunday based week of year (Range: `0..=53`).\n */\n wk_of_yr_sun: number;\n /**\n * Monday based week of year (Range: `0..=53`).\n */\n wk_of_yr_mon: number;\n /**\n * Used for formatting (strftime).\n * A stored offset in seconds, used within the crate.\n */\n offset_sec: number | null;\n /**\n * A stored IANA name, used within the crate, %Q.\n */\n tz: AsciiStr | null;\n /**\n * UTC, EST, %Z\n */\n tz_abbrev: AsciiStr | null;\n}"

Source§

const SERIALIZATION_CONFIG: SerializationConfig

Source§

type JsType = JsType

Source§

fn into_js(&self) -> Result<Self::JsType, Error>
where Self: Serialize,

Source§

fn from_js<T>(js: T) -> Result<Self, Error>
where T: Into<JsValue>, Self: DeserializeOwned,

Source§

impl Copy for GregorianTime

Source§

impl Eq for GregorianTime

Source§

impl StructuralPartialEq for GregorianTime

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<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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,