-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Types of js_sys::Date functions seem wrong #3585
Comments
Yeah, that's a bug. |
makes sense. when do you do breaking changes? should i write a pull request? if yes, which types would be preferable? |
There is currently no timeline for a breaking change. Unfortunately
No, but I will keep it in mind and ping you when we get there.
I think |
that does not sound good, what's the reason? is there a way i can help?
i think for all (realistic) scenarios this should be enough, though there might be a case for f64 since that is more or less what you can give in js ? (though i doubt setting one of the fields to more than 2^31 is necessary or sensible?) |
There is no specific reason, I guess nobody is getting paid to do it and there is nobody currently available with enough spare time to take it on either. It's the nature of open source! We are always happy to welcome new contributors, so if you want to help there is always stuff to do. Resolving issues, reviewing PRs and making PRs. You can find us on Discord if you want some pointers on where to start or to just discuss things with us in real time.
Ideally I think we need a more neutral API that only does what bindings are supposed to do and nothing else. E.g. we could just use |
For completeness, there's other issues with the Date API as well. For example, the arguments to |
Summary
Types of js_sys::Date functions seem wrong
Additional Details
When i have a Date object in the browser (or nodejs). E.g., i can do
let foo = new Date(); foo.setMonth(-1);
to set the date to the last month of the previous year which is super handy when doing calculations on dates (This works for all fields). With this crate this does not work, since most of the functions only take 'u32' as parameter. MDN does not really specify the exact type, but it says 'integer' so unsigned values seem wrong. ECMAScript standard just says it has to be convertable to the number type:
https://262.ecma-international.org/14.0/#sec-date.prototype.setmonth
https://262.ecma-international.org/14.0/#sec-tonumber
Curiously, the function
set_full_year_with_month
(and similar ones) do accepti32
, but for the month part only.(This also applies for the
new_with_year_month_..
etc functions, but only for month,day,etc. never for the year)I'd propose that all the functions should take a signed integer (at least
i32
, probably eveni64
/f64
?) so that one can use that functionality described above, or is there any reason why it is implemented in this way? If there is a reason, this should at least be documented properly in the crate.The text was updated successfully, but these errors were encountered: