{"record":{"id":"a3534f3b2e511ea7","repo":"oxc-project/oxc","slug":"prefer-date-now-over-new-date","errorCode":null,"errorMessage":"Prefer `Date.now()` over `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":13,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse 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;","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs#L1-L31","documentation":"Raised by unicorn/prefer-date-now when `new Date()` is used to obtain the current timestamp. Allocating a Date just for milliseconds is wasteful; the faulting input is the `new Date()` expression at the labeled span, and the fix rewrites it to `Date.now()`.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_date_now.rs:13 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use `Date.now()` which returns the epoch milliseconds directly","If you need a Date object, keep `new Date()` but derive the timestamp via `date.getTime()`"],"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"}