Expand description
Astronomical time scales and conversions with nanosecond resolution.
Time stores an instant with a type-level Scale. The scale marker
prevents accidental mixing of values while the conversion implementations
make changes of scale explicit:
use anytime::{Time, scales::{TAI, UTC}};
let utc = Time::<UTC>::from_jd(2_451_545.0);
let tai: Time<TAI> = utc.into();Values can also be compared and differenced directly, even when they use
different scales. Subtraction returns a chrono::TimeDelta, while
comparisons use standard ordering operators:
use anytime::{Time, scales::{TAI, UTC}};
use chrono::TimeDelta;
let earlier = Time::<UTC>::from_jd(2_451_545.0);
let later: Time<TAI> = Time::<UTC>::from_jd(2_451_546.0).into();
let is_ordered = earlier < later;
let difference = later - earlier;A value can be formatted as a Gregorian date string, including sub-second
precision, through Time::gregorian:
use anytime::{Time, scales::UTC};
use chrono::NaiveDate;
let date = NaiveDate::from_ymd_opt(2000, 1, 1)
.unwrap()
.and_hms_nano_opt(12, 0, 0, 123_456_789)
.unwrap();
let date_string = Time::<UTC>::from_gregorian(date)
.gregorian()
.to_string();When the scale is selected at runtime, use AnyTime’s constructors with
TimeScale:
use anytime::{AnyTime, TimeScale};
let utc = AnyTime::from_isot_str("2000-01-01T12:00:00", TimeScale::UTC).unwrap();When the scale for a whole collection is selected at runtime, use
AnyTimeSeries. It stores the scale once while retaining a homogeneous
typed series internally:
use anytime::{AnyTimeSeries, Time, TimeSeries, scales::{TAI, UTC}};
let tai = TimeSeries::new(vec![Time::<TAI>::from_jd(2_451_545.0)]);
let series: AnyTimeSeries = tai.into();
let utc: TimeSeries<UTC> = series.into();
assert_eq!(utc.len(), 1);Convert a runtime-selected value to another runtime-selected scale with
AnyTime::convert:
use anytime::{AnyTime, TimeScale};
let utc = AnyTime::from_jd(2_451_545.0, TimeScale::UTC);
let tai = utc.convert(TimeScale::TAI);Typed values also support the same parsing constructors. std::str::FromStr
assumes an ISO 8601 T-separated date and time without an offset, interpreted
in the type’s scale:
use anytime::{Time, scales::UTC};
let utc: Time<UTC> = "2000-01-01T12:00:00".parse().unwrap();The crate supports UTC, TAI, TT, TCG, TCB, TDB, and UT1. Its GNSS scales are
BDT, GLONASST, GPST, GST, and QZZST. UTC conversions use leap-second data built
into the crate. UT1 conversions additionally use Earth-orientation data loaded
with load_finals2000a.
§Feature overview
- Use
Time::from_jd,Time::from_mjd,Time::from_split_jd, orTime::from_gregorianto construct a typed value, orAnyTime’s runtime-scale constructors when the scale is chosen dynamically. - Use
Time::jd,Time::mjd,Time::split_jd, orTime::gregorianto inspect a value. - Use the
From/Intoimplementations orTime::utc,Time::tai, and the other scale methods to convert values. - Use
TimeSeriesfor stored collections orTimeSeries::range_iterfor lazy ranges. UseAnyTimeSerieswhen the common series scale is selected at runtime. - Use
AnyTimewhen a collection may contain values from multiple scales. - Enable the
serdefeature to serialize and deserializeTime,AnyTime,TimeSeries,AnyTimeSeries, andTimeScalevalues.
Re-exports§
pub use scales::TimeScale;pub use scales::TimeScaleParseError;pub use scales::BDT;pub use scales::GLONASST;pub use scales::GPS;pub use scales::GPST;pub use scales::GST;pub use scales::QZZST;pub use scales::TAI;pub use scales::TCB;pub use scales::TCG;pub use scales::TDB;pub use scales::TDT;pub use scales::TT;pub use scales::UT;pub use scales::UT1;pub use scales::UTC;
Modules§
- scales
- Marker types and runtime selection for the time scales supported by
crate::Time.
Structs§
- AnyTime
Series Into Iter - An owning iterator over values in an
AnyTimeSeries. - AnyTime
Series Iter - An iterator that borrows an
AnyTimeSeriesand yieldsAnyTimevalues. - Time
- A time value associated with a specific time scale.
- Time
Series - A collection of time values associated with a specific time scale.
- Time
Series Range - A lazily generated range of times with an exclusive end bound.
Enums§
- AnyTime
- A time value whose scale is selected at runtime.
- AnyTime
Series - A collection of time values whose common scale is selected at runtime.
- Finals
Load Error - Errors encountered while loading finals2000A.all.
Traits§
Functions§
- load_
finals2000a - Load and atomically replace the shared finals2000A dataset.