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).
fullstack ruleP1universalStack: javascript
datesdate-fnscorrectness
Use a date library for date arithmetic instead of manual mutation
Compute relative dates with a helper like subDays rather than subtracting from getDate(), which is error-prone around month/year boundaries.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | const yesterday = new Date(now); |
| 2 | // breaks at month boundaries (e.g. day 1 - 1) |
| 3 | yesterday.setDate(yesterday.getDate() - 1); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | import { subDays } from 'date-fns'; |
| 2 | const yesterday = subDays(now, 1); |
Explanation (EN)
Objašnjenje (HR)