Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Compare dates by timestamp, not by object identity
Use timestamps for explicit instant comparisons; Date relational comparison is defined, while strict equality tests identity.
Bad example
| 1 | const sameInstant = new Date(0) === new Date(0); |
Explanation (EN)
Strict equality between separate Date instances tests identity, not whether they represent the same instant.
Objašnjenje (HR)
Good example
| 1 | if (dateA.getTime() > dateB.getTime()) { /* ... */ } |
| 2 | if (dateA.getTime() === dateB.getTime()) { /* ... */ } |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Compare valid Date timestamps explicitly when the intent is instant equality or ordering, rejecting Invalid Date as required.
Exceptions / Tradeoffs (EN)
Relational operators on ordinary valid Date objects already compare their numeric primitive values. Strict equality compares object identity. Calendar-day comparison requires a timezone/calendar contract instead.