Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in os.time? #203

Open
EzequielHiran opened this issue Jun 16, 2022 · 4 comments
Open

Bug in os.time? #203

EzequielHiran opened this issue Jun 16, 2022 · 4 comments

Comments

@EzequielHiran
Copy link

EzequielHiran commented Jun 16, 2022

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

@daurnimator
Copy link
Member

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

lua_pushinteger(L, Math.floor(t / 1000));

(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

@EzequielHiran
Copy link
Author

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

@daurnimator
Copy link
Member

Would it be easy to modify your application to use Date directly via fengari-interop?

@EzequielHiran
Copy link
Author

Thanks a lot, I will use that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants