fixed erratic `fmt` behaviors with format specifiers. (rust-lang/rust#15934)
This commit is contained in:
parent
b79f6b302b
commit
f7065f1625
|
@ -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(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(-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());
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,7 +255,7 @@ impl fmt::Show for Duration {
|
||||||
let hasdate = self.days != 0;
|
let hasdate = self.days != 0;
|
||||||
let hastime = (self.secs != 0 || self.nanos != 0) || !hasdate;
|
let hastime = (self.secs != 0 || self.nanos != 0) || !hasdate;
|
||||||
|
|
||||||
try!('P'.fmt(f));
|
try!(write!(f, "P"));
|
||||||
if hasdate {
|
if hasdate {
|
||||||
// technically speaking the negative part is not the valid ISO 8601,
|
// technically speaking the negative part is not the valid ISO 8601,
|
||||||
// but we need to print it anyway.
|
// 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::nanoseconds(42).to_string(), "PT0,000000042S".to_string());
|
||||||
assert_eq!((Duration::days(7) + Duration::milliseconds(6543)).to_string(),
|
assert_eq!((Duration::days(7) + Duration::milliseconds(6543)).to_string(),
|
||||||
"P7DT6,543S".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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -332,6 +332,10 @@ mod tests {
|
||||||
"00:00:00,043210".to_string());
|
"00:00:00,043210".to_string());
|
||||||
assert_eq!(TimeZ::from_hms_nano(0, 0, 0, 6543210).to_string(),
|
assert_eq!(TimeZ::from_hms_nano(0, 0, 0, 6543210).to_string(),
|
||||||
"00:00:00,006543210".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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue