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 consistent date types across DTOs and tests
Keep date types consistent within each contract and explicitly map domain dates to wire strings.
Bad example
| 1 | createdAt: new Date(), // here a Date |
| 2 | createdAt: '2022-01-01', // elsewhere a string |
Explanation (EN)
Interchanging a Date and an unspecified string inside one contract can hide timezone and serialization mistakes.
Objašnjenje (HR)
Good example
| 1 | const instant = new Date("2022-01-01T00:00:00.000Z"); |
| 2 | const dto = { createdAt: instant.toISOString() }; |
Explanation (EN)
The domain uses Date while the JSON DTO uses a deterministic UTC string; tests should assert the appropriate layer.
Objašnjenje (HR)
Notes (EN)
Represent each layer's date contract consistently and convert explicitly across serialization boundaries, using deterministic fixtures with a stated timezone.
Exceptions / Tradeoffs (EN)
A domain Date and wire ISO string can correctly represent the same instant in different layers. Do not force Date into JSON or convert a calendar date into an instant without a domain decision.