Skip to main content

Time

Struct Time 

Source
pub struct Time<T: TimeScale> { /* private fields */ }
Expand description

An instant in time in a given TimeScale, relative to J2000.

Time supports femtosecond precision, but be aware that many algorithms operating on Times are not accurate to this level of precision.

Implementations§

Source§

impl<T: TimeScale> Time<T>

Source

pub const fn new(scale: T, seconds: i64, subsecond: Subsecond) -> Self

Instantiates a Time in the given TimeScale from the count of seconds since J2000, subdivided into integral seconds and Subsecond.

Source

pub fn from_date_and_time( scale: T, date: Date, time: TimeOfDay, ) -> Result<Self, TimeError>

Instantiates a Time in the given TimeScale from a Date and a TimeOfDay.

§Errors
  • Returns TimeError::LeapSecondsOutsideUtc if time is a leap second, since leap seconds cannot be unambiguously represented by a continuous time format.
Source

pub fn from_iso(scale: T, iso: &str) -> Result<Self, TimeError>

Instantiates a Time in the given TimeScale from an ISO 8601 string.

§Errors
  • Returns TimeError::InvalidIsoString if iso is not a valid ISO 8601 timestamp.
Source

pub const fn from_delta(scale: T, delta: TimeDelta) -> Self

Instantiates a Time in the given TimeScale and a TimeDelta relative to J2000.

Source

pub const fn from_epoch(scale: T, epoch: Epoch) -> Self

Returns the Time at epoch in the given TimeScale.

Since Time is defined relative to J2000, this is equivalent to the delta between J2000 and epoch.

Source

pub fn from_julian_date(scale: T, julian_date: Days, epoch: Epoch) -> Self

Given a Julian date, instantiates a Time in the specified TimeScale, relative to epoch.

Source

pub fn from_two_part_julian_date(scale: T, jd1: Days, jd2: Days) -> Self

Instantiates a Time from a two-part Julian date jd1 + jd2 in days.

Source

pub fn builder_with_scale(scale: T) -> TimeBuilder<T>

Returns a TimeBuilder for constructing a new Time in the given TimeScale.

Source

pub fn scale(&self) -> T
where T: Copy,

Returns the timescale

Source

pub fn with_scale<S: TimeScale>(&self, scale: S) -> Time<S>

Returns a new Time with the delta of self but time scale scale.

Note that the underlying delta is simply copied – no time scale transformation takes place.

Source

pub fn try_to_scale<S, P>( &self, scale: S, provider: &P, ) -> Result<Time<S>, P::Error>
where T: Copy, S: TimeScale + Copy, P: TryOffset<T, S> + ?Sized,

Converts this time to scale using the given offset provider.

Source

pub fn to_scale<S>(&self, scale: S) -> Time<S>

Converts this time to scale using the default offset provider.

Source

pub fn with_scale_and_delta<S: TimeScale>( &self, scale: S, delta: TimeDelta, ) -> Time<S>

Returns a new Time with the delta of self adjusted by delta, and time scale scale.

Note that no time scale transformation takes place beyond the adjustment specified by delta.

Source

pub fn jd0(scale: T) -> Self

Returns the Julian epoch as a Time in the given TimeScale.

Source

pub fn mjd0(scale: T) -> Self

Returns the modified Julian epoch as a Time in the given TimeScale.

Source

pub fn j1950(scale: T) -> Self

Returns the J1950 epoch as a Time in the given TimeScale.

Source

pub fn j2000(scale: T) -> Self

Returns the J2000 epoch as a Time in the given TimeScale.

Source

pub fn as_seconds_and_subsecond(&self) -> Option<(i64, Subsecond)>

Returns the seconds and subsecond components, or None if the delta is non-finite.

Source

pub fn seconds(&self) -> Option<i64>

Returns the number of whole seconds since J2000.

Source

pub fn subsecond(&self) -> Option<f64>

Returns the fraction of a second from the last whole second as an f64.

Source§

impl<T: TimeScale + Into<DynTimeScale>> Time<T>

Source

pub fn into_dyn(self) -> DynTime

Converts this time into a DynTime with a runtime time scale.

Trait Implementations§

Source§

impl<T: TimeScale> Add<TimeDelta> for Time<T>

Source§

type Output = Time<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: TimeDelta) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: TimeScale + Debug> ApproxEq for Time<T>

Source§

fn approx_eq(&self, rhs: &Self, atol: f64, rtol: f64) -> ApproxEqResults

Compares self with rhs for approximate equality. Read more
Source§

impl<T: TimeScale> CalendarDate for Time<T>

Source§

fn date(&self) -> Date

Returns the date component.
Source§

fn year(&self) -> i64

Returns the year.
Source§

fn month(&self) -> u8

Returns the month (1–12).
Source§

fn day(&self) -> u8

Returns the day of the month (1–31).
Source§

fn day_of_year(&self) -> u16

Returns the day number within the year (1–366).
Source§

impl<T: TimeScale> CivilTime for Time<T>

Source§

fn time(&self) -> TimeOfDay

Returns the time-of-day component.
Source§

fn hour(&self) -> u8

Returns the hour (0–23).
Source§

fn minute(&self) -> u8

Returns the minute (0–59).
Source§

fn second(&self) -> u8

Returns the second (0–60, where 60 represents a leap second).
Source§

fn as_seconds_f64(&self) -> f64

Returns the second including the subsecond fraction as an f64.
Source§

fn millisecond(&self) -> u32

Returns the millisecond component (0–999).
Source§

fn microsecond(&self) -> u32

Returns the microsecond component (0–999).
Source§

fn nanosecond(&self) -> u32

Returns the nanosecond component (0–999).
Source§

fn picosecond(&self) -> u32

Returns the picosecond component (0–999).
Source§

fn femtosecond(&self) -> u32

Returns the femtosecond component (0–999).
Source§

impl<T: Clone + TimeScale> Clone for Time<T>

Source§

fn clone(&self) -> Time<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + TimeScale> Debug for Time<T>

Source§

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

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

impl<T: Default + TimeScale> Default for Time<T>

Source§

fn default() -> Time<T>

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

impl<T: TimeScale> Display for Time<T>

Source§

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

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

impl FromStr for Time<Tai>

Source§

type Err = TimeError

The associated error which can be returned from parsing.
Source§

fn from_str(iso: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl FromStr for Time<Tcb>

Source§

type Err = TimeError

The associated error which can be returned from parsing.
Source§

fn from_str(iso: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl FromStr for Time<Tcg>

Source§

type Err = TimeError

The associated error which can be returned from parsing.
Source§

fn from_str(iso: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl FromStr for Time<Tdb>

Source§

type Err = TimeError

The associated error which can be returned from parsing.
Source§

fn from_str(iso: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl FromStr for Time<Tt>

Source§

type Err = TimeError

The associated error which can be returned from parsing.
Source§

fn from_str(iso: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl FromStr for Time<Ut1>

Source§

type Err = TimeError

The associated error which can be returned from parsing.
Source§

fn from_str(iso: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<T: TimeScale> JulianDate for Time<T>

Source§

fn julian_date(&self, epoch: Epoch, unit: Unit) -> f64

Expresses self as a Julian date in the specified Unit, relative to the given Epoch. Read more
Source§

fn two_part_julian_date(&self) -> (f64, f64)

Expresses self as a two-part Julian date in the specified Unit, relative to the given Epoch. Read more
Source§

fn seconds_since_julian_epoch(&self) -> f64

Returns the number of seconds since the Julian epoch as an f64.
Source§

fn seconds_since_modified_julian_epoch(&self) -> f64

Returns the number of seconds since the Modified Julian epoch as an f64.
Source§

fn seconds_since_j1950(&self) -> f64

Returns the number of seconds since J1950 as an f64.
Source§

fn seconds_since_j2000(&self) -> f64

Returns the number of seconds since J2000 as an f64.
Source§

fn days_since_julian_epoch(&self) -> f64

Returns the number of days since the Julian epoch as an f64.
Source§

fn days_since_modified_julian_epoch(&self) -> f64

Returns the number of days since the Modified Julian epoch as an f64.
Source§

fn days_since_j1950(&self) -> f64

Returns the number of days since J1950 as an f64.
Source§

fn days_since_j2000(&self) -> f64

Returns the number of days since J2000 as an f64.
Source§

fn years_since_julian_epoch(&self) -> f64

Returns the number of years since the Julian epoch as an f64.
Source§

fn years_since_modified_julian_epoch(&self) -> f64

Returns the number of years since the Modified Julian epoch as an f64.
Source§

fn years_since_j1950(&self) -> f64

Returns the number of years since J1950 as an f64.
Source§

fn years_since_j2000(&self) -> f64

Returns the number of years since J2000 as an f64.
Source§

fn centuries_since_julian_epoch(&self) -> f64

Returns the number of centuries since the Julian epoch as an f64.
Source§

fn centuries_since_modified_julian_epoch(&self) -> f64

Returns the number of centuries since the Modified Julian epoch as an f64.
Source§

fn centuries_since_j1950(&self) -> f64

Returns the number of centuries since J1950 as an f64.
Source§

fn centuries_since_j2000(&self) -> f64

Returns the number of centuries since J2000 as an f64.
Source§

impl<T: Ord + TimeScale> Ord for Time<T>

Source§

fn cmp(&self, other: &Time<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl<T: PartialEq + TimeScale> PartialEq for Time<T>

Source§

fn eq(&self, other: &Time<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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<T: PartialOrd + TimeScale> PartialOrd for Time<T>

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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<T: TimeScale> Sub<TimeDelta> for Time<T>

Source§

type Output = Time<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: TimeScale> Sub for Time<T>

Source§

type Output = TimeDelta

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: TimeScale> ToDelta for Time<T>

Source§

fn to_delta(&self) -> TimeDelta

Transforms the value into a TimeDelta.
Source§

impl<T> ToUtc for Time<T>

Source§

fn to_utc_with_provider(&self, provider: &impl LeapSecondsProvider) -> Utc

Converts to UTC using the given leap-seconds provider.
Source§

fn to_utc(&self) -> Utc

Converts to UTC using the built-in leap-seconds table.
Source§

impl<T: Copy + TimeScale> Copy for Time<T>

Source§

impl<T: Eq + TimeScale> Eq for Time<T>

Source§

impl<T: TimeScale> StructuralPartialEq for Time<T>

Auto Trait Implementations§

§

impl<T> Freeze for Time<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Time<T>
where T: RefUnwindSafe,

§

impl<T> Send for Time<T>
where T: Send,

§

impl<T> Sync for Time<T>
where T: Sync,

§

impl<T> Unpin for Time<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Time<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Time<T>
where T: UnwindSafe,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.