Skip to content

Commit cb55ba9

Browse files
Merge pull request #303 from nyx-space/bug/261-jde_utc_days-error
Fix conversion to Gregorian
2 parents a48d457 + 39a5d43 commit cb55ba9

File tree

6 files changed

+205
-143
lines changed

6 files changed

+205
-143
lines changed

src/duration/kani_verif.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// Here lives all of the formal verification for Duration.
1212

13-
use super::{Duration, DurationError};
13+
use super::{Duration, DurationError, EpochError};
1414
use crate::NANOSECONDS_PER_CENTURY;
1515

1616
use kani::Arbitrary;
@@ -43,9 +43,9 @@ fn formal_duration_truncated_ns_reciprocity() {
4343
// Then it does not fit on a i64, so this function should return an error
4444
assert_eq!(
4545
dur_from_part.try_truncated_nanoseconds(),
46-
Err(Err(EpochError::Duration {
46+
Err(EpochError::Duration {
4747
source: DurationError::Overflow,
48-
}))
48+
})
4949
);
5050
} else if centuries == -1 {
5151
// If we are negative by just enough that the centuries is negative, then the truncated seconds

src/duration/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
* Documentation: https://nyxspace.com/
99
*/
1010

11-
use crate::errors::DurationError;
12-
use crate::{
13-
EpochError, SECONDS_PER_CENTURY, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE,
14-
};
11+
use crate::errors::{DurationError, EpochError};
12+
use crate::{SECONDS_PER_CENTURY, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE};
1513

1614
pub use crate::{Freq, Frequencies, TimeUnits, Unit};
1715

@@ -692,7 +690,15 @@ impl fmt::Display for Duration {
692690
}
693691

694692
let values = [days, hours, minutes, seconds, milli, us, nano];
695-
let units = ["days", "h", "min", "s", "ms", "μs", "ns"];
693+
let units = [
694+
if days > 1 { "days" } else { "day" },
695+
"h",
696+
"min",
697+
"s",
698+
"ms",
699+
"μs",
700+
"ns",
701+
];
696702

697703
let mut insert_space = false;
698704
for (val, unit) in values.iter().zip(units.iter()) {
@@ -767,7 +773,7 @@ mod ut_duration {
767773
fn test_serdes() {
768774
for (dt, content) in [
769775
(Duration::from_seconds(10.1), r#""10 s 100 ms""#),
770-
(1.0_f64.days() + 99.nanoseconds(), r#""1 days 99 ns""#),
776+
(1.0_f64.days() + 99.nanoseconds(), r#""1 day 99 ns""#),
771777
(
772778
1.0_f64.centuries() + 99.seconds(),
773779
r#""36525 days 1 min 39 s""#,

0 commit comments

Comments
 (0)