The month argument of Date methods should not be specified as 12

  • BAD_MONTH_ARG
  • Error
  • Medium
  • No tags

This rule applies when the month argument of Date methods is specified as 12.

Since the month argument is 0-based, specifying 12 results in the January of the next year. This is not likely to be a programmer's intent. If specifying the January date was actually intended, it is recommended to add 1 to the year argument and use 0 as the month to clarify the intention.

Note that the day argument is 1-based unlike the month argument.

Noncompliant Code Example

View with compliant examples side by side
let christmas = new Date(2020, 12, 25); // BAD_MONTH_ARG alarm

Compliant Code Example

View with noncompliant examples side by side
let christmas = new Date(2020, 11, 25);

Version

This rule was introduced in DeepScan 1.44.0.

See

Was this documentation helpful?