Skip to content

Commit b58ed96

Browse files
Merge pull request #253 from nyx-space/248-epochfrom_format_str-does-not-set-hours-minutes-and-seconds
Day of year formatting now parses elapsed time
2 parents f410365 + 559c630 commit b58ed96

24 files changed

Lines changed: 53 additions & 33 deletions

Cargo.toml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hifitime"
3-
version = "3.8.3"
3+
version = "3.8.4"
44
authors = ["Christopher Rabotin <christopher.rabotin@gmail.com>"]
55
description = "Ultra-precise date and time handling in Rust for scientific applications with leap second support"
66
homepage = "https://nyxspace.com/"
@@ -18,14 +18,19 @@ crate-type = ["cdylib", "rlib"]
1818
name = "hifitime"
1919

2020
[dependencies]
21-
serde = {version = "1.0.155", optional = true}
22-
serde_derive = {version = "1.0.155", optional = true}
23-
der = {version = "0.6.1", features = ["derive", "real"], optional = true}
21+
serde = { version = "1.0.155", optional = true }
22+
serde_derive = { version = "1.0.155", optional = true }
23+
der = { version = "0.6.1", features = ["derive", "real"], optional = true }
2424
pyo3 = { version = "0.19.0", features = ["extension-module"], optional = true }
25-
num-traits = {version = "0.2.15", default-features = false, features = ["libm"]}
26-
lexical-core = {version = "0.8.5", default-features = false, features = ["parse-integers", "parse-floats"]}
27-
reqwest = { version = "0.11", features = ["blocking", "json"], optional = true}
28-
tabled = {version = "0.14.0", optional = true}
25+
num-traits = { version = "0.2.15", default-features = false, features = [
26+
"libm",
27+
] }
28+
lexical-core = { version = "0.8.5", default-features = false, features = [
29+
"parse-integers",
30+
"parse-floats",
31+
] }
32+
reqwest = { version = "0.11", features = ["blocking", "json"], optional = true }
33+
tabled = { version = "0.14.0", optional = true }
2934
openssl = { version = "0.10", features = ["vendored"], optional = true }
3035

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

4348
[[bench]]
4449
name = "crit_epoch"
45-
harness = false
50+
harness = false
4651

4752
[[bench]]
4853
name = "crit_duration"

examples/python/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
* Hifitime, part of the Nyx Space tools
3-
* Copyright (C) 2022 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
3+
* Copyright (C) 2023 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
44
* This Source Code Form is subject to the terms of the Apache
55
* v. 2.0. If a copy of the Apache License was not distributed with this
66
* file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.

examples/python/timescales.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
* Hifitime, part of the Nyx Space tools
3-
* Copyright (C) 2022 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
3+
* Copyright (C) 2023 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
44
* This Source Code Form is subject to the terms of the Apache
55
* v. 2.0. If a copy of the Apache License was not distributed with this
66
* file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.

src/asn1der.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Hifitime, part of the Nyx Space tools
3-
* Copyright (C) 2022 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
3+
* Copyright (C) 2023 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
44
* This Source Code Form is subject to the terms of the Apache
55
* v. 2.0. If a copy of the Apache License was not distributed with this
66
* file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.

src/deprecated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Hifitime, part of the Nyx Space tools
3-
* Copyright (C) 2022 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
3+
* Copyright (C) 2023 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
44
* This Source Code Form is subject to the terms of the Apache
55
* v. 2.0. If a copy of the Apache License was not distributed with this
66
* file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.

src/duration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Hifitime, part of the Nyx Space tools
3-
* Copyright (C) 2022 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
3+
* Copyright (C) 2023 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
44
* This Source Code Form is subject to the terms of the Apache
55
* v. 2.0. If a copy of the Apache License was not distributed with this
66
* file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.

src/efmt/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Hifitime, part of the Nyx Space tools
3-
* Copyright (C) 2022 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
3+
* Copyright (C) 2023 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
44
* This Source Code Form is subject to the terms of the Apache
55
* v. 2.0. If a copy of the Apache License was not distributed with this
66
* file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.

src/efmt/format.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Hifitime, part of the Nyx Space tools
3-
* Copyright (C) 2022 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
3+
* Copyright (C) 2023 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
44
* This Source Code Form is subject to the terms of the Apache
55
* v. 2.0. If a copy of the Apache License was not distributed with this
66
* file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.
@@ -309,7 +309,14 @@ impl Format {
309309
};
310310

311311
let epoch = match day_of_year {
312-
Some(days) => Epoch::from_day_of_year(decomposed[0], days, ts),
312+
Some(days) => {
313+
// Parse the elapsed time in the given day
314+
let elapsed = (decomposed[3] as i64) * Unit::Hour
315+
+ (decomposed[4] as i64) * Unit::Minute
316+
+ (decomposed[5] as i64) * Unit::Second
317+
+ (decomposed[6] as i64) * Unit::Nanosecond;
318+
Epoch::from_day_of_year(decomposed[0], days, ts) + elapsed
319+
}
313320
None => Epoch::maybe_from_gregorian(
314321
decomposed[0],
315322
decomposed[1].try_into().unwrap(),
@@ -522,3 +529,11 @@ fn epoch_format_from_str() {
522529
let fmt = Format::from_str("%a, %d %b %Y %H:%M:%S").unwrap();
523530
assert_eq!(fmt, crate::efmt::consts::RFC2822);
524531
}
532+
533+
#[cfg(feature = "std")]
534+
#[test]
535+
fn gh_248_regression() {
536+
let e = Epoch::from_format_str("2023-117T12:55:26", "%Y-%jT%H:%M:%S").unwrap();
537+
538+
assert_eq!(format!("{e}"), "2023-04-28T12:55:26 UTC");
539+
}

src/efmt/formatter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Hifitime, part of the Nyx Space tools
3-
* Copyright (C) 2022 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
3+
* Copyright (C) 2023 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
44
* This Source Code Form is subject to the terms of the Apache
55
* v. 2.0. If a copy of the Apache License was not distributed with this
66
* file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.

src/efmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Hifitime, part of the Nyx Space tools
3-
* Copyright (C) 2022 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
3+
* Copyright (C) 2023 Christopher Rabotin <christopher.rabotin@gmail.com> et al. (cf. AUTHORS.md)
44
* This Source Code Form is subject to the terms of the Apache
55
* v. 2.0. If a copy of the Apache License was not distributed with this
66
* file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0.

0 commit comments

Comments
 (0)