diff --git a/lib/src/crypto/x509.rs b/lib/src/crypto/x509.rs index c49bc039c..b25c52c37 100644 --- a/lib/src/crypto/x509.rs +++ b/lib/src/crypto/x509.rs @@ -12,7 +12,7 @@ use std::{ result::Result, }; -use chrono::{DateTime, TimeZone, Utc}; +use chrono::{DateTime, NaiveDateTime, Utc}; use openssl::{ asn1::*, hash, @@ -593,7 +593,8 @@ impl X509 { } else { date }; - Utc.datetime_from_str(date, "%b %d %H:%M:%S %Y") + NaiveDateTime::parse_from_str(date, "%b %d %H:%M:%S %Y") + .map(|naive| naive.and_utc()) .map_err(|e| { error!("Cannot parse ASN1 date, err = {:?}", e); X509Error diff --git a/lib/src/types/date_time.rs b/lib/src/types/date_time.rs index a400da55f..7302abd19 100644 --- a/lib/src/types/date_time.rs +++ b/lib/src/types/date_time.rs @@ -140,12 +140,18 @@ impl From<(u16, u16, u16, u16, u16, u16, u32)> for DateTime { if nanos as i64 >= NANOS_PER_SECOND { panic!("Invalid nanosecond"); } - let dt = Utc.ymd(year as i32, month as u32, day as u32).and_hms_nano( - hour as u32, - minute as u32, - second as u32, - nanos, - ); + let dt = Utc + .with_ymd_and_hms( + year as i32, + month as u32, + day as u32, + hour as u32, + minute as u32, + second as u32, + ) + .unwrap() + .with_nanosecond(nanos) + .unwrap(); DateTime::from(dt) } } @@ -211,12 +217,10 @@ impl DateTime { /// in and out of rfc3999 without any loss of precision to make it easier to do comparison tests. #[cfg(test)] pub fn rfc3339_now() -> DateTime { - use chrono::NaiveDateTime; use std::time::{SystemTime, UNIX_EPOCH}; let duration = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); - let naive = NaiveDateTime::from_timestamp(duration.as_secs() as i64, 0); - let now = DateTimeUtc::from_utc(naive, Utc); + let now = DateTimeUtc::from_timestamp(duration.as_secs() as i64, 0).unwrap(); DateTime::from(now) } @@ -327,13 +331,15 @@ impl DateTime { /// The OPC UA epoch - Jan 1 1601 00:00:00 fn epoch_chrono() -> DateTimeUtc { - Utc.ymd(MIN_YEAR as i32, 1, 1).and_hms(0, 0, 0) + Utc.with_ymd_and_hms(MIN_YEAR as i32, 1, 1, 0, 0, 0) + .unwrap() } /// The OPC UA endtimes - Dec 31 9999 23:59:59 i.e. the date after which dates are returned as MAX_INT64 ticks /// Spec doesn't say what happens in the last second before midnight... fn endtimes_chrono() -> DateTimeUtc { - Utc.ymd(MAX_YEAR as i32, 12, 31).and_hms(23, 59, 59) + Utc.with_ymd_and_hms(MAX_YEAR as i32, 12, 31, 23, 59, 59) + .unwrap() } /// Turns a duration to ticks