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).
frontend ruleP2universalStack: javascript
datesreadabilitydate-fnsclean-code
Use a date library helper for interval/range checks
Express 'is now within [start, end]' with a date-library helper (e.g. isWithinInterval) instead of chaining manual new Date() comparisons.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codejavascript
| 1 | const active = new Date() >= new Date(event.startTime) && new Date() < new Date(event.endTime); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | import { isWithinInterval } from 'date-fns'; |
| 2 | const active = isWithinInterval(new Date(), { start: event.startTime, end: event.endTime }); |
Explanation (EN)
Objašnjenje (HR)