diff --git a/src/date.rs b/src/date.rs index 80e964f033..f1cfdaf1a7 100644 --- a/src/date.rs +++ b/src/date.rs @@ -751,6 +751,10 @@ mod tests { assert_eq!(DateZ::from_ymd(0, 3, 4).to_string(), "0000-03-04".to_string()); assert_eq!(DateZ::from_ymd(-307, 3, 4).to_string(), "-0307-03-04".to_string()); assert_eq!(DateZ::from_ymd(12345, 3, 4).to_string(), "+12345-03-04".to_string()); + + // the format specifier should have no effect on `TimeZ` + assert_eq!(format!("{:+30}", DateZ::from_ymd(1234, 5, 6)), "1234-05-06".to_string()); + assert_eq!(format!("{:30}", DateZ::from_ymd(12345, 6, 7)), "+12345-06-07".to_string()); } } diff --git a/src/duration.rs b/src/duration.rs index 5658adaa35..4d9493aabc 100644 --- a/src/duration.rs +++ b/src/duration.rs @@ -255,7 +255,7 @@ impl fmt::Show for Duration { let hasdate = self.days != 0; let hastime = (self.secs != 0 || self.nanos != 0) || !hasdate; - try!('P'.fmt(f)); + try!(write!(f, "P")); if hasdate { // technically speaking the negative part is not the valid ISO 8601, // but we need to print it anyway. @@ -344,6 +344,10 @@ mod tests { assert_eq!(Duration::nanoseconds(42).to_string(), "PT0,000000042S".to_string()); assert_eq!((Duration::days(7) + Duration::milliseconds(6543)).to_string(), "P7DT6,543S".to_string()); + + // the format specifier should have no effect on `Duration` + assert_eq!(format!("{:30}", Duration::days(1) + Duration::milliseconds(2345)), + "P1DT2,345S".to_string()); } } diff --git a/src/time.rs b/src/time.rs index ff90952ab2..84b235d455 100644 --- a/src/time.rs +++ b/src/time.rs @@ -332,6 +332,10 @@ mod tests { "00:00:00,043210".to_string()); assert_eq!(TimeZ::from_hms_nano(0, 0, 0, 6543210).to_string(), "00:00:00,006543210".to_string()); + + // the format specifier should have no effect on `TimeZ` + assert_eq!(format!("{:30}", TimeZ::from_hms_milli(3, 5, 7, 9)), + "03:05:07,009".to_string()); } }