Make sure input value=12:30:01 doesn't turn into 12:30:1

This commit is contained in:
Patrick Shaughnessy 2020-01-11 14:19:37 -05:00
parent 419954474b
commit 6dc8f67f8f
3 changed files with 70 additions and 0 deletions

View file

@ -474,7 +474,15 @@ impl DOMString {
"{:04}-{:02}-{:02}T{:02}:{:02}",
year, month, day, hour, minute
);
} else if second < 10.0 {
// we need exactly one leading zero on the seconds,
// whatever their total string length might be
self.0 = format!(
"{:04}-{:02}-{:02}T{:02}:{:02}:0{}",
year, month, day, hour, minute, second
);
} else {
// we need no leading zeroes on the seconds
self.0 = format!(
"{:04}-{:02}-{:02}T{:02}:{:02}:{}",
year, month, day, hour, minute, second