Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conversion to Gregorian #303

Merged
merged 17 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor but it was driving me crazy that a duration of one day was printed in plural form.

"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
Loading