-
-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
DateTimeUtcFromDate
schema (#3956)
Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"effect": minor | ||
--- | ||
|
||
add DateTimeUtcFromDate schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/effect/test/Schema/Schema/DateTime/DateTimeUtcFromDate.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as DateTime from "effect/DateTime" | ||
import * as S from "effect/Schema" | ||
import * as Util from "effect/test/Schema/TestUtils" | ||
import { describe, expect, it } from "vitest" | ||
|
||
describe("DateTimeUtcFromDate", () => { | ||
it("decoding", async () => { | ||
await Util.expectDecodeUnknownSuccess(S.DateTimeUtcFromDate, new Date(0), DateTime.unsafeMake(0)) | ||
await Util.expectDecodeUnknownSuccess( | ||
S.DateTimeUtcFromDate, | ||
new Date("2024-12-06T00:00:00Z"), | ||
DateTime.unsafeMake({ day: 6, month: 12, year: 2024, hour: 0, minute: 0, second: 0, millisecond: 0 }) | ||
) | ||
|
||
await Util.expectDecodeUnknownFailure( | ||
S.DateTimeUtcFromDate, | ||
null, | ||
`DateTimeUtcFromDate | ||
└─ Encoded side transformation failure | ||
└─ Expected DateFromSelf, actual null` | ||
) | ||
await Util.expectDecodeUnknownFailure( | ||
S.DateTimeUtcFromDate, | ||
new Date(NaN), | ||
`DateTimeUtcFromDate | ||
└─ Transformation process failure | ||
└─ Expected DateTimeUtcFromDate, actual Invalid Date` | ||
) | ||
}) | ||
|
||
it("encoding", async () => { | ||
await Util.expectEncodeSuccess(S.DateTimeUtcFromDate, DateTime.unsafeMake(0), new Date(0)) | ||
expect( | ||
S.encodeSync(S.DateTimeUtcFromDate)( | ||
DateTime.unsafeMake({ day: 6, month: 12, year: 2024, hour: 0, minute: 0, second: 0, millisecond: 0 }) | ||
) | ||
).toStrictEqual(new Date("2024-12-06T00:00:00Z")) | ||
}) | ||
}) |