Skip to main content

YmdHms

Struct YmdHms 

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

Combined Gregorian date + wall time with subsecond precision.

Has some basic calendar aware math, but not time zone aware.

§Examples

Creating a YmdHms.

use deep_time::{Dt, Scale};

// clamped to 29
let x = Dt::from_ymd(2000, 2, 30).to_ymdhms(Scale::TAI);

assert_eq!(x.day(), 29);

Adding a year. 2000 is a leap year and Feb. 29th is possible, but 2001 isn’t a leap year so the day is clamped to the 28th.

use deep_time::{Dt, Scale};

let x = Dt::from_ymd(2000, 2, 29).to_ymdhms(Scale::TAI);
let x = x.add_yr(1);

assert_eq!(x.day(), 28);

Implementations§

Source§

impl YmdHms

Source

pub const fn to_dt(&self) -> Dt

Reconstructs a Dt.

Source

pub const fn add_yr(&self, years: i64) -> Self

Adds (or subtracts) whole years, preserving month and day-of-month. Negative values subtract years. Uses standard last-day-of-month clamping.

Source

pub const fn add_mo(&self, months: i64) -> Self

Adds (or subtracts) whole months. Negative values subtract months. Uses i128 total-month arithmetic to avoid overflow at extreme years.

Source

pub const fn add_days(&self, days: i64) -> Self

Adds (or subtracts) calendar days using Julian Day arithmetic. Negative values subtract days.

Source

pub const fn add_wk(&self, weeks: i64) -> Self

Source

pub const fn add_attos(&self, attos: i128) -> Self

Source

pub const fn add_sec(&self, sec: i64) -> Self

Source

pub const fn add_min(&self, min: i64) -> Self

Source

pub const fn add_hr(&self, hr: i64) -> Self

Source

pub const fn yr(&self) -> i64

Source

pub const fn mo(&self) -> u8

Source

pub const fn day(&self) -> u8

Source

pub const fn hr(&self) -> u8

Source

pub const fn min(&self) -> u8

Source

pub const fn sec(&self) -> u8

Source

pub const fn attos(&self) -> u64

Source

pub const fn unix_attosec(&self) -> i128

Attoseconds since 1970-01-01 midnight, on whatever time scale the object was created on.

Source

pub const fn scale(&self) -> Scale

The time scale that the object was created on.

Trait Implementations§

Source§

impl Clone for YmdHms

Source§

fn clone(&self) -> YmdHms

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 YmdHms

Source§

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

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

impl<'de> Deserialize<'de> for YmdHms

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 Hash for YmdHms

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 PartialEq for YmdHms

Source§

fn eq(&self, other: &YmdHms) -> 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 YmdHms

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 YmdHms

Source§

const DECL: &'static str = "/**\n * Combined Gregorian date + wall time with subsecond precision.\n *\n * Has some basic calendar aware math, but not time zone aware.\n *\n * ## Examples\n *\n * **Creating a** [`YmdHms`].\n *\n * ```\n * use deep_time::{Dt, Scale};\n *\n * // clamped to 29\n * let x = Dt::from_ymd(2000, 2, 30).to_ymdhms(Scale::TAI);\n *\n * assert_eq!(x.day(), 29);\n * ```\n *\n * **Adding a year.** 2000 is a leap year and Feb. 29th is possible, but\n * 2001 isn\\\'t a leap year so the day is clamped to the 28th.\n *\n * ```\n * use deep_time::{Dt, Scale};\n *\n * let x = Dt::from_ymd(2000, 2, 29).to_ymdhms(Scale::TAI);\n * let x = x.add_yr(1);\n *\n * assert_eq!(x.day(), 28);\n * ```\n */\nexport interface YmdHms {\n yr: number;\n mo: number;\n day: number;\n hr: number;\n min: number;\n sec: number;\n attos: number;\n unix_attosec: number;\n scale: Scale;\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 YmdHms

Source§

impl Eq for YmdHms

Source§

impl StructuralPartialEq for YmdHms

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>,