Skip to content

Commit

Permalink
fixed erratic fmt behaviors with format specifiers. (rust-lang/rust…
Browse files Browse the repository at this point in the history
  • Loading branch information
lifthrasiir committed Jul 25, 2014
1 parent b79f6b3 commit f7065f1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/date.rs
Expand Up @@ -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());
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/duration.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
}
}

4 changes: 4 additions & 0 deletions src/time.rs
Expand Up @@ -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());
}
}

0 comments on commit f7065f1

Please sign in to comment.