Bug in os.time?
Hi, I am using fengari to create a client side framework, but I have noticed os.time fails with some valid dates.
os.time({year=2065, month=8, day=1}) gives TypeError: invalid argument
Any date with a year above 2030 fails. Is this a bug? I tried this in standard lua and it doesn't fail.
By the way, great job, I love fengari
os.time({year=2065, month=8, day=1}) gives TypeError: invalid argument
I'm able to confirm/replicate.
Checking arguments to Date they are fine.
debugged with:
a=Date
Date = function() { console.log(arguments) }
which shows:
Arguments { 0: 2065, 1: 7, 2: 1, 3: 12, 4: 0, 5: 0, … }
0: 2065
1: 7
2: 1
3: 12
4: 0
5: 0
callee: function Date()
length: 6
Symbol(Symbol.iterator): function values()
<prototype>: Object { … }
debugger eval code:1:29
And verified that new a(2065,7,1,12,0,0) works fine.
So the issue is likely in https://github.com/fengari-lua/fengari/blob/eb2453c0c36f3802c8effeb65f36090de0c59a0e/src/loslib.js#L438
(new a(2065,7,1,12,0,0))/1000 returns the number 3016317600 as expected.
So the error must come from lua_pushinteger. Which makes sense: fengari only supports (signed) 32bit integers (https://github.com/fengari-lua/fengari#integers) and this timestamp is out of range.
I'm not sure what the fix should be.
If we use lua_pushnumber instead then we have a small incompatibility with standard lua which fengari strives to not have
I understand, but right now we have fengari with a top limit date and it is not so far in the future. Any app using dates will have problems pass 2030 or something like that
Would it be easy to modify your application to use Date directly via fengari-interop?
Thanks a lot, I will use that