noUselessDateGetTime (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.0 - Diagnostic Category:
lint/nursery/noUselessDateGetTime - This rule has an unsafe fix.
- The default severity of this rule is warning.
- Sources:
- Same as
unicorn/consistent-date-clone
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noUselessDateGetTime": "error" } } }}Description
Section titled “Description”Disallow calling .getTime() on a date before passing it to the Date constructor.
Passing a Date object to new Date() creates a copy of it.
Calling .getTime() on the date first does the same thing with extra code.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”const copy = new Date(date.getTime());code-block.js:1:28 lint/nursery/noUselessDateGetTime FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This .getTime() call is unnecessary.
> 1 │ const copy = new Date(date.getTime());
│ ^^^^^^^^^
2 │
ℹ Passing a date directly to new Date() already creates a copy of it.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Remove the .getTime() call.
1 │ - const·copy·=·new·Date(date.getTime());
1 │ + const·copy·=·new·Date(date);
2 2 │
const copy = new Date(date);const timestamp = date.getTime();Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.