Skip to content

Types of js_sys::Date functions seem wrong #3585

Open
@flumm

Description

@flumm

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 accept i32, 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 even i64/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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking-changeTracking breaking changes for the next major version bump (if ever)bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions