Introduce the Date Port API

Replaced `gettimeofday`-related code with `jerry_port_get_current_time`
and `jerry_port_get_time_zone` function calls. Moved old code to
default port implementation.

Removed `ENABLE_DATE_SYS_CALLS` as date syscalls should "just work".

Fix DST adjustments: even if `gettimeofday` returns meaningful data in
`tz_dsttime`, the value is just a flag (or, according to some sources,
a tri-state value: >0 if DST applies, ==0 if DST does not apply, <0 if
unknown). Hitherto, the field was simply added to/subtracted from a
time value in milliseconds. To use it approximately correctly, the
field's value should be multiplied by "millisecs/hour".

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2016-04-18 20:54:18 +02:00
parent a3b1db3638
commit b523cf3cd1
6 changed files with 91 additions and 52 deletions
@@ -33,10 +33,6 @@
#define BUILTIN_UNDERSCORED_ID date
#include "ecma-builtin-internal-routines-template.inc.h"
#ifdef JERRY_ENABLE_DATE_SYS_CALLS
#include <sys/time.h>
#endif /* JERRY_ENABLE_DATE_SYS_CALLS */
/** \addtogroup ecma ECMA
* @{
*
@@ -450,18 +446,8 @@ static ecma_value_t
ecma_builtin_date_now (ecma_value_t this_arg __attr_unused___) /**< this argument */
{
ecma_number_t *now_num_p = ecma_alloc_number ();
*now_num_p = ECMA_NUMBER_ZERO;
#ifdef JERRY_ENABLE_DATE_SYS_CALLS
struct timeval tv;
if (gettimeofday (&tv, NULL) != 0)
{
return ecma_raise_type_error (ECMA_ERR_MSG ("gettimeofday failed"));
}
*now_num_p = ((ecma_number_t) tv.tv_sec) * 1000.0 + ((ecma_number_t) (tv.tv_usec / 1000));
#endif /* JERRY_ENABLE_DATE_SYS_CALLS */
*now_num_p = (ecma_number_t) jerry_port_get_current_time ();
return ecma_make_number_value (now_num_p);
} /* ecma_builtin_date_now */