made `Time::fmt` to use the same decimal separator as `Duration::fmt`.

This commit is contained in:
Kang Seonghoon 2014-07-31 11:03:32 +09:00
parent ead13f66d8
commit ed71a1037b
1 changed files with 8 additions and 8 deletions

View File

@ -217,11 +217,11 @@ impl fmt::Show for NaiveTime {
if nano == 0 { if nano == 0 {
Ok(()) Ok(())
} else if nano % 1_000_000 == 0 { } else if nano % 1_000_000 == 0 {
write!(f, ",{:03}", nano / 1_000_000) write!(f, ".{:03}", nano / 1_000_000)
} else if nano % 1_000 == 0 { } else if nano % 1_000 == 0 {
write!(f, ",{:06}", nano / 1_000) write!(f, ".{:06}", nano / 1_000)
} else { } else {
write!(f, ",{:09}", nano) write!(f, ".{:09}", nano)
} }
} }
} }
@ -336,19 +336,19 @@ mod tests {
#[test] #[test]
fn test_time_fmt() { fn test_time_fmt() {
assert_eq!(NaiveTime::from_hms_milli(23, 59, 59, 999).to_string(), assert_eq!(NaiveTime::from_hms_milli(23, 59, 59, 999).to_string(),
"23:59:59,999".to_string()); "23:59:59.999".to_string());
assert_eq!(NaiveTime::from_hms_milli(23, 59, 59, 1_000).to_string(), assert_eq!(NaiveTime::from_hms_milli(23, 59, 59, 1_000).to_string(),
"23:59:60".to_string()); "23:59:60".to_string());
assert_eq!(NaiveTime::from_hms_milli(23, 59, 59, 1_001).to_string(), assert_eq!(NaiveTime::from_hms_milli(23, 59, 59, 1_001).to_string(),
"23:59:60,001".to_string()); "23:59:60.001".to_string());
assert_eq!(NaiveTime::from_hms_micro(0, 0, 0, 43210).to_string(), assert_eq!(NaiveTime::from_hms_micro(0, 0, 0, 43210).to_string(),
"00:00:00,043210".to_string()); "00:00:00.043210".to_string());
assert_eq!(NaiveTime::from_hms_nano(0, 0, 0, 6543210).to_string(), assert_eq!(NaiveTime::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 `NaiveTime` // the format specifier should have no effect on `NaiveTime`
assert_eq!(format!("{:30}", NaiveTime::from_hms_milli(3, 5, 7, 9)), assert_eq!(format!("{:30}", NaiveTime::from_hms_milli(3, 5, 7, 9)),
"03:05:07,009".to_string()); "03:05:07.009".to_string());
} }
} }