Skip to content

Latest commit

 

History

History
24 lines (15 loc) · 935 Bytes

File metadata and controls

24 lines (15 loc) · 935 Bytes

consistent-date-clone

📝 Prefer passing Date directly to the constructor when cloning.

💼 This rule is enabled in the following configs: ✅ recommended, ☑️ unopinionated.

🔧 This rule is automatically fixable by the --fix CLI option.

The Date constructor can clone a ⁠Date object directly when passed as an argument, making timestamp conversion unnecessary.

Note: Before ES2015, new Date(date) converted date to a string first, so it's not safe to clone.

Examples

// ❌
new Date(date.getTime());

// ✅
new Date(date);