Make Date.parse handle 24:00:00.000 time properly (#3196)

ES5.1 15.9.1.15 Note1 defines that 24:00 is same as 0:00
of the next day. The spec explicitly doesn't mention that
24:01 should be invalid, but it should be self-evident.
(FireFox and Chrome also refuses times bigger than 24:00)

JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác oszi@inf.u-szeged.hu
This commit is contained in:
Csaba Osztrogonác 2019-10-03 09:49:51 +02:00 committed by Robert Fancsik
parent cd7720ee08
commit 6a848a36fd
2 changed files with 9 additions and 5 deletions

View File

@ -277,10 +277,6 @@ ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
{
hours = ecma_number_make_nan ();
}
else if (hours == 24)
{
hours = ECMA_NUMBER_ZERO;
}
if (date_str_curr_p < date_str_end_p
&& *date_str_curr_p == ':')
@ -324,6 +320,11 @@ ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
}
}
if (hours == 24 && (minutes != 0 || seconds != 0 || milliseconds != 0))
{
hours = ecma_number_make_nan ();
}
time = ecma_date_make_time (hours, minutes, seconds, milliseconds);
}
else

View File

@ -36,6 +36,9 @@ var wrongFormats = ["",
"2015-01-01T00:",
"2015-01-01T00:00:00.1",
"2015-01-01T00:00:00.01",
"2015-01-01T24:01:00.000",
"2015-01-01T24:00:01.000",
"2015-01-01T24:00:00.001",
"2015-01-01T00:00+01:00Z",
"2015/01/01",
"2015-01-32",
@ -93,7 +96,7 @@ d = Date.parse("2015-01T00:00:00.000");
assert (d == 1420070400000);
d = Date.parse("2015-01T24:00:00.000");
assert (d == 1420070400000);
assert (d == 1420156800000);
d = Date.parse("2015-01T00:00:00.000+03:00");
assert (d == 1420059600000);