Skip to main content

Time

Struct Time 

Source
pub struct Time<S: Scale, F: TimeFormat = J2000s> { /* private fields */ }
Expand description

A point in time on scale S, tagged with external format phantom F.

The default F is J2000s, so Time<S> in code is Time<S, J2000s>: SI seconds since J2000.0 TT on the scale’s coordinate axis.

Storage is always a compensated (hi, lo) pair of seconds. The format tag does not duplicate storage; it only types the API (raw(), conversions, …).

§Preconditions

NaN must never appear in encoded scalars or storage components — behavior is undefined if it does. ±∞ may be carried when callers use instants as sentinels; operations that require finite coordinates (ΔT loops, UTC civil decoding, POSIX Unix mapping, …) may still return ConversionError::NonFinite.

Implementations§

Source§

impl<F> Time<TT, F>

Source

pub fn try_from_chrono(dt: DateTime<Utc>) -> Result<Self, ConversionError>

Build a TT Time in format F from a UTC chrono timestamp.

Source

pub fn from_chrono(dt: DateTime<Utc>) -> Self

Build a TT Time in format F from a UTC chrono timestamp.

Source

pub fn try_from_chrono_with( dt: DateTime<Utc>, ctx: &TimeContext, ) -> Result<Self, ConversionError>

Like Self::try_from_chrono, but uses an explicit TimeContext.

Source

pub fn from_chrono_with(dt: DateTime<Utc>, ctx: &TimeContext) -> Self

Like Self::from_chrono, but uses an explicit TimeContext.

Source

pub fn try_to_chrono(self) -> Result<DateTime<Utc>, ConversionError>

Convert to a UTC chrono timestamp (TT → UTC using a default context).

Source

pub fn to_chrono(self) -> Option<DateTime<Utc>>

Convert to a UTC chrono timestamp (TT → UTC using a default context).

Source

pub fn try_to_chrono_with( self, ctx: &TimeContext, ) -> Result<DateTime<Utc>, ConversionError>

Like Self::try_to_chrono, but uses an explicit TimeContext.

Source

pub fn to_chrono_with(self, ctx: &TimeContext) -> Option<DateTime<Utc>>

Like Self::to_chrono, but uses an explicit TimeContext.

Source§

impl<F: TimeFormat> Time<UTC, F>

Source

pub fn try_from_chrono_with( dt: DateTime<Utc>, ctx: &TimeContext, ) -> Result<Time<UTC, J2000s>, ConversionError>

Build a UTC instant from a chrono::DateTime<Utc> using the context’s captured time-data bundle.

Source

pub fn try_from_chrono( dt: DateTime<Utc>, ) -> Result<Time<UTC, J2000s>, ConversionError>

Build a UTC instant from a chrono::DateTime<Utc>.

Snapshots the active time-data bundle at call time via TimeContext::new. For reproducible pipelines, prefer try_from_chrono_with with an explicit context.

Source

pub fn from_chrono_with( dt: DateTime<Utc>, ctx: &TimeContext, ) -> Time<UTC, J2000s>

Convenience panicking wrapper over try_from_chrono_with.

Source

pub fn from_chrono(dt: DateTime<Utc>) -> Time<UTC, J2000s>

Convenience panicking wrapper over try_from_chrono.

Snapshots the active time-data bundle at call time via TimeContext::new. For reproducible pipelines, prefer from_chrono_with.

Source

pub fn try_to_chrono_with( self, ctx: &TimeContext, ) -> Result<DateTime<Utc>, ConversionError>

Convert to a chrono::DateTime<Utc>, preserving leap-second labels, using the context’s captured time-data bundle.

Source

pub fn try_to_chrono(self) -> Result<DateTime<Utc>, ConversionError>

Convert to a chrono::DateTime<Utc>, preserving leap-second labels.

Snapshots the active time-data bundle at call time via TimeContext::new. For reproducible pipelines, prefer try_to_chrono_with with an explicit context.

Source

pub fn to_chrono_with(self, ctx: &TimeContext) -> Option<DateTime<Utc>>

Convenience non-fallible wrapper (returns None on error) using the context’s captured time-data bundle.

Source

pub fn to_chrono(self) -> Option<DateTime<Utc>>

Convenience non-fallible wrapper (returns None on error).

Snapshots the active time-data bundle at call time via TimeContext::new. For reproducible pipelines, prefer to_chrono_with.

Source

pub fn is_leap_second_with(self, ctx: &TimeContext) -> bool

Returns true if this instant falls inside a positive leap second in UTC (e.g. 23:59:60) using the context’s captured time-data bundle.

Source

pub fn is_leap_second(self) -> bool

Returns true if this instant falls inside a positive leap second in UTC (e.g. 23:59:60).

Snapshots the active time-data bundle at call time via TimeContext::new. For reproducible pipelines, prefer is_leap_second_with.

Source§

impl<S: Scale, F: TimeFormat> Time<S, F>

Source

pub fn reinterpret<G: TimeFormat>(self) -> Time<S, G>

Same instant, different format tag (zero cost).

Source

pub fn to_j2000s(self) -> Time<S, J2000s>

SI J2000-second tagged view of the same instant.

Source

pub fn raw_seconds_pair(self) -> (Second, Second)

Raw internal storage pair in J2000-TT seconds on the instance scale.

Source§

impl<S: CoordinateScale> Time<S, J2000s>

Source

pub fn from_raw_j2000_seconds(seconds: Second) -> Result<Self, ConversionError>

Build from J2000 TT seconds on the scale’s coordinate axis.

Source

pub fn try_from_raw_j2000_seconds_split( hi: Second, lo: Second, ) -> Result<Self, ConversionError>

Build from a split J2000-second pair on the scale’s coordinate axis.

Source

pub fn shifted_by<U>(self, delta: Quantity<U>) -> Self
where U: TimeUnit,

Shift this instant forward by a typed duration.

Source

pub fn shifted_back_by<U>(self, delta: Quantity<U>) -> Self
where U: TimeUnit,

Shift this instant backward by a typed duration.

Source

pub fn duration_since(self, other: Self) -> Second

Duration from other to self.

Source

pub fn duration_until(self, other: Self) -> Second

Duration from self to other.

Source§

impl<S: CoordinateScale, F: InfallibleFormatForScale<S>> Time<S, F>

Source

pub fn raw(self) -> Quantity<F::Unit>

Encoded scalar for this format (derived from split storage).

Source

pub fn quantity(self) -> Quantity<F::Unit>

Alias for Self::raw.

Source§

impl<S: CoordinateScale, F> Time<S, F>
where F: FormatForScale<S>,

Source§

impl<S: Scale, F: TimeFormat> Time<S, F>

Source

pub fn to<T>(self) -> T::Output

Unified infallible conversion to a scale/view target.

Source

pub fn try_to<T>(self) -> Result<T::Output, ConversionError>
where T: ConversionTarget<S, F>,

Unified fallible conversion to a scale/view target.

Source

pub fn to_with<T>(self, ctx: &TimeContext) -> Result<T::Output, ConversionError>
where T: ContextConversionTarget<S, F>,

Unified context-backed conversion to a scale/view target.

Source

pub fn to_scale<S2: Scale>(self) -> Time<S2, F>
where S: InfallibleScaleConvert<S2>,

Infallible scale conversion; preserves format tag F.

Source

pub fn to_scale_with<S2: Scale>( self, ctx: &TimeContext, ) -> Result<Time<S2, F>, ConversionError>
where S: ContextScaleConvert<S2>,

Context-required scale conversion (UT1 routes); preserves F.

Source§

impl<S: Scale, F: FormatForScale<S>> Time<S, F>

Source

pub fn try_new(raw: Quantity<F::Unit>) -> Result<Self, ConversionError>

Fallible constructor from an encoded scalar.

Only surfaces domain failures from format decoding (UTC policy, leap seconds, ranges, …). Scalar hygiene is a caller precondition: NaN must not be passed; ±∞ is accepted only where the format decoder tolerates it.

Source

pub fn try_new_with( raw: Quantity<F::Unit>, ctx: &TimeContext, ) -> Result<Self, ConversionError>

Like Self::try_new, but uses ctx for UTC / POSIX decoding policy.

Source§

impl<S: Scale, F: InfallibleFormatForScale<S>> Time<S, F>

Source

pub fn new(value: f64) -> Self

Infallible constructor from the raw scalar value for format F.

§Panics

If value is NaN. ±∞ is allowed as storage when callers use sentinel instants.

Source§

impl<S: CoordinateScale, F: InfallibleFormatForScale<S>> Time<S, F>

Source

pub fn min(self, other: Self) -> Self

Source

pub fn max(self, other: Self) -> Self

Source

pub fn mean(self, other: Self) -> Self

Source§

impl Time<TT, JD>

TT Julian date at J2000.0 (JD 2 451 545.0); matches Self::jd_epoch_tt, usable in const.

Source

pub const JD_EPOCH_J2000_0: Self

Source§

impl<S: Scale> Time<S, JD>

Source

pub fn jd_epoch_tt() -> Self
where S: CoordinateScale,

TT J2000.0 as a Julian Date on scale S (JD 2 451 545.0).

Source

pub fn value(self) -> f64
where S: CoordinateScale,

Source

pub fn julian_centuries(self) -> f64
where S: CoordinateScale,

Source§

impl<S: Scale> Time<S, MJD>

Source

pub fn value(self) -> f64
where S: CoordinateScale,

Trait Implementations§

Source§

impl<S: CoordinateScale, F, U> Add<Quantity<U>> for Time<S, F>

Source§

type Output = Time<S, F>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Quantity<U>) -> Self::Output

Performs the + operation. Read more
Source§

impl<S: CoordinateScale, F, U> AddAssign<Quantity<U>> for Time<S, F>

Source§

fn add_assign(&mut self, rhs: Quantity<U>)

Performs the += operation. Read more
Source§

impl<S: Scale, F: TimeFormat> Clone for Time<S, F>

Source§

fn clone(&self) -> Self

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<S: Scale, F: TimeFormat> Debug for Time<S, F>

Source§

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

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

impl<S: CoordinateScale, F> Display for Time<S, F>

Source§

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

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

impl Display for Time<UTC, Unix>

Source§

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

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

impl<F> From<DateTime<Utc>> for Time<TT, F>

Source§

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

Converts to this type from the input type.
Source§

impl<S: Scale> From<Time<S, JD>> for Time<S>

Source§

fn from(value: JulianDate<S>) -> Self

Converts to this type from the input type.
Source§

impl<S: Scale> From<Time<S, MJD>> for Time<S>

Source§

fn from(value: ModifiedJulianDate<S>) -> Self

Converts to this type from the input type.
Source§

impl From<Time<TAI, GPS>> for Time<TAI>

Source§

fn from(value: GpsTime) -> Self

Converts to this type from the input type.
Source§

impl From<Time<UTC, Unix>> for Time<UTC>

Source§

fn from(value: UnixTime) -> Self

Converts to this type from the input type.
Source§

impl<S: CoordinateScale, F> LowerExp for Time<S, F>

Source§

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

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

impl<S: Scale, F: TimeFormat> PartialEq for Time<S, F>

Source§

fn eq(&self, other: &Self) -> 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<S: Scale, F: TimeFormat> PartialOrd for Time<S, F>

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<S: CoordinateScale, F, U> Sub<Quantity<U>> for Time<S, F>

Source§

type Output = Time<S, F>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Quantity<U>) -> Self::Output

Performs the - operation. Read more
Source§

impl<S: CoordinateScale, F> Sub for Time<S, F>

Source§

type Output = Quantity<<F as TimeFormat>::Unit>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<S: CoordinateScale, F, U> SubAssign<Quantity<U>> for Time<S, F>

Source§

fn sub_assign(&mut self, rhs: Quantity<U>)

Performs the -= operation. Read more
Source§

impl TimeInstant for Time<TT>

Source§

type Duration = Quantity<Second>

Duration type produced by subtracting two instants.
Source§

fn difference(&self, other: &Self) -> Second

Signed duration from other to self (self − other).
Source§

fn add_duration(&self, dur: Second) -> Self

Shift this instant forward by duration.
Source§

impl<S: CoordinateScale, F> UpperExp for Time<S, F>

Source§

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

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

impl<S: Scale, F: TimeFormat> Copy for Time<S, F>

Auto Trait Implementations§

§

impl<S, F> Freeze for Time<S, F>

§

impl<S, F> RefUnwindSafe for Time<S, F>

§

impl<S, F> Send for Time<S, F>

§

impl<S, F> Sync for Time<S, F>

§

impl<S, F> Unpin for Time<S, F>

§

impl<S, F> UnsafeUnpin for Time<S, F>

§

impl<S, F> UnwindSafe for Time<S, F>

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<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> Same for T

Source§

type Output = T

Should always be Self
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 = 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.