Skip to content

Commit

Permalink
Merge pull request #166 from gwbres/gnss_timescales
Browse files Browse the repository at this point in the history
introducing GNSS timescales
  • Loading branch information
ChristopherRabotin authored Oct 25, 2022
2 parents a1ca5cb + a7f89a2 commit 6895e85
Show file tree
Hide file tree
Showing 10 changed files with 538 additions and 132 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hifitime"
version = "3.5.0"
version = "3.6.0"
authors = ["Christopher Rabotin <christopher.rabotin@gmail.com>"]
description = "Ultra-precise date and time handling in Rust for scientific applications with leap second support"
homepage = "https://nyxspace.com/"
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ This library is validated against NASA/NAIF SPICE for the Ephemeris Time to Univ
+ Terrestrial Time (TT)
+ Ephemeris Time (ET) without the small perturbations as per NASA/NAIF SPICE leap seconds kernel
+ Dynamic Barycentric Time (TDB), a higher fidelity ephemeris time
+ Global Positioning System (GPS), and UNIX
+ Global Positioning System (GPST)
+ Galileo System Time (GST)
+ BaiDou Time (BDT)
+ UNIX
## Non-features
* Time-agnostic / date-only epochs. Hifitime only supports the combination of date and time, but the `Epoch::{at_midnight, at_noon}` is provided as a helper function.

Expand All @@ -45,7 +48,7 @@ Put this in your `Cargo.toml`:

```toml
[dependencies]
hifitime = "3.5"
hifitime = "3.6"
```

## Examples:
Expand Down Expand Up @@ -281,7 +284,8 @@ In order to provide full interoperability with NAIF, hifitime uses the NAIF algo

# Changelog

## 3.5.1
## 3.6.0
+ Galileo System Time and BeiDou Time are now supported, huge thanks to [@gwbres](https://github.com/gwbres) for all that work!
+ Significant speed improvement in the initialization of Epochs from their Gregorian representation, thanks [@conradludgate](https://github.com/conradludgate) for [#160](https://github.com/nyx-space/hifitime/pull/160).
+ Epoch and Duration now have a `min` and `max` function which respectively returns a copy of the epoch/duration that is the smallest or the largest between `self` and `other`, cf. [#164](https://github.com/nyx-space/hifitime/issues/164).
+ [Python] Duration and Epochs now support the operators `>`, `>=`, `<`, `<=`, `==`, and `!=`. Epoch now supports `init_from_gregorian` with a time scape, like in Rust. Epochs can also be subtracted from one another using the `timedelta` function, cf. [#162](https://github.com/nyx-space/hifitime/issues/162).
Expand Down
14 changes: 7 additions & 7 deletions benches/bench_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("TBD seconds and JDE ET", |b| {
b.iter(|| {
let e = Epoch::from_gregorian_utc_hms(2015, 2, 7, 11, 22, 33);
black_box(Epoch::from_tdb_seconds(e.as_tdb_seconds()));
black_box(Epoch::from_jde_et(e.as_jde_et_days()));
black_box(Epoch::from_tdb_seconds(e.to_tdb_seconds()));
black_box(Epoch::from_jde_et(e.to_jde_et_days()));

let f: Epoch = e + black_box(50) * Unit::Second;
black_box(f.as_tdb_seconds());
black_box(f.as_jde_et_days());
black_box(f.to_tdb_seconds());
black_box(f.to_jde_et_days());
})
});

c.bench_function("TT", |b| {
b.iter(|| {
let e = Epoch::from_gregorian_utc_hms(2015, 2, 7, 11, 22, 33);
e.as_tt_seconds();
e.to_tt_seconds();

let f: Epoch = e + black_box(50) * Unit::Second;
f.as_tt_seconds();
f.to_tt_seconds();
})
});

c.bench_function("Duration to f64 seconds", |b| {
b.iter(|| {
let d: Duration = Unit::Second * black_box(3.0);
d.in_seconds();
d.to_seconds();
})
});

Expand Down
6 changes: 6 additions & 0 deletions examples/python/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@
print(time_series)
for (num, epoch) in enumerate(time_series):
print(f"#{num}:\t{epoch}")

e1 = Epoch.system_now()
e3 = e1 + Unit.Day * 1.5998
epoch_delta = e3.timedelta(e1)
assert epoch_delta == Unit.Day * 1 + Unit.Hour * 14 + Unit.Minute * 23 + Unit.Second * 42.720
print(epoch_delta)
10 changes: 8 additions & 2 deletions src/asn1der.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ impl<'a> Decode<'a> for Epoch {
TimeScale::ET => Self::from_et_duration(duration),
TimeScale::TDB => Self::from_tdb_duration(duration),
TimeScale::UTC => Self::from_utc_duration(duration),
TimeScale::GPST => Self::from_gpst_duration(duration),
TimeScale::GST => Self::from_gst_duration(duration),
TimeScale::BDT => Self::from_bdt_duration(duration),
})
}
}
Expand Down Expand Up @@ -89,7 +92,7 @@ impl<'a> Decode<'a> for Unit {
// Testing the encoding and decoding of an Epoch inherently also tests the encoding and decoding of a Duration
#[test]
fn test_encdec() {
for ts_u8 in 0..5 {
for ts_u8 in 0..=7 {
let ts: TimeScale = ts_u8.into();

let epoch = if ts == TimeScale::UTC {
Expand All @@ -104,6 +107,9 @@ fn test_encdec() {
TimeScale::TT => epoch.to_tt_duration(),
TimeScale::TDB => epoch.to_tdb_duration(),
TimeScale::UTC => epoch.to_utc_duration(),
TimeScale::GPST => epoch.to_gpst_duration(),
TimeScale::GST => epoch.to_gst_duration(),
TimeScale::BDT => epoch.to_bdt_duration(),
};

let e_dur = epoch.to_duration();
Expand All @@ -128,7 +134,7 @@ fn test_encdec() {
);
}

for unit_u8 in 0..8 {
for unit_u8 in 0..=7 {
let unit: Unit = unit_u8.into();

// Create a buffer
Expand Down
1 change: 1 addition & 0 deletions src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl Default for Duration {
impl Duration {
/// Builds a new duration from the number of centuries and the number of nanoseconds
#[must_use]
#[deprecated(note = "Prefer from_parts()", since = "3.6.0")]
pub fn new(centuries: i16, nanoseconds: u64) -> Self {
let mut out = Self {
centuries,
Expand Down
Loading

0 comments on commit 6895e85

Please sign in to comment.