Skip to content

(new Date()).setMonth() set invalid monthΒ #59672

@hg-pavlov

Description

@hg-pavlov

nodejs -v : v24.5.0
OS: Debian 12
When set month to 1 - date object returns 2

const tables = [ { month: 0 }, { month: 0 }, { month: 0 }, { month: 0 }, { month: 0 }, { month: 0 }, { month: 0 }, { month: 1 }, { month: 1 }, { month: 1 }, { month: 1 }, { month: 1 }, { month: 1 }, { month: 1 }, { month: 2 }, { month: 2 }, { month: 2 }, { month: 2 }, { month: 2 }, { month: 2 }, { month: 2 }, ]; tables.forEach(tbl => { console.log(tbl.month); const d = new Date(); d.setMonth(tbl.month); console.log(tbl.month,' => ',d.getMonth()); });
this code returns

0
0 => 0
0
0 => 0
0
0 => 0
0
0 => 0
0
0 => 0
0
0 => 0
0
0 => 0
1
1 => 2
1
1 => 2
1
1 => 2
1
1 => 2
1
1 => 2
1
1 => 2
1
1 => 2
2
2 => 2
2
2 => 2
2
2 => 2
2
2 => 2
2
2 => 2
2
2 => 2
2
2 => 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidIssues and PRs that are invalid.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions