Files
SMANAGE/TempLate/MSOC/Python/Lib/ScriptLib/time.js
T
2026-06-16 11:55:14 +08:00

152 lines
7.1 KiB
JavaScript

var $builtinmodule = function() {
function check_struct_time(a) {
if (!(a instanceof b)) throw new Sk.builtin.TypeError("Required argument 'struct_time' must be of type: 'struct_time'");
var c, d = a.v.length,
e = a.v;
for (c = 0; c < d; ++c)
if (!Sk.builtin.checkInt(e[c])) throw new Sk.builtin.TypeError("struct_time may only contain integers");
return !0
}
function padLeft(a, b, d) {
var c = a.toString();
return Array(b - c.length + 1)
.join(d || " ") + c
}
function isLeapYear(a) {
return 0 == (3 & a) && (0 != a % 100 || 0 == a % 400)
}
function getDayOfYear(a, b) {
b = b || !1;
var c = b ? a.getUTCMonth() : a.getMonth(),
d = b ? a.getUTCDate() : a.getDate(),
e = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334][c] + d;
return 1 < c && isLeapYear(b ? a.getUTCFullYear() : a.getFullYear()) && e++, e
}
function stdTimezoneOffset() {
var a = Math.max,
b = new Date(2002, 0, 1),
c = new Date(2002, 6, 1);
return a(b.getTimezoneOffset(), c.getTimezoneOffset())
}
function dst(a) {
return a.getTimezoneOffset() < stdTimezoneOffset()
}
function timeZoneName(a) {
var b, c = /\\((.*)\\)/.exec(a.toString());
if (null != this.navigator && (b = this.navigator.userLanguage || this.navigator.language), c && 1 < c.length) return c[1];
if (void 0 === b) return null;
try {
var d = a.toLocaleString(b, {
timeZoneName: "short"
});
return c = d.split(" "), c[c.length - 1]
} catch (a) {
return null
}
}
function date_to_struct_time(a, c) {
return c = c || !1, new b([Sk.builtin.assk$(c ? a.getUTCFullYear() : a.getFullYear()), Sk.builtin.assk$((c ? a.getUTCMonth() : a.getMonth()) + 1), Sk.builtin.assk$(c ? a.getUTCDate() : a.getDate()), Sk.builtin.assk$(c ? a.getUTCHours() : a.getHours()), Sk.builtin.assk$(c ? a.getUTCMinutes() : a.getMinutes()), Sk.builtin.assk$(c ? a.getUTCSeconds() : a.getSeconds()), Sk.builtin.assk$(((c ? a.getUTCDay() : a.getDay()) + 6) % 7), Sk.builtin.assk$(getDayOfYear(a, c)), Sk.builtin.assk$(c ? 0 : dst(a) ? 1 : 0)])
}
function localtime_f(a) {
Sk.builtin.pyCheckArgsLen("localtime", arguments.length, 0, 1);
var b = new Date;
if (a) {
Sk.builtin.pyCheckType("secs", "number", Sk.builtin.checkNumber(a));
var c = Sk.builtin.asnum$(a);
b.setTime(1e3 * c)
}
return date_to_struct_time(b)
}
function asctime_f(a) {
if (!a || Sk.builtin.checkNone(a) ? a = localtime_f() : !(a instanceof b) && (a = new b(a)), a instanceof Sk.builtin.tuple && 9 == a.v.length) {
var e = [d[Sk.builtin.asnum$(a.v[6])], c[Sk.builtin.asnum$(a.v[1]) - 1], padLeft(Sk.builtin.asnum$(a.v[2])
.toString(), 2, "0"), padLeft(Sk.builtin.asnum$(a.v[3])
.toString(), 2, "0") + ":" + padLeft(Sk.builtin.asnum$(a.v[4])
.toString(), 2, "0") + ":" + padLeft(Sk.builtin.asnum$(a.v[5])
.toString(), 2, "0"), padLeft(Sk.builtin.asnum$(a.v[0])
.toString(), 4, "0")];
return new Sk.builtin.str(e.join(" "))
}
}
function mktime_f(a) {
if (a instanceof Sk.builtin.tuple && 9 == a.v.length) {
var b = new Date(Sk.builtin.asnum$(a.v[0]), Sk.builtin.asnum$(a.v[1]) - 1, Sk.builtin.asnum$(a.v[2]), Sk.builtin.asnum$(a.v[3]), Sk.builtin.asnum$(a.v[4]), Sk.builtin.asnum$(a.v[5]));
return Sk.builtin.assk$(b.getTime() / 1e3, void 0)
}
throw new Sk.builtin.TypeError("mktime() requires a struct_time or 9-tuple")
}
var a = {
__file__: "/src/lib/time/__init__.js",
__package__: new Sk.builtin.str("")
},
b = Sk.builtin.make_structseq("time", "struct_time", {
tm_year: "year, for example, 1993",
tm_mon: "month of year, range [1, 12]",
tm_mday: "day of month, range [1, 31]",
tm_hour: "hours, range [0, 23]",
tm_min: "minutes, range [0, 59]",
tm_sec: "seconds, range [0, 61]",
tm_wday: "day of week, range [0, 6], Monday is 0",
tm_yday: "day of year, range [1, 366]",
tm_isdst: "1 if summer time is in effect, 0 if not, and -1 if unknown"
});
a.struct_time = b, a.time = new Sk.builtin.func(function() {
Sk.builtin.pyCheckArgsLen("time", arguments.length, 0, 0);
var a = Date.now();
return this.performance && this.performance.now && (a += performance.now() % 1), Sk.builtin.assk$(a / 1e3, void 0)
}), a.sleep = new Sk.builtin.func(function(a) {
return Sk.builtin.pyCheckArgsLen("sleep", arguments.length, 1, 1), Sk.builtin.pyCheckType("delay", "float", Sk.builtin.checkNumber(a)), new Sk.misceval.promiseToSuspension(new Promise(function(b) {
Sk.setTimeout(function() {
b(Sk.builtin.none.none$)
}, 1e3 * Sk.ffi.remapToJs(a))
}))
}), a.localtime = new Sk.builtin.func(localtime_f), a.gmtime = new Sk.builtin.func(function(a) {
Sk.builtin.pyCheckArgsLen("localtime", arguments.length, 0, 1);
var b = new Date;
if (a) {
Sk.builtin.pyCheckType("secs", "number", Sk.builtin.checkNumber(a));
var c = Sk.builtin.asnum$(a);
b.setTime(1e3 * c)
}
return date_to_struct_time(b, !0)
});
var c = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
d = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
return a.asctime = new Sk.builtin.func(asctime_f), a.ctime = new Sk.builtin.func(function(a) {
return asctime_f(localtime_f(a))
}), a.mktime = new Sk.builtin.func(mktime_f), a.timezone = new Sk.builtin.int_(60 * stdTimezoneOffset()), a.altzone = new Sk.builtin.int_(60 * function altTimezoneOffset() {
var a = Math.min,
b = new Date(2002, 0, 1),
c = new Date(2002, 6, 1);
return a(b.getTimezoneOffset(), c.getTimezoneOffset())
}()), a.daylight = new Sk.builtin.int_(dst(new Date) ? 1 : 0), a.tzname = new Sk.builtin.tuple(function timeZoneNames() {
var a = new Date(2002, 0, 1),
b = new Date(2002, 6, 1);
return dst(a) ? [new Sk.builtin.str(timeZoneName(b)), new Sk.builtin.str(timeZoneName(a))] : [new Sk.builtin.str(timeZoneName(a)), new Sk.builtin.str(timeZoneName(b))]
}()), a.accept2dyear = Sk.builtin.assk$(1), a.clock = new Sk.builtin.func(function() {
var a = 0;
return a = this.performance && this.performance.now ? performance.now() / 1e3 : new Date()
.getTime() / 1e3, new Sk.builtin.float_(a)
}), a.strftime = new Sk.builtin.func(function strftime_f(a, c) {
var d;
if (Sk.builtin.pyCheckArgsLen("strftime", arguments.length, 1, 2), !Sk.builtin.checkString(a)) throw new Sk.builtin.TypeError("format must be a string");
return c ? !(c instanceof b) && (c = new b(c)) : c = localtime_f(), check_struct_time(c), d = Sk.ffi.remapToJs(a), Sk.ffi.remapToPy(strftime(d, new Date(1e3 * mktime_f(c)
.v)))
}), a.tzset = new Sk.builtin.func(function tzset_f() {
throw new Sk.builtin.NotImplementedError("time.tzset() is not yet implemented")
}), a.strptime = new Sk.builtin.func(function strptime_f(a, b) {
Sk.builtin.pyCheckArgsLen("strptime", arguments.length, 1, 2), Sk.builtin.pyCheckType("string", "string", Sk.builtin.checkString(a)), void 0 === b ? b = new Sk.builtin.str("%a %b %d %H:%M:%S %Y") : Sk.builtin.pyCheckType("format", "string", Sk.builtin.checkString(b));
let c = date_to_struct_time(strptime(Sk.ffi.remapToJs(a), Sk.ffi.remapToJs(b), !0));
return c.v[8] = new Sk.builtin.int_(-1), c
}), a
};