anytime
Ergonomic astronomical rust timescales
anytime provides astronomical time scales and conversions with nanosecond
resolution. Time
stores an instant with a type-level scale, making changes of scale explicit.
Supported scales are UTC, TAI, TT, TCG, TCB, TDB, and UT1. GNSS scales are
BDT, GLONASST, GPST, GST, and QZZST.
Enable the optional serde feature to serialize and deserialize Time,
AnyTime, TimeSeries, AnyTimeSeries, and TimeScale values.
Examples
Convert between scales
use ;
let utc = from_jd;
let tai: = utc.into;
When the target scale is selected at runtime, use AnyTime::convert:
use ;
let utc = from_jd;
let tai = utc.convert;
assert_eq!;
Compare and difference
Values can be compared and differenced directly, even when they use different
scales. Subtraction returns a chrono::TimeDelta.
use ;
let earlier = from_jd;
let later: = from_jd.into;
let is_ordered = earlier < later;
let difference = later - earlier;
Format a Gregorian date
gregorian().to_string() preserves sub-second precision.
use ;
use NaiveDate;
let date = from_ymd_opt
.unwrap
.and_hms_nano_opt
.unwrap;
let date_string = from_gregorian
.gregorian
.to_string;
assert_eq!;
Construct with a runtime scale
use ;
let utc = from_isot_str.unwrap;
assert_eq!;
Parse a typed time
Time<S> provides the same parsing constructors as AnyTime. Its FromStr
implementation assumes an ISO 8601 T-separated date and time without an
offset, interpreted in S.
use ;
let utc: = "2000-01-01T12:00:00".parse.unwrap;
assert_eq!;
Store a runtime-scale series
Use AnyTimeSeries when the scale is selected at runtime. It stores the scale
once for the entire homogeneous collection.
use ;
let tai = new;
let series: AnyTimeSeries = tai.into;
let utc: = series.into;
assert_eq!;
Benchmarks
Run the scale conversion benchmarks with Criterion:
To compare each conversion with the fastest result, run:
The helper reads Criterion's median estimates and reports relative cost, where
the fastest conversion is 1.000x.