Skip to content

Commit 6a848a3

Browse files
ossy-szegedrerobika
authored andcommitted
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 [email protected]
1 parent cd7720e commit 6a848a3

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-date.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,6 @@ ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
277277
{
278278
hours = ecma_number_make_nan ();
279279
}
280-
else if (hours == 24)
281-
{
282-
hours = ECMA_NUMBER_ZERO;
283-
}
284280

285281
if (date_str_curr_p < date_str_end_p
286282
&& *date_str_curr_p == ':')
@@ -324,6 +320,11 @@ ecma_builtin_date_parse (ecma_value_t this_arg, /**< this argument */
324320
}
325321
}
326322

323+
if (hours == 24 && (minutes != 0 || seconds != 0 || milliseconds != 0))
324+
{
325+
hours = ecma_number_make_nan ();
326+
}
327+
327328
time = ecma_date_make_time (hours, minutes, seconds, milliseconds);
328329
}
329330
else

tests/jerry/date-parse.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ var wrongFormats = ["",
3636
"2015-01-01T00:",
3737
"2015-01-01T00:00:00.1",
3838
"2015-01-01T00:00:00.01",
39+
"2015-01-01T24:01:00.000",
40+
"2015-01-01T24:00:01.000",
41+
"2015-01-01T24:00:00.001",
3942
"2015-01-01T00:00+01:00Z",
4043
"2015/01/01",
4144
"2015-01-32",
@@ -93,7 +96,7 @@ d = Date.parse("2015-01T00:00:00.000");
9396
assert (d == 1420070400000);
9497

9598
d = Date.parse("2015-01T24:00:00.000");
96-
assert (d == 1420070400000);
99+
assert (d == 1420156800000);
97100

98101
d = Date.parse("2015-01T00:00:00.000+03:00");
99102
assert (d == 1420059600000);

0 commit comments

Comments
 (0)