Fix Date.parse to handle times without timezone properly (#4249)

https://www.ecma-international.org/ecma-262/11.0/#sec-date.parse
"When the UTC offset representation is absent, date-only forms are
interpreted as a UTC time and date-time forms are interpreted as a local time."

JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác csaba.osztrogonac@h-lab.eu
This commit is contained in:
Csaba Osztrogonác
2020-10-01 16:34:59 +02:00
committed by GitHub
parent e227634b45
commit 8fe3891b15
3 changed files with 19 additions and 6 deletions
@@ -293,6 +293,7 @@ ecma_builtin_date_parse_ISO_string_format (const lit_utf8_byte_t *date_str_curr_
day = ecma_date_parse_date_chars (&date_str_curr_p, date_str_end_p, 2, 1, 31);
}
bool is_utc = true;
/* 4. read time if any */
if (ecma_date_parse_special_char (&date_str_curr_p, date_str_end_p, 'T'))
{
@@ -367,13 +368,24 @@ ecma_builtin_date_parse_ISO_string_format (const lit_utf8_byte_t *date_str_curr_
ecma_number_t timezone_offset = ecma_date_make_time (hours, minutes, ECMA_NUMBER_ZERO, ECMA_NUMBER_ZERO);
time += is_timezone_sign_negative ? timezone_offset : -timezone_offset;
}
else
{
is_utc = false;
}
}
}
if (date_str_curr_p >= date_str_end_p)
{
ecma_number_t date = ecma_date_make_day (year, month - 1, day);
return ecma_date_make_date (date, time);
ecma_number_t result_date = ecma_date_make_date (date, time);
if (!is_utc)
{
result_date = ecma_date_utc (result_date);
}
return result_date;
}
}
return ecma_number_make_nan ();