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:
@@ -27,11 +27,6 @@
|
||||
|
||||
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_DATE_BUILTIN
|
||||
|
||||
#ifdef JERRY_ENABLE_DATE_SYS_CALLS
|
||||
#include <sys/time.h>
|
||||
|
||||
#endif /* JERRY_ENABLE_DATE_SYS_CALLS */
|
||||
|
||||
/** \addtogroup ecma ECMA
|
||||
* @{
|
||||
*
|
||||
@@ -451,21 +446,14 @@ ecma_date_week_day (ecma_number_t time) /**< time value */
|
||||
inline ecma_number_t __attr_always_inline___
|
||||
ecma_date_local_tza ()
|
||||
{
|
||||
#ifdef JERRY_ENABLE_DATE_SYS_CALLS
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
jerry_time_zone_t tz;
|
||||
|
||||
tz.tz_minuteswest = 0; /* gettimeofday may not fill tz, so zero-initializing */
|
||||
|
||||
if (gettimeofday (&tv, &tz) != 0)
|
||||
if (!jerry_port_get_time_zone (&tz))
|
||||
{
|
||||
return ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
return tz.tz_minuteswest * -ECMA_DATE_MS_PER_MINUTE;
|
||||
#else /* !JERRY_ENABLE_DATE_SYS_CALLS */
|
||||
return ECMA_NUMBER_ZERO;
|
||||
#endif /* JERRY_ENABLE_DATE_SYS_CALLS */
|
||||
return tz.offset * -ECMA_DATE_MS_PER_MINUTE;
|
||||
} /* ecma_date_local_tza */
|
||||
|
||||
/**
|
||||
@@ -484,21 +472,14 @@ ecma_date_daylight_saving_ta (ecma_number_t time) /**< time value */
|
||||
return time; /* time is NaN */
|
||||
}
|
||||
|
||||
#ifdef JERRY_ENABLE_DATE_SYS_CALLS
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
jerry_time_zone_t tz;
|
||||
|
||||
tz.tz_dsttime = 0; /* gettimeofday may not fill tz, so zero-initializing */
|
||||
|
||||
if (gettimeofday (&tv, &tz) != 0)
|
||||
if (!jerry_port_get_time_zone (&tz))
|
||||
{
|
||||
return ecma_number_make_nan ();
|
||||
}
|
||||
|
||||
return tz.tz_dsttime;
|
||||
#else /* !JERRY_ENABLE_DATE_SYS_CALLS */
|
||||
return ECMA_NUMBER_ZERO;
|
||||
#endif /* JERRY_ENABLE_DATE_SYS_CALLS */
|
||||
return tz.daylight_saving_time * ECMA_DATE_MS_PER_HOUR;
|
||||
} /* ecma_date_daylight_saving_ta */
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user