close

consistent-date-clone

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/consistent-date-clone': 'error',
    },
  },
]);

Rule Details

Prefer passing an existing Date directly to the Date constructor when cloning it. Since ECMAScript 2015, new Date(date) copies the original date's time value without requiring an intermediate number.

Examples of incorrect code for this rule:

const copy = new Date(date.getTime());

Examples of correct code for this rule:

const copy = new Date(date);

The rule only reports the direct new Date(date.getTime()) shape. Calls with additional constructor arguments or component-wise date construction are left unchanged:

new Date(date.getTime(), extraArgument);

new Date(
  date.getFullYear(),
  date.getMonth(),
  date.getDate(),
  date.getHours(),
  date.getMinutes(),
  date.getSeconds(),
);

Original Documentation