Validate DateTime object instants before construction - #6942
Conversation
|
There was a problem hiding this comment.
ℹ️ Minor suggestions only — the regression test is focused and correct, but it should also cover
DateTime.makeUnsafeso the implementation fix cannot miss that path.
Reviewed changes
Reviewed the initial failing regression test added to packages/effect/test/DateTimeInstantValidation.test.ts; the implementation fix described in the PR is not present yet on the reviewed commit.
- Adds a focused regression test that
DateTime.make({ epochMilliseconds: NaN })andDateTime.make({ epochMilliseconds: 8_640_000_000_000_001 })both returnNone. - The assertion values match JavaScript
Datevalidation behavior (new Date(8640000000000001).getTime()isNaN), confirming the object-instant branch is the one missing validation.
@v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏
| import { DateTime, Option } from "effect" | ||
|
|
||
| describe("DateTime instant validation", () => { | ||
| it("rejects invalid object instants", () => { |
There was a problem hiding this comment.
The PR description also says makeUnsafe can construct unusable values. Consider adding assertions for DateTime.makeUnsafe({ epochMilliseconds: NaN }) and DateTime.makeUnsafe({ epochMilliseconds: 8_640_000_000_000_001 }) throwing, so the implementation fix covers both APIs.

Summary
DateTime.make returns Some for NaN and out-of-range object instants, and makeUnsafe can construct unusable values.
Important
This PR starts with focused failing reproduction tests. Add the implementation fix to this same branch; CI is expected to fail until that fix is included.
Object instants bypass validity and range checks
Module:
DateTimeAudit ID:
core-a-f-datetime-object-instant-validationSeverity / confidence: medium / high
What happens
DateTime.make returns Some for NaN and out-of-range object instants, and makeUnsafe can construct unusable values.
Why it happens
The object-instant branch calls makeUtc(input.epochMilliseconds) directly, unlike number and Date inputs that pass through JavaScript Date validation.
Expected behavior
{ epochMilliseconds: number } is supported, DateTime.make returns None when construction would produce an invalid date-time, and makeUnsafe rejects construction failures.
Relevant implementation
These links and excerpts are pinned to audit base
c9b56ab507f224426ee8388dc450da447ec4715f.packages/effect/src/internal/dateTime.ts:217-225packages/effect/src/internal/dateTime.ts:296-297packages/effect/src/DateTime.ts:224-233packages/effect/src/DateTime.ts:742-755View problematic code at
packages/effect/src/internal/dateTime.ts:217-225View exact lines on GitHub
View problematic code at
packages/effect/src/internal/dateTime.ts:296-297View exact lines on GitHub
View problematic code at
packages/effect/src/DateTime.ts:224-233View exact lines on GitHub
View problematic code at
packages/effect/src/DateTime.ts:742-755View exact lines on GitHub
Reproduction
pnpm test --run packages/effect/test/DateTimeInstantValidation.test.tsObserved failure: A direct Node 24 source probe returned Some for both NaN and out-of-range object instants.
Implementation handoff
The initial reproduction tests on this branch are the regression specification for the implementation fix that should follow in this PR.
pnpm test --run packages/effect/test/DateTimeInstantValidation.test.tsAudit provenance
c9b56ab507f224426ee8388dc450da447ec4715fc9b56ab507f224426ee8388dc450da447ec4715fcore-a-f-datetime-object-instant-validation