From df4912a33f440914c8f22087ca954eb48c66a8b7 Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Wed, 13 Jun 2018 23:00:20 -0400 Subject: [PATCH] Test formatting with more precise nanoseconds There is some specific behavior around writing out truncated nanos that we want to be sure to preserve. --- src/format/strftime.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/format/strftime.rs b/src/format/strftime.rs index 7b66665..d7cf68c 100644 --- a/src/format/strftime.rs +++ b/src/format/strftime.rs @@ -408,9 +408,9 @@ fn test_strftime_items() { #[cfg(test)] #[test] fn test_strftime_docs() { - use {FixedOffset, TimeZone}; + use {FixedOffset, TimeZone, Timelike}; - let dt = FixedOffset::east(34200).ymd(2001, 7, 8).and_hms_nano(0, 34, 59, 1_026_490_000); + let dt = FixedOffset::east(34200).ymd(2001, 7, 8).and_hms_nano(0, 34, 59, 1_026_490_708); // date specifiers assert_eq!(dt.format("%Y").to_string(), "2001"); @@ -449,14 +449,16 @@ fn test_strftime_docs() { assert_eq!(dt.format("%p").to_string(), "AM"); assert_eq!(dt.format("%M").to_string(), "34"); assert_eq!(dt.format("%S").to_string(), "60"); - assert_eq!(dt.format("%f").to_string(), "026490000"); - assert_eq!(dt.format("%.f").to_string(), ".026490"); + assert_eq!(dt.format("%f").to_string(), "026490708"); + assert_eq!(dt.format("%.f").to_string(), ".026490708"); + assert_eq!(dt.with_nanosecond(1_026_490_000).unwrap().format("%.f").to_string(), + ".026490"); assert_eq!(dt.format("%.3f").to_string(), ".026"); assert_eq!(dt.format("%.6f").to_string(), ".026490"); - assert_eq!(dt.format("%.9f").to_string(), ".026490000"); + assert_eq!(dt.format("%.9f").to_string(), ".026490708"); assert_eq!(dt.format("%3f").to_string(), "026"); assert_eq!(dt.format("%6f").to_string(), "026490"); - assert_eq!(dt.format("%9f").to_string(), "026490000"); + assert_eq!(dt.format("%9f").to_string(), "026490708"); assert_eq!(dt.format("%R").to_string(), "00:34"); assert_eq!(dt.format("%T").to_string(), "00:34:60"); assert_eq!(dt.format("%X").to_string(), "00:34:60"); @@ -469,7 +471,9 @@ fn test_strftime_docs() { // date & time specifiers assert_eq!(dt.format("%c").to_string(), "Sun Jul 8 00:34:60 2001"); - assert_eq!(dt.format("%+").to_string(), "2001-07-08T00:34:60.026490+09:30"); + assert_eq!(dt.format("%+").to_string(), "2001-07-08T00:34:60.026490708+09:30"); + assert_eq!(dt.with_nanosecond(1_026_490_000).unwrap().format("%+").to_string(), + "2001-07-08T00:34:60.026490+09:30"); assert_eq!(dt.format("%s").to_string(), "994518299"); // special specifiers