Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JEnoch committed Jul 1, 2024
1 parent 6b159d9 commit b0edeac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/ntp64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,22 @@ mod tests {
#[test]
fn to_string_rfc3339() {
use crate::*;
use regex::Regex;

let rfc3339_regex = Regex::new(
r"^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]Z$"
).unwrap();

let now = SystemTime::now();
let t = NTP64::from(SystemTime::now().duration_since(UNIX_EPOCH).unwrap());
let t = NTP64::from(now.duration_since(UNIX_EPOCH).unwrap());

let rfc3339 = t.to_string_rfc3339();
assert_eq!(rfc3339, humantime::format_rfc3339_nanos(now).to_string());
assert!(rfc3339_regex.is_match(&rfc3339));

// Test that alternate format "{:#}" displays in RFC3339 format
let rfc3339_2 = format!("{t:#}");
assert_eq!(rfc3339_2, humantime::format_rfc3339_nanos(now).to_string());
assert!(rfc3339_regex.is_match(&rfc3339_2));
}
}
1 change: 1 addition & 0 deletions src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl fmt::Display for Timestamp {
/// # Examples
/// ```
/// use uhlc::*;
/// use std::convert::TryFrom;
///
/// let t =Timestamp::new(NTP64(7386690599959157260), ID::try_from([0x33]).unwrap());
/// println!("{t}"); // displays: 7386690599959157260/33
Expand Down

0 comments on commit b0edeac

Please sign in to comment.