diff options
author | daurnimator <quae@daurnimator.com> | 2018-04-22 21:18:46 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2018-04-22 21:20:45 +1000 |
commit | 421b243fb88673709386661f6fb053ecef9e56e2 (patch) | |
tree | 723871a0a95ba068bc19dfff99af422732a85dff | |
parent | cb96b5d9527975424ddb70561fce87c947f9ba08 (diff) | |
download | fengari-421b243fb88673709386661f6fb053ecef9e56e2.tar.gz fengari-421b243fb88673709386661f6fb053ecef9e56e2.tar.bz2 fengari-421b243fb88673709386661f6fb053ecef9e56e2.zip |
src/loslib.js: Calculate yday of passed in Date, not the current date
-rw-r--r-- | src/loslib.js | 3 | ||||
-rw-r--r-- | test/loslib.test.js | 1 |
2 files changed, 2 insertions, 2 deletions
diff --git a/src/loslib.js b/src/loslib.js index b58b368..89b5399 100644 --- a/src/loslib.js +++ b/src/loslib.js @@ -76,8 +76,7 @@ const setallfields = function(L, time, utc) { setfield(L, "month", (utc ? time.getUTCMonth() : time.getMonth()) + 1); setfield(L, "year", utc ? time.getUTCFullYear() : time.getFullYear()); setfield(L, "wday", (utc ? time.getUTCDay() : time.getDay()) + 1); - let now = new Date(); - setfield(L, "yday", Math.floor((now - (new Date(now.getFullYear(), 0, 0))) / (1000 * 60 * 60 * 24))); + setfield(L, "yday", Math.floor((time - (new Date(time.getFullYear(), 0, 0 /* shortcut to correct day by one */))) / 86400000)); // setboolfield(L, "isdst", time.get); }; diff --git a/test/loslib.test.js b/test/loslib.test.js index 02735cb..e2b626e 100644 --- a/test/loslib.test.js +++ b/test/loslib.test.js @@ -120,6 +120,7 @@ test('os.time normalisation of table', () => { assert(t.month == 2, "unmodified month") assert(t.year == 2018, "unmodified year") assert(t.wday == 3, "correct wday") + assert(t.yday == 51, "correct yday") `; lualib.luaL_openlibs(L); expect(lauxlib.luaL_loadstring(L, to_luastring(luaCode))).toBe(lua.LUA_OK); |