Skip to content

Commit

Permalink
Add another GPST Gregorian to/from test
Browse files Browse the repository at this point in the history
Closes #287
  • Loading branch information
ChristopherRabotin committed Oct 6, 2024
1 parent 8041c23 commit 64b4767
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 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 = "4.0.0-alpha.1"
version = "4.0.0-beta"
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
3 changes: 2 additions & 1 deletion src/epoch/system_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use crate::{Duration, Epoch, HifitimeError};
/// Clippy thinks these are the same type, but they aren't.
#[allow(clippy::unnecessary_fallible_conversions)]
pub(crate) fn duration_since_unix_epoch() -> Result<Duration, HifitimeError> {
// TODO: Check why there is a map_err and and_then
// map_err maps the duration_since error into a hifitime error, if the conversion to a SystemTime fails.
// Then we converts a valid SystemTime into a Hifitime duration, unless it fails via and_then
web_time::SystemTime::now()
.duration_since(web_time::SystemTime::UNIX_EPOCH)
.map_err(|_| HifitimeError::SystemTimeError)
Expand Down
6 changes: 6 additions & 0 deletions tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2069,11 +2069,17 @@ fn regression_test_gh_282() {
fn regression_test_gh_288() {
use core::str::FromStr;
let epoch = Epoch::from_str("2021-03-06 11:14:40.9960 GPST").unwrap();
let epoch_from_gpst =
Epoch::from_gregorian(2021, 3, 6, 11, 14, 40, 996_000_000, TimeScale::GPST);

assert_eq!(
"2021-03-06T11:14:40.996000000 GPST",
format!("{}", epoch.to_gregorian_str(TimeScale::GPST))
);
assert_eq!(
format!("{}", epoch_from_gpst.to_gregorian_str(TimeScale::GPST)),
format!("{}", epoch.to_gregorian_str(TimeScale::GPST))
);
assert_eq!("2021-03-06T11:14:40.996000000 GPST", format!("{epoch}"));
assert_eq!(
"2021-03-06T11:14:40.996000",
Expand Down

0 comments on commit 64b4767

Please sign in to comment.