1
- use hifitime:: { Epoch , Polynomial , TimeScale } ;
1
+ use hifitime:: { Duration , Epoch , Polynomial , TimeScale } ;
2
2
3
- /// [TimePolynomial ] allows precise [Epoch] translation to another [TimeScale].
3
+ /// [TimeCorrection ] allows precise [Epoch] translation to another [TimeScale].
4
4
/// For example, |[TimeScale::GPST]-[TimeScale::UTC]| when referencing [TimeScale::GPST] to [TimeScale::UTC].
5
5
#[ derive( Copy , Clone , PartialEq ) ]
6
- pub struct TimePolynomial {
6
+ pub struct TimeCorrection {
7
7
/// LHS [TimeScale] to which [Polynomial] applies
8
8
pub lhs_timescale : TimeScale ,
9
+
9
10
/// RHS [TimeScale] to which [Polynomial] applies
10
11
pub rhs_timescale : TimeScale ,
12
+
11
13
/// Reference [Epoch] usually expressed in LHS [TimeScale], but we support any [TimeScale] here.
12
14
pub ref_epoch : Epoch ,
15
+
16
+ /// Validity period as [Duration]
17
+ pub validity_period : Duration ,
18
+
13
19
/// [Polynomial]
14
20
pub polynomial : Polynomial ,
15
21
}
16
22
17
- impl TimePolynomial {
18
- /// Define new [TimePolynomial ] from Reference [Epoch] expressed as week counter
23
+ impl TimeCorrection {
24
+ /// Define new [TimeCorrection ] from Reference [Epoch] expressed as week counter
19
25
/// and elapsed seconds within week.
20
26
pub fn from_reference_time_of_week_seconds (
21
27
ref_week : u32 ,
22
28
ref_tow : u64 ,
29
+ validity_period : Duration ,
23
30
lhs_timescale : TimeScale ,
24
31
rhs_timescale : TimeScale ,
25
32
polynomial : Polynomial ,
26
33
) -> Self {
27
34
Self :: from_reference_time_of_week_nanos (
28
35
ref_week,
29
36
ref_tow * 1_000_000_000 ,
37
+ validity_period,
30
38
lhs_timescale,
31
39
rhs_timescale,
32
40
polynomial,
33
41
)
34
42
}
35
43
36
- /// Define new [TimePolynomial ] from reference [Epoch] that must be expressed in the correct [TimeScale]
44
+ /// Define new [TimeCorrection ] from reference [Epoch] that must be expressed in the correct [TimeScale]
37
45
pub fn from_reference_epoch (
38
46
ref_epoch : Epoch ,
47
+ validity_period : Duration ,
39
48
rhs_timescale : TimeScale ,
40
49
polynomial : Polynomial ,
41
50
) -> Self {
42
51
Self {
43
52
ref_epoch,
53
+ validity_period,
44
54
lhs_timescale : ref_epoch. time_scale ,
45
55
rhs_timescale,
46
56
polynomial,
47
57
}
48
58
}
49
59
50
- /// Define a new [TimePolynomials ] from Reference [Epoch] expressed as week counter and
60
+ /// Define a new [TimeCorrections ] from Reference [Epoch] expressed as week counter and
51
61
/// elapsed nanoseconds within week.
52
62
pub fn from_reference_time_of_week_nanos (
53
63
ref_week : u32 ,
54
64
ref_tow_nanos : u64 ,
65
+ validity_period : Duration ,
55
66
lhs_timescale : TimeScale ,
56
67
rhs_timescale : TimeScale ,
57
68
polynomial : Polynomial ,
@@ -60,9 +71,27 @@ impl TimePolynomial {
60
71
61
72
Self {
62
73
ref_epoch,
74
+ validity_period,
63
75
lhs_timescale,
64
76
rhs_timescale,
65
77
polynomial,
66
78
}
67
79
}
80
+
81
+ /// Returns true if this [TimeCorrection] should apply at ongoing [Epoch],
82
+ /// acoording to publication validity period.
83
+ pub fn applies ( & self , now : Epoch ) -> bool {
84
+ let dt = ( now - self . ref_epoch ) . abs ( ) ;
85
+ dt < self . validity_period
86
+ }
87
+
88
+ /// Returns first [Epoch] for which this [TimeCorrection] should apply.
89
+ pub fn validity_period_start ( & self ) -> Epoch {
90
+ self . ref_epoch - self . validity_period
91
+ }
92
+
93
+ /// Returns last [Epoch] for which this [TimeCorrection] should apply.
94
+ pub fn validity_period_end ( & self ) -> Epoch {
95
+ self . ref_epoch + self . validity_period
96
+ }
68
97
}
0 commit comments