Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: javascript
datescomparisoncorrectness
Compare dates by timestamp, not by object identity
Use getTime() (or valueOf) when comparing Date instances; comparing Date objects directly with relational operators is unreliable/misleading.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codejavascript
| 1 | if (dateA > dateB) { /* relies on coercion, fragile */ } |
| 2 | if (dateA === dateB) { /* always false for distinct objects */ } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | if (dateA.getTime() > dateB.getTime()) { /* ... */ } |
| 2 | if (dateA.getTime() === dateB.getTime()) { /* ... */ } |
Explanation (EN)
Objašnjenje (HR)