"use strict"; const lua = require('./lua.js'); const lauxlib = require('./lauxlib.js'); const strftime = require('strftime'); /* options for ANSI C 89 (only 1-char options) */ const L_STRFTIMEC89 = lua.to_luastring("aAbBcdHIjmMpSUwWxXyYZ%"); const LUA_STRFTIMEOPTIONS = L_STRFTIMEC89; /* options for ISO C 99 and POSIX */ // const L_STRFTIMEC99 = lua.to_luastring("aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%||EcECExEXEyEYOdOeOHOIOmOMOSOuOUOVOwOWOy"); /* two-char options */ // const LUA_STRFTIMEOPTIONS = L_STRFTIMEC99; /* options for Windows */ // const L_STRFTIMEWIN = lua.to_luastring("aAbBcdHIjmMpSUwWxXyYzZ%||#c#x#d#H#I#j#m#M#S#U#w#W#y#Y"); /* two-char options */ // const LUA_STRFTIMEOPTIONS = L_STRFTIMEWIN; const setfield = function(L, key, value) { lua.lua_pushinteger(L, value); lua.lua_setfield(L, -2, lua.to_luastring(key, true)); }; const setallfields = function(L, time, utc) { setfield(L, "sec", !utc ? time.getSeconds() : time.getUTCSeconds()); setfield(L, "min", !utc ? time.getMinutes() : time.getUTCMinutes()); setfield(L, "hour", !utc ? time.getHours() : time.getUTCHours()); setfield(L, "day", !utc ? time.getDate() : time.getUTCDate()); setfield(L, "month", !utc ? time.getMonth() : time.getUTCMonth()); setfield(L, "year", !utc ? time.getFullYear() : time.getUTCFullYear()); setfield(L, "wday", !utc ? time.getDay() : time.getUTCDay()); let now = new Date(); setfield(L, "yday", Math.floor((now - (new Date(now.getFullYear(), 0, 0))) / (1000 * 60 * 60 * 24))); // setboolfield(L, "isdst", time.get); }; const L_MAXDATEFIELD = (Number.MAX_SAFE_INTEGER / 2); const getfield = function(L, key, d, delta) { let t = lua.lua_getfield(L, -1, lua.to_luastring(key, true)); /* get field and its type */ let res = lua.lua_tointegerx(L, -1); if (res === false) { /* field is not an integer? */ if (t !== lua.LUA_TNIL) /* some other value? */ return lauxlib.luaL_error(L, lua.to_luastring("field '%s' is not an integer"), key); else if (d < 0) /* absent field; no default? */ return lauxlib.luaL_error(L, lua.to_luastring("field '%s' missing in date table"), key); res = d; } else { if (!(-L_MAXDATEFIELD <= res && res <= L_MAXDATEFIELD)) return lauxlib.luaL_error(L, lua.to_luastring("field '%s' is out-of-bound"), key); res -= delta; } lua.lua_pop(L, 1); return res; }; const array_cmp = function(a, ai, b, bi, len) { for (let i=0; i