/* 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 #include /** * Default implementation of jerry_port_local_tza. * * @return offset between UTC and local time at the given unix timestamp, if * available. Otherwise, returns 0, assuming UTC time. */ 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 */ /** * Default implementation of jerry_port_current_time. * * @return milliseconds since Unix epoch */ 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__) */