Path: blob/main/system/lib/libc/emscripten_time.c
6162 views
/*1* Copyright 2022 The Emscripten Authors. All rights reserved.2* Emscripten is available under two separate licenses, the MIT license and the3* University of Illinois/NCSA Open Source License. Both these licenses can be4* found in the LICENSE file.5*/67#include <emscripten/emscripten.h>8#include <emscripten/html5.h>9#include <time.h>10#include <stdbool.h>11#include <sys/time.h>12#include <threads.h>13#include "libc.h"1415#include "emscripten_internal.h"1617weak time_t __time(time_t *t) {18double ret = emscripten_date_now() / 1000;19if (t) {20*t = ret;21}22return ret;23}2425static thread_local bool checked_monotonic = false;26static thread_local bool is_monotonic = 0;2728weak int __gettimeofday(struct timeval *restrict tv, void *restrict tz) {29double now_ms = emscripten_date_now();30long long now_s = now_ms / 1000;31tv->tv_sec = now_s; // seconds32tv->tv_usec = (now_ms - (now_s * 1000)) * 1000; // microseconds33return 0;34}3536weak int dysize(int year) {37int leap = ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)));38return leap ? 366 : 365;39}4041weak_alias(__time, time);42weak_alias(__gettimeofday, gettimeofday);434445