Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/libc/emscripten_time.c
6162 views
1
/*
2
* Copyright 2022 The Emscripten Authors. All rights reserved.
3
* Emscripten is available under two separate licenses, the MIT license and the
4
* University of Illinois/NCSA Open Source License. Both these licenses can be
5
* found in the LICENSE file.
6
*/
7
8
#include <emscripten/emscripten.h>
9
#include <emscripten/html5.h>
10
#include <time.h>
11
#include <stdbool.h>
12
#include <sys/time.h>
13
#include <threads.h>
14
#include "libc.h"
15
16
#include "emscripten_internal.h"
17
18
weak time_t __time(time_t *t) {
19
double ret = emscripten_date_now() / 1000;
20
if (t) {
21
*t = ret;
22
}
23
return ret;
24
}
25
26
static thread_local bool checked_monotonic = false;
27
static thread_local bool is_monotonic = 0;
28
29
weak int __gettimeofday(struct timeval *restrict tv, void *restrict tz) {
30
double now_ms = emscripten_date_now();
31
long long now_s = now_ms / 1000;
32
tv->tv_sec = now_s; // seconds
33
tv->tv_usec = (now_ms - (now_s * 1000)) * 1000; // microseconds
34
return 0;
35
}
36
37
weak int dysize(int year) {
38
int leap = ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)));
39
return leap ? 366 : 365;
40
}
41
42
weak_alias(__time, time);
43
weak_alias(__gettimeofday, gettimeofday);
44
45