hifitime 4.0.0-dev

Ultra-precise date and time handling in Rust for scientific applications with leap second support
Documentation
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
/*
 * Hifitime, part of the Nyx Space tools
 * Copyright (C) 2023 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
 * This Source Code Form is subject to the terms of the Apache
 * v. 2.0. If a copy of the Apache License was not distributed with this
 * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.
 *
 * Documentation: https://nyxspace.com/
 */

use crate::prelude::*;

#[deprecated(since = "3.5.0", note = "TimeSystem has been renamed to TimeScale")]
pub type TimeSystem = TimeScale;

impl Duration {
    #[must_use]
    #[deprecated(note = "Prefer to_seconds()", since = "3.5.0")]
    pub fn in_seconds(&self) -> f64 {
        self.to_seconds()
    }

    /// Returns the value of this duration in the requested unit.
    #[must_use]
    #[deprecated(note = "Prefer to_unit()", since = "3.5.0")]
    pub fn in_unit(&self, unit: Unit) -> f64 {
        self.to_unit(unit)
    }
}

impl Epoch {
    #[must_use]
    /// Get the accumulated number of leap seconds up to this Epoch accounting only for the IERS leap seconds.
    /// For the leap seconds _and_ the scaling in "prehistoric" times from 1960 to 1972, use `leap_seconds()`.
    #[deprecated(note = "Prefer leap_seconds_iers or leap_seconds", since = "3.4.0")]
    pub fn get_num_leap_seconds(&self) -> i32 {
        self.leap_seconds_iers()
    }

    #[must_use]
    #[deprecated(note = "Prefer as_tdb_duration", since = "3.4.0")]
    /// Returns the duration since Dynamic Barycentric Time (TDB) J2000 (used for Archinal et al. rotations)
    pub fn as_tdb_duration_since_j2000(&self) -> Duration {
        self.to_tdb_duration()
    }

    #[must_use]
    #[deprecated(note = "Prefer as_et_duration", since = "3.4.0")]
    /// Returns the duration since Ephemeris Time (ET) J2000 (used for Archinal et al. rotations)
    pub fn as_et_duration_since_j2000(&self) -> Duration {
        self.to_et_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_duration(&self) -> Duration {
        self.to_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_duration_in_time_scale(&self, time_scale: TimeScale) -> Duration {
        self.to_duration_in_time_scale(time_scale)
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_duration_since_j1900(&self) -> Duration {
        self.to_duration_since_j1900()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_duration_since_j1900_in_time_scale(&self, time_scale: TimeScale) -> Duration {
        self.to_duration_since_j1900_in_time_scale(time_scale)
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tai_seconds(&self) -> f64 {
        self.to_tai_seconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub const fn as_tai_duration(&self) -> Duration {
        self.to_tai_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tai(&self, unit: Unit) -> f64 {
        self.to_tai(unit)
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tai_days(&self) -> f64 {
        self.to_tai_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_utc_seconds(&self) -> f64 {
        self.to_utc_seconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_utc_duration(&self) -> Duration {
        self.to_utc_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_utc(&self, unit: Unit) -> f64 {
        self.to_utc(unit)
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_utc_days(&self) -> f64 {
        self.to_utc_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_mjd_tai_days(&self) -> f64 {
        self.to_mjd_tai_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_mjd_tai_seconds(&self) -> f64 {
        self.to_mjd_tai_seconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_mjd_tai(&self, unit: Unit) -> f64 {
        self.to_mjd_tai(unit)
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_mjd_utc_days(&self) -> f64 {
        self.to_mjd_utc_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_mjd_utc(&self, unit: Unit) -> f64 {
        self.to_mjd_utc(unit)
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_mjd_utc_seconds(&self) -> f64 {
        self.to_mjd_utc_seconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_tai_days(&self) -> f64 {
        self.to_jde_tai_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_tai(&self, unit: Unit) -> f64 {
        self.to_jde_tai(unit)
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_tai_duration(&self) -> Duration {
        self.to_jde_tai_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_tai_seconds(&self) -> f64 {
        self.to_jde_tai_seconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_utc_days(&self) -> f64 {
        self.to_jde_utc_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_utc_duration(&self) -> Duration {
        self.to_jde_utc_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_utc_seconds(&self) -> f64 {
        self.to_jde_utc_seconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tt_seconds(&self) -> f64 {
        self.to_tt_seconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tt_duration(&self) -> Duration {
        self.to_tt_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tt_days(&self) -> f64 {
        self.to_tt_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tt_centuries_j2k(&self) -> f64 {
        self.to_tt_centuries_j2k()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tt_since_j2k(&self) -> Duration {
        self.to_tt_since_j2k()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_tt_days(&self) -> f64 {
        self.to_jde_tt_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_tt_duration(&self) -> Duration {
        self.to_jde_tt_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_mjd_tt_days(&self) -> f64 {
        self.to_mjd_tt_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_mjd_tt_duration(&self) -> Duration {
        self.to_mjd_tt_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_gpst_seconds(&self) -> f64 {
        self.to_gpst_seconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_gpst_duration(&self) -> Duration {
        self.to_gpst_duration()
    }

    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_gpst_nanoseconds(&self) -> Result<u64, Errors> {
        self.to_gpst_nanoseconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_gpst_days(&self) -> f64 {
        self.to_gpst_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_unix(&self, unit: Unit) -> f64 {
        self.to_unix(unit)
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_unix_seconds(&self) -> f64 {
        self.to_unix_seconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_unix_milliseconds(&self) -> f64 {
        self.to_unix_milliseconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_unix_days(&self) -> f64 {
        self.to_unix_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_et_seconds(&self) -> f64 {
        self.to_et_seconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_et_duration_since_j1900(&self) -> Duration {
        self.to_et_duration_since_j1900()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_et_duration(&self) -> Duration {
        self.to_et_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tdb_duration(&self) -> Duration {
        self.to_tdb_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tdb_seconds(&self) -> f64 {
        self.to_tdb_seconds()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tdb_duration_since_j1900(&self) -> Duration {
        self.to_tdb_duration_since_j1900()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_et_days(&self) -> f64 {
        self.to_jde_et_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_et_duration(&self) -> Duration {
        self.to_jde_et_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_et(&self, unit: Unit) -> f64 {
        self.to_jde_et(unit)
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_tdb_duration(&self) -> Duration {
        self.to_jde_tdb_duration()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_jde_tdb_days(&self) -> f64 {
        self.to_jde_tdb_days()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tdb_days_since_j2000(&self) -> f64 {
        self.to_tdb_days_since_j2000()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_tdb_centuries_since_j2000(&self) -> f64 {
        self.to_tdb_centuries_since_j2000()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_et_days_since_j2000(&self) -> f64 {
        self.to_et_days_since_j2000()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_et_centuries_since_j2000(&self) -> f64 {
        self.to_et_centuries_since_j2000()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_gregorian_utc(&self) -> (i32, u8, u8, u8, u8, u8, u32) {
        self.to_gregorian_utc()
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_gregorian_tai(&self) -> (i32, u8, u8, u8, u8, u8, u32) {
        self.to_gregorian_tai()
    }
}

#[cfg(feature = "std")]
impl Epoch {
    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_gregorian_utc_str(&self) -> String {
        format!("{}", self)
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_gregorian_tai_str(&self) -> String {
        format!("{:x}", self)
    }

    #[must_use]
    #[deprecated(
        note = "Prefix for this function is now `to_` instead of `as_`.",
        since = "3.5.0"
    )]
    pub fn as_gregorian_str(&self, ts: TimeScale) -> String {
        self.to_gregorian_str(ts)
    }
}