Skip to content

Commit

Permalink
Merge pull request #303 from nyx-space/bug/261-jde_utc_days-error
Browse files Browse the repository at this point in the history
Fix conversion to Gregorian
  • Loading branch information
ChristopherRabotin authored May 20, 2024
2 parents a48d457 + 39a5d43 commit cb55ba9
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 143 deletions.
6 changes: 3 additions & 3 deletions src/duration/kani_verif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

use super::{Duration, DurationError};
use super::{Duration, DurationError, EpochError};
use crate::NANOSECONDS_PER_CENTURY;

use kani::Arbitrary;
Expand Down Expand Up @@ -43,9 +43,9 @@ fn formal_duration_truncated_ns_reciprocity() {
// Then it does not fit on a i64, so this function should return an error
assert_eq!(
dur_from_part.try_truncated_nanoseconds(),
Err(Err(EpochError::Duration {
Err(EpochError::Duration {
source: DurationError::Overflow,
}))
})
);
} else if centuries == -1 {
// If we are negative by just enough that the centuries is negative, then the truncated seconds
Expand Down
18 changes: 12 additions & 6 deletions src/duration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
* Documentation: https://nyxspace.com/
*/

use crate::errors::DurationError;
use crate::{
EpochError, SECONDS_PER_CENTURY, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE,
};
use crate::errors::{DurationError, EpochError};
use crate::{SECONDS_PER_CENTURY, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE};

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

Expand Down Expand Up @@ -692,7 +690,15 @@ impl fmt::Display for Duration {
}

let values = [days, hours, minutes, seconds, milli, us, nano];
let units = ["days", "h", "min", "s", "ms", "μs", "ns"];
let units = [
if days > 1 { "days" } else { "day" },
"h",
"min",
"s",
"ms",
"μs",
"ns",
];

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

0 comments on commit cb55ba9

Please sign in to comment.