Skip to content

Commit

Permalink
Merge branch '4.0.0-dev' into 4.0.0-dev-nyx-spacegh-237
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherRabotin committed Jun 12, 2023
2 parents c6218ef + 8396a4d commit 846418e
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 219 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hifitime"
version = "3.8.1"
version = "4.0.0-dev"
authors = ["Christopher Rabotin <christopher.rabotin@gmail.com>"]
description = "Ultra-precise date and time handling in Rust for scientific applications with leap second support"
homepage = "https://nyxspace.com/"
Expand All @@ -21,7 +21,7 @@ name = "hifitime"
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.18.1", features = ["extension-module"], 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}
Expand All @@ -30,7 +30,7 @@ openssl = { version = "0.10", features = ["vendored"], optional = true }

[dev-dependencies]
serde_json = "1.0.91"
criterion = "0.4.0"
criterion = "0.5.1"
iai = "0.1"

[features]
Expand Down
432 changes: 227 additions & 205 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/duration/kani.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn formal_duration_truncated_ns_reciprocity() {
// We fit on a i64 but we need to account for the number of nanoseconds wrapped to the negative centuries.

let nanos = u_ns.rem_euclid(NANOSECONDS_PER_CENTURY);
let expect_rslt = i64::from(centuries + 1) * NANOSECONDS_PER_CENTURY as i64 + nanos as i64;
let expect_rslt = i64::from(centuries) * NANOSECONDS_PER_CENTURY as i64 + nanos as i64;

let recip_ns = dur_from_part.try_truncated_nanoseconds().unwrap();
assert_eq!(recip_ns, expect_rslt);
Expand Down
2 changes: 1 addition & 1 deletion src/duration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl Duration {
+ i128::from(self.nanoseconds)
} else {
// Centuries negative by a decent amount
i128::from(self.centuries) * i128::from(NANOSECONDS_PER_CENTURY)
i128::from(self.centuries + 1) * i128::from(NANOSECONDS_PER_CENTURY)
- i128::from(self.nanoseconds)
}
}
Expand Down
15 changes: 11 additions & 4 deletions src/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ impl Epoch {

// Add the seconds for the months prior to the current month
duration_wrt_1900 += Unit::Day * i64::from(CUMULATIVE_DAYS_FOR_MONTH[(month - 1) as usize]);

if is_leap_year(year) && month > 2 {
// NOTE: If on 29th of February, then the day is not finished yet, and therefore
// the extra seconds are added below as per a normal day.
Expand Down Expand Up @@ -1217,7 +1218,7 @@ impl Epoch {
day = if sign >= 0 {
days_in_year - days_so_far + 1.0
} else {
days_in_year - days_so_far - 1.0
days_in_year - days_so_far
};
break;
}
Expand All @@ -1237,9 +1238,6 @@ impl Epoch {
} else {
usual_days_per_month(11) as f64
};
} else if sign < 0 {
// Must add one day because just below, we'll be ignoring the days when rebuilding the time.
day += 1.0;
}

if sign < 0 {
Expand All @@ -1254,6 +1252,15 @@ impl Epoch {
nanos,
);

// Last check on the validity of the Gregorian date

if time == Duration::ZERO || month == 12 && day == 32.0 {
// We've underflowed since we're before 1900.
year += 1;
month = 1;
day = 1.0;
}

let (_, _, hours, minutes, seconds, milliseconds, microseconds, nanos) =
(24 * Unit::Hour + time).decompose();

Expand Down
6 changes: 1 addition & 5 deletions src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ impl Default for MonthName {
}
}

impl MonthName {
const MAX: u8 = 12;
}

impl FromStr for MonthName {
type Err = ParsingErrors;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Expand All @@ -70,7 +66,7 @@ impl FromStr for MonthName {

impl From<u8> for MonthName {
fn from(u: u8) -> Self {
match u.rem_euclid(Self::MAX) {
match u {
1 => Self::January,
2 => Self::February,
3 => Self::March,
Expand Down
21 changes: 21 additions & 0 deletions tests/epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,3 +1941,24 @@ fn test_leap_seconds_file() {
}
}
}

#[test]
fn regression_test_gh_204() {
use core::str::FromStr;
use hifitime::Epoch;

let e1700 = Epoch::from_str("1700-01-01T00:00:00 TAI").unwrap();
assert_eq!(format!("{e1700:x}"), "1700-01-01T00:00:00 TAI");

let e1700 = Epoch::from_str("1700-04-17T02:10:09 TAI").unwrap();
assert_eq!(format!("{e1700:x}"), "1700-04-17T02:10:09 TAI");

let e1799 = Epoch::from_str("1799-01-01T00:00:01 TAI").unwrap();
assert_eq!(format!("{e1799:x}"), "1799-01-01T00:00:01 TAI");

let e1899 = Epoch::from_str("1899-01-01T00:00:00 TAI").unwrap();
assert_eq!(format!("{e1899:x}"), "1899-01-01T00:00:00 TAI");

let e1900_m1 = Epoch::from_str("1899-12-31T23:59:59 TAI").unwrap();
assert_eq!(format!("{e1900_m1:x}"), "1899-12-31T23:59:59 TAI");
}

0 comments on commit 846418e

Please sign in to comment.