Skip to content

Commit

Permalink
Merge pull request #253 from nyx-space/248-epochfrom_format_str-does-…
Browse files Browse the repository at this point in the history
…not-set-hours-minutes-and-seconds

Day of year formatting now parses elapsed time
  • Loading branch information
ChristopherRabotin authored Aug 20, 2023
2 parents f410365 + 559c630 commit b58ed96
Show file tree
Hide file tree
Showing 24 changed files with 53 additions and 33 deletions.
23 changes: 14 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hifitime"
version = "3.8.3"
version = "3.8.4"
authors = ["Christopher Rabotin <[email protected]>"]
description = "Ultra-precise date and time handling in Rust for scientific applications with leap second support"
homepage = "https://nyxspace.com/"
Expand All @@ -18,14 +18,19 @@ crate-type = ["cdylib", "rlib"]
name = "hifitime"

[dependencies]
serde = {version = "1.0.155", optional = true}
serde_derive = {version = "1.0.155", optional = true}
der = {version = "0.6.1", features = ["derive", "real"], optional = true}
serde = { version = "1.0.155", optional = true }
serde_derive = { version = "1.0.155", optional = true }
der = { version = "0.6.1", features = ["derive", "real"], optional = true }
pyo3 = { version = "0.19.0", features = ["extension-module"], optional = true }
num-traits = {version = "0.2.15", default-features = false, features = ["libm"]}
lexical-core = {version = "0.8.5", default-features = false, features = ["parse-integers", "parse-floats"]}
reqwest = { version = "0.11", features = ["blocking", "json"], optional = true}
tabled = {version = "0.14.0", optional = true}
num-traits = { version = "0.2.15", default-features = false, features = [
"libm",
] }
lexical-core = { version = "0.8.5", default-features = false, features = [
"parse-integers",
"parse-floats",
] }
reqwest = { version = "0.11", features = ["blocking", "json"], optional = true }
tabled = { version = "0.14.0", optional = true }
openssl = { version = "0.10", features = ["vendored"], optional = true }

[dev-dependencies]
Expand All @@ -42,7 +47,7 @@ ut1 = ["std", "reqwest", "tabled", "openssl"]

[[bench]]
name = "crit_epoch"
harness = false
harness = false

[[bench]]
name = "crit_duration"
Expand Down
2 changes: 1 addition & 1 deletion examples/python/basic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion examples/python/timescales.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/asn1der.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/deprecated.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/duration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/efmt/consts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
19 changes: 17 additions & 2 deletions src/efmt/format.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down Expand Up @@ -309,7 +309,14 @@ impl Format {
};

let epoch = match day_of_year {
Some(days) => Epoch::from_day_of_year(decomposed[0], days, ts),
Some(days) => {
// Parse the elapsed time in the given day
let elapsed = (decomposed[3] as i64) * Unit::Hour
+ (decomposed[4] as i64) * Unit::Minute
+ (decomposed[5] as i64) * Unit::Second
+ (decomposed[6] as i64) * Unit::Nanosecond;
Epoch::from_day_of_year(decomposed[0], days, ts) + elapsed
}
None => Epoch::maybe_from_gregorian(
decomposed[0],
decomposed[1].try_into().unwrap(),
Expand Down Expand Up @@ -522,3 +529,11 @@ fn epoch_format_from_str() {
let fmt = Format::from_str("%a, %d %b %Y %H:%M:%S").unwrap();
assert_eq!(fmt, crate::efmt::consts::RFC2822);
}

#[cfg(feature = "std")]
#[test]
fn gh_248_regression() {
let e = Epoch::from_format_str("2023-117T12:55:26", "%Y-%jT%H:%M:%S").unwrap();

assert_eq!(format!("{e}"), "2023-04-28T12:55:26 UTC");
}
2 changes: 1 addition & 1 deletion src/efmt/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/efmt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/epoch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/leap_seconds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/leap_seconds_file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/month.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/python.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/timescale.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/timeseries.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/timeunits.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/ut1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion src/weekday.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Hifitime, part of the Nyx Space tools
* Copyright (C) 2022 Christopher Rabotin <[email protected]> et al. (cf. AUTHORS.md)
* Copyright (C) 2023 Christopher Rabotin <[email protected]> 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.
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_epoch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_utcnow():
dt = datetime.utcnow()

# Hifitime uses a different clock to Python and print down to the nanosecond
assert dt.isoformat()[:21] == f"{epoch}"[:21]
assert dt.isoformat()[:20] == f"{epoch}"[:20]


def test_time_series():
Expand Down

0 comments on commit b58ed96

Please sign in to comment.