1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! 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();
//! # assert_eq!(tai.utc().jd(), 2_451_545.0);
//! ```
//!
//! 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;
//! # assert!(is_ordered);
//! # assert_eq!(difference, TimeDelta::seconds(86_400));
//! ```
//!
//! 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();
//! # assert_eq!(date_string, "2000-01-01 12:00:00.123456789");
//! ```
//!
//! The crate supports UTC, TAI, GPST, TT, TCG, and UT1. 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`], or
//! [`Time::from_gregorian`] to construct a value.
//! - Use [`Time::jd`], [`Time::mjd`], [`Time::split_jd`], or
//! [`Time::gregorian`] to inspect a value.
//! - Use the `From`/`Into` implementations or [`Time::utc`], [`Time::tai`], and
//! the other scale methods to convert values.
//! - Use [`TimeSeries`] for stored collections or [`TimeSeries::range_iter`]
//! for lazy ranges.
//! - Use [`AnyTime`] when a collection may contain values from multiple scales.
//!
// Astronomical time-scale names intentionally retain their standard acronyms.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;