Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Abstract date parsing logic into utilities
Avoid manually parsing date strings with `new Date()` or `split()` due to timezone ambiguity and fragility. Use centralized utilities instead.
Bad example
| 1 | function IssueDate({ dateString }: { dateString: string }) { |
| 2 | // Bad: '2023-10-10' is parsed as UTC midnight, which may display as |
| 3 | // the previous day in western timezones (e.g., Oct 9th). |
| 4 | const date = new Date(dateString); |
| 5 |
|
| 6 | // Bad: Manual splitting is verbose and breaks if the format changes. |
| 7 | const [year, month, day] = dateString.split('-'); |
| 8 |
|
| 9 | return <span>{date.toLocaleDateString()}</span>; |
| 10 | } |
Explanation (EN)
Parsing a date-only string as an instant can shift its displayed calendar day.
Objašnjenje (HR)
Tumačenje kalendarskog datuma kao vremenskog trenutka može pomaknuti prikazani dan.
Good example
| 1 | const label = formatCalendarDate(dateString, { format: 'dd.MM.yyyy' }); |
Explanation (EN)
The existing calendar-date helper validates the date-only contract without converting it through an unintended timezone.
Objašnjenje (HR)
Postojeća funkcija za kalendarske datume provjerava taj ugovor bez pretvorbe kroz nenamjernu vremensku zonu.
Notes (EN)
At a date boundary, distinguish calendar dates from instants, validate the accepted format and explicitly select the intended timezone before formatting. Reuse the existing date utility.
Bilješke (HR)
Na ulazu razlikuj kalendarski datum od trenutka u vremenu, validiraj format i izričito odredi vremensku zonu prije formatiranja. Koristi postojeću pomoćnu funkciju za datume.
Exceptions / Tradeoffs (EN)
Native Date is suitable for validated instant formats; a library wrapper alone does not resolve ambiguous timezone semantics. Do not add a dependency solely for a simple proven conversion.