{"record":{"id":"9d0881af76baaba1","repo":"oxc-project/oxc","slug":"unnecessary-gettime-call","errorCode":null,"errorMessage":"Unnecessary `.getTime()` call","messagePattern":"Unnecessary `\\.getTime\\(\\)` call","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/consistent_date_clone.rs","lineNumber":9,"sourceCode":"use crate::{AstNode, context::LintContext, rule::Rule};\nuse oxc_ast::AstKind;\nuse oxc_ast::ast::{Argument, Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nfn consistent_date_clone_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unnecessary `.getTime()` call\")\n        .with_help(\"Prefer passing `Date` directly to the constructor when cloning\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct ConsistentDateClone;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// The Date constructor can clone a `Date` object directly when passed as an argument,\n    /// making timestamp conversion unnecessary. This rule enforces the use of the\n    /// direct `Date` cloning instead of using `.getTime()` for conversion.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Using `.getTime()` to convert a `Date` object to a timestamp and then back to a\n    /// `Date` is redundant and unnecessary. Simply passing the `Date` object to the","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/consistent_date_clone.rs#L1-L27","documentation":"Diagnostic from oxlint's `unicorn/consistent-date-clone` rule. The `Date` constructor clones a `Date` directly when passed as the argument, so converting to epoch millis with `.getTime()` and back is redundant; the rule flags that pattern. Detection is narrow: a `new Date(...)` with exactly one argument, no type arguments, whose argument is a zero-argument, non-optional-chained `.getTime()` call — an autofix deletes the `.getTime()` suffix.","triggerScenarios":"`const copy = new Date(original.getTime());` or `new Date(this.startsAt.getTime())` — any `new Date(x.getTime())` where the call is a plain member call with no arguments and no optional chaining.","commonSituations":"Date cloning in schedulers/calendars and immutable state updates; code written to avoid the deprecated `new Date(dateString)` pitfall by over-generalizing to timestamps; enabling the unicorn preset in an older codebase.","solutions":["Pass the Date directly: `const copy = new Date(original);`.","Run `oxlint --fix` to strip the redundant `.getTime()` calls automatically.","Reserve `.getTime()` for arithmetic on epoch milliseconds, not for cloning."],"exampleFix":"// before\nconst copy = new Date(original.getTime());\n// after\nconst copy = new Date(original);","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clone Dates with `new Date(existingDate)`; reserve `.getTime()` for epoch-millisecond arithmetic.","During review, flag any `new Date(...)` whose single argument ends in `.getTime()`.","Let `oxlint --fix` strip redundant `.getTime()` calls in one pass when enabling the unicorn preset."],"tags":["oxlint","lint","unicorn","date","refactor"],"backgroundTag":"redundant-date-conversion","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}