pub struct TimeScaleConversion {
pub source: TimeScale,
pub target: TimeScale,
pub offset_seconds: f64,
}Expand description
A caller-supplied time-scale conversion policy.
The conversion stores the source and target time scales plus the explicit
target - source offset in SI seconds. It does not model Delta T,
leap seconds, DUT1, or relativistic TDB terms itself; it only packages the
caller’s chosen rule so an instant can be retagged explicitly and
reproducibly. Its compact summary renders the structured field names
explicitly so release-facing diagnostics do not have to infer which side of
the conversion the offset applies to.
§Example
use pleiades_types::{Instant, JulianDay, TimeScale, TimeScaleConversion};
let policy = TimeScaleConversion::new(TimeScale::Ut1, TimeScale::Tt, 64.184);
let instant = Instant::new(JulianDay::from_days(2_451_545.0), TimeScale::Ut1);
let converted = policy.apply(instant).expect("UT1-tagged instant");
assert_eq!(policy.summary_line(), "source=UT1; target=TT; offset_seconds=64.184 s");
assert_eq!(converted.scale, TimeScale::Tt);use pleiades_types::{Instant, JulianDay, TimeScale, TimeScaleConversion};
let policy = TimeScaleConversion::new(TimeScale::Tdb, TimeScale::Tt, -0.001_657);
let instant = Instant::new(JulianDay::from_days(2_451_545.0), TimeScale::Tdb);
assert!(policy.validate(instant).is_ok());
assert_eq!(policy.summary_line(), "source=TDB; target=TT; offset_seconds=-0.001657 s");
assert_eq!(policy.validated_summary_line(instant).unwrap(), policy.summary_line());Fields§
§source: TimeScaleThe source time scale expected by the policy.
target: TimeScaleThe target time scale produced by the policy.
offset_seconds: f64The explicit target - source offset in SI seconds.
Implementations§
Source§impl TimeScaleConversion
impl TimeScaleConversion
Sourcepub const fn new(
source: TimeScale,
target: TimeScale,
offset_seconds: f64,
) -> TimeScaleConversion
pub const fn new( source: TimeScale, target: TimeScale, offset_seconds: f64, ) -> TimeScaleConversion
Creates a new caller-supplied time-scale conversion policy.
Sourcepub fn summary_line(&self) -> String
pub fn summary_line(&self) -> String
Returns a compact one-line rendering of the caller-supplied policy.
Sourcepub fn validated_summary_line(
&self,
instant: Instant,
) -> Result<String, TimeScaleConversionError>
pub fn validated_summary_line( &self, instant: Instant, ) -> Result<String, TimeScaleConversionError>
Returns the compact summary line after validating the policy.
This keeps the fail-closed rendering path co-located with the explicit conversion contract when a caller wants to report the policy before mutating the instant.
Sourcepub fn validate(self, instant: Instant) -> Result<(), TimeScaleConversionError>
pub fn validate(self, instant: Instant) -> Result<(), TimeScaleConversionError>
Validates the policy against a specific instant without retagging it.
This is useful when a caller wants to preflight the explicit conversion contract before mutating the instant itself. The source scale must match the instant’s current scale, and the offset must be finite.
Sourcepub fn apply(
self,
instant: Instant,
) -> Result<Instant, TimeScaleConversionError>
pub fn apply( self, instant: Instant, ) -> Result<Instant, TimeScaleConversionError>
Applies the policy to an instant.
This is the mutating counterpart to TimeScaleConversion::validate.
The source scale must match the instant’s current scale, and the offset
must be finite. Otherwise the conversion fails with the same structured
time-scale error used by the lower-level helpers.
Trait Implementations§
Source§impl Clone for TimeScaleConversion
impl Clone for TimeScaleConversion
Source§fn clone(&self) -> TimeScaleConversion
fn clone(&self) -> TimeScaleConversion
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more