xbintsc 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/runtime/xt_stdlib2.c +17 -2
package/package.json
CHANGED
package/runtime/xt_stdlib2.c
CHANGED
|
@@ -19,6 +19,21 @@
|
|
|
19
19
|
#include <string.h>
|
|
20
20
|
#include <time.h>
|
|
21
21
|
|
|
22
|
+
/*
|
|
23
|
+
* `timegm` and `gmtime_r` are POSIX extensions that MSVC's CRT does not
|
|
24
|
+
* provide. Wrap the platform-specific equivalents so the Date implementation
|
|
25
|
+
* below compiles everywhere.
|
|
26
|
+
*/
|
|
27
|
+
#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__)
|
|
28
|
+
static time_t xt_timegm(struct tm *tm) { return (time_t)_mkgmtime64(tm); }
|
|
29
|
+
static struct tm *xt_gmtime_r(const time_t *timer, struct tm *buf) {
|
|
30
|
+
return gmtime_s(buf, timer) == 0 ? buf : NULL;
|
|
31
|
+
}
|
|
32
|
+
#else
|
|
33
|
+
static time_t xt_timegm(struct tm *tm) { return timegm(tm); }
|
|
34
|
+
static struct tm *xt_gmtime_r(const time_t *timer, struct tm *buf) { return gmtime_r(timer, buf); }
|
|
35
|
+
#endif
|
|
36
|
+
|
|
22
37
|
int xt_value_equals(xt_value a, xt_value b) {
|
|
23
38
|
if (XT_IS_NUMBER(a) && XT_IS_NUMBER(b)) {
|
|
24
39
|
double x = xt_to_double(a);
|
|
@@ -943,7 +958,7 @@ xt_value xt_date_static(xt_value name, int32_t argc, xt_value *argv) {
|
|
|
943
958
|
tm.tm_year = xt_to_int32(xt_arg_at(argc, argv, 0)) - 1900;
|
|
944
959
|
tm.tm_mon = xt_to_int32(xt_arg_at(argc, argv, 1));
|
|
945
960
|
tm.tm_mday = argc > 2 ? xt_to_int32(xt_arg_at(argc, argv, 2)) : 1;
|
|
946
|
-
return xt_number((double)
|
|
961
|
+
return xt_number((double)xt_timegm(&tm) * 1000.0);
|
|
947
962
|
}
|
|
948
963
|
return XT_UNDEFINED;
|
|
949
964
|
}
|
|
@@ -953,7 +968,7 @@ static xt_value xt_date_method(xt_value target, const char *method, int32_t argc
|
|
|
953
968
|
xt_date *date = (xt_date *)XT_GET_PTR(target);
|
|
954
969
|
time_t seconds = (time_t)(date->time / 1000.0);
|
|
955
970
|
struct tm tm;
|
|
956
|
-
|
|
971
|
+
xt_gmtime_r(&seconds, &tm);
|
|
957
972
|
if (strcmp(method, "getTime") == 0 || strcmp(method, "valueOf") == 0) return xt_number(date->time);
|
|
958
973
|
const char *name = method;
|
|
959
974
|
char utc[32];
|