Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use a date library helper for interval/range checks
Use a verified interval helper or explicit comparisons preserving exact endpoint semantics.
Bad example
| 1 | const active = new Date() >= new Date(event.startTime) && new Date() < new Date(event.endTime); |
Explanation (EN)
Two separate clock reads can observe different instants, and an inappropriate helper can alter endpoint behavior.
Objašnjenje (HR)
Good example
| 1 | const now = Date.now(); |
| 2 | const start = parseValidInstant(event.startTime); |
| 3 | const end = parseValidInstant(event.endTime); |
| 4 | const active = now >= start && now < end; |
Explanation (EN)
The validated epoch values retain the original half-open interval and use one clock snapshot.
Objašnjenje (HR)
Notes (EN)
Capture now once and preserve whether the interval endpoints are inclusive or exclusive when replacing manual comparisons with a library helper.
Exceptions / Tradeoffs (EN)
Many interval helpers include both endpoints, so they do not directly replace start <= now < end. Validate input dates, ordering and timezone; reuse an existing helper only when its exact boundary contract matches.