{"record":{"id":"4b87e4d99ed1f606","repo":"oxc-project/oxc","slug":"prefer-date-now-over-kind-new-date","errorCode":null,"errorMessage":"Prefer `Date.now()` over `{kind}(new Date())`","messagePattern":"Prefer `Date\\.now\\(\\)` over `(.+?)\\(new Date\\(\\)\\)`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs","lineNumber":25,"sourceCode":"use oxc_span::{GetSpan, Span};\nuse oxc_syntax::operator::{AssignmentOperator, BinaryOperator, UnaryOperator};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn prefer_date_now(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer `Date.now()` over `new Date()`\")\n        .with_help(\"Change to `Date.now()`.\")\n        .with_label(span)\n}\n\nfn prefer_date_now_over_methods(span: Span, bad_method: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Prefer `Date.now()` over `new Date().{bad_method}()`\"))\n        .with_help(\"Change to `Date.now()`.\")\n        .with_label(span)\n}\n\nfn prefer_date_now_over_number_date_object(span: Span, kind: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Prefer `Date.now()` over `{kind}(new Date())`\"))\n        .with_help(\"Change to `Date.now()`.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferDateNow;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Prefers use of `Date.now()` over `new Date().getTime()` or `new Date().valueOf()`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Using `Date.now()` is shorter and nicer than `new Date().getTime()`, and avoids unnecessary instantiation of `Date` objects.\n    ///\n    /// ### Examples\n    ///","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs#L7-L43","documentation":"Diagnostic from the unicorn/prefer-date-now lint rule. It fires when `new Date()` is passed through a numeric operation or coercion, such as `Math.abs(new Date())`, `Math.floor(+new Date())`, or binary arithmetic on `new Date()`, to obtain the current epoch time. The result is identical to `Date.now()` but goes through object allocation and implicit coercion. It is a lint warning, not a runtime failure.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs:25 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace the numeric coercion of `new Date()` with a direct `Date.now()` call","Simplify `Math.floor(+new Date())` to `Date.now()` (epoch ms is already an integer)","Apply the rule's auto-fix where available"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}