b4bc23078a
Notable changes: - Remove the comments in port impl, that's easily getting to in-consistence - Sync the jerryscript-port.h and 05.PORT-API.md - Fixes the invalid comment in port codes JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com
60 lines
1.6 KiB
C
60 lines
1.6 KiB
C
/* Copyright JS Foundation and other contributors, http://js.foundation
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "jerryscript-port.h"
|
|
|
|
#if defined(__unix__) || defined(__APPLE__)
|
|
|
|
#include <sys/time.h>
|
|
#include <time.h>
|
|
|
|
int32_t
|
|
jerry_port_local_tza (double unix_ms)
|
|
{
|
|
time_t time = (time_t) unix_ms / 1000;
|
|
|
|
#if defined(HAVE_TM_GMTOFF)
|
|
struct tm tm;
|
|
localtime_r (&time, &tm);
|
|
|
|
return ((int32_t) tm.tm_gmtoff) * 1000;
|
|
#else /* !defined(HAVE_TM_GMTOFF) */
|
|
struct tm gmt_tm;
|
|
struct tm local_tm;
|
|
|
|
gmtime_r (&time, &gmt_tm);
|
|
localtime_r (&time, &local_tm);
|
|
|
|
time_t gmt = mktime (&gmt_tm);
|
|
|
|
/* mktime removes the daylight saving time from the result time value, however we want to keep it */
|
|
local_tm.tm_isdst = 0;
|
|
time_t local = mktime (&local_tm);
|
|
|
|
return (int32_t) difftime (local, gmt) * 1000;
|
|
#endif /* HAVE_TM_GMTOFF */
|
|
} /* jerry_port_local_tza */
|
|
|
|
double
|
|
jerry_port_current_time (void)
|
|
{
|
|
struct timeval tv;
|
|
gettimeofday (&tv, NULL);
|
|
|
|
return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
|
|
} /* jerry_port_current_time */
|
|
|
|
#endif /* defined(__unix__) || defined(__APPLE__) */
|