-
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
285 additions
and
3 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/schema": patch | ||
--- | ||
|
||
add Date filters (less than, greater than, between), closes #3606 |
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
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
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,37 @@ | ||
import * as S from "@effect/schema/Schema" | ||
import * as Util from "@effect/schema/test/TestUtils" | ||
import { describe, it } from "vitest" | ||
|
||
describe("betweenDate", () => { | ||
const schema = S.DateFromSelf.pipe(S.betweenDate(new Date(-1), new Date(1))) | ||
|
||
it("decoding", async () => { | ||
await Util.expectDecodeUnknownSuccess( | ||
schema, | ||
new Date(-1) | ||
) | ||
await Util.expectDecodeUnknownSuccess( | ||
schema, | ||
new Date(0) | ||
) | ||
await Util.expectDecodeUnknownSuccess( | ||
schema, | ||
new Date(1) | ||
) | ||
|
||
await Util.expectDecodeUnknownFailure( | ||
schema, | ||
new Date(-2), | ||
`a date between 1969-12-31T23:59:59.999Z and 1970-01-01T00:00:00.001Z | ||
└─ Predicate refinement failure | ||
└─ Expected a date between 1969-12-31T23:59:59.999Z and 1970-01-01T00:00:00.001Z, actual 1969-12-31T23:59:59.998Z` | ||
) | ||
await Util.expectDecodeUnknownFailure( | ||
schema, | ||
new Date(2), | ||
`a date between 1969-12-31T23:59:59.999Z and 1970-01-01T00:00:00.001Z | ||
└─ Predicate refinement failure | ||
└─ Expected a date between 1969-12-31T23:59:59.999Z and 1970-01-01T00:00:00.001Z, actual 1970-01-01T00:00:00.002Z` | ||
) | ||
}) | ||
}) |
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,29 @@ | ||
import * as S from "@effect/schema/Schema" | ||
import * as Util from "@effect/schema/test/TestUtils" | ||
import { describe, it } from "vitest" | ||
|
||
describe("greaterThanDate", () => { | ||
const schema = S.DateFromSelf.pipe(S.greaterThanDate(new Date(0))) | ||
|
||
it("decoding", async () => { | ||
await Util.expectDecodeUnknownSuccess( | ||
schema, | ||
new Date(1) | ||
) | ||
|
||
await Util.expectDecodeUnknownFailure( | ||
schema, | ||
new Date(0), | ||
`a date after 1970-01-01T00:00:00.000Z | ||
└─ Predicate refinement failure | ||
└─ Expected a date after 1970-01-01T00:00:00.000Z, actual 1970-01-01T00:00:00.000Z` | ||
) | ||
await Util.expectDecodeUnknownFailure( | ||
schema, | ||
new Date(-1), | ||
`a date after 1970-01-01T00:00:00.000Z | ||
└─ Predicate refinement failure | ||
└─ Expected a date after 1970-01-01T00:00:00.000Z, actual 1969-12-31T23:59:59.999Z` | ||
) | ||
}) | ||
}) |
26 changes: 26 additions & 0 deletions
26
packages/schema/test/Schema/Date/greaterThanOrEqualToDate.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,26 @@ | ||
import * as S from "@effect/schema/Schema" | ||
import * as Util from "@effect/schema/test/TestUtils" | ||
import { describe, it } from "vitest" | ||
|
||
describe("greaterThanOrEqualToDate", () => { | ||
const schema = S.DateFromSelf.pipe(S.greaterThanOrEqualToDate(new Date(0))) | ||
|
||
it("decoding", async () => { | ||
await Util.expectDecodeUnknownSuccess( | ||
schema, | ||
new Date(1) | ||
) | ||
await Util.expectDecodeUnknownSuccess( | ||
schema, | ||
new Date(0) | ||
) | ||
|
||
await Util.expectDecodeUnknownFailure( | ||
schema, | ||
new Date(-1), | ||
`a date after or equal to 1970-01-01T00:00:00.000Z | ||
└─ Predicate refinement failure | ||
└─ Expected a date after or equal to 1970-01-01T00:00:00.000Z, actual 1969-12-31T23:59:59.999Z` | ||
) | ||
}) | ||
}) |
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,29 @@ | ||
import * as S from "@effect/schema/Schema" | ||
import * as Util from "@effect/schema/test/TestUtils" | ||
import { describe, it } from "vitest" | ||
|
||
describe("lessThanDate", () => { | ||
const schema = S.DateFromSelf.pipe(S.lessThanDate(new Date(0))) | ||
|
||
it("decoding", async () => { | ||
await Util.expectDecodeUnknownSuccess( | ||
schema, | ||
new Date(-1) | ||
) | ||
|
||
await Util.expectDecodeUnknownFailure( | ||
schema, | ||
new Date(0), | ||
`a date before 1970-01-01T00:00:00.000Z | ||
└─ Predicate refinement failure | ||
└─ Expected a date before 1970-01-01T00:00:00.000Z, actual 1970-01-01T00:00:00.000Z` | ||
) | ||
await Util.expectDecodeUnknownFailure( | ||
schema, | ||
new Date(1), | ||
`a date before 1970-01-01T00:00:00.000Z | ||
└─ Predicate refinement failure | ||
└─ Expected a date before 1970-01-01T00:00:00.000Z, actual 1970-01-01T00:00:00.001Z` | ||
) | ||
}) | ||
}) |
26 changes: 26 additions & 0 deletions
26
packages/schema/test/Schema/Date/lessThanOrEqualToDate.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,26 @@ | ||
import * as S from "@effect/schema/Schema" | ||
import * as Util from "@effect/schema/test/TestUtils" | ||
import { describe, it } from "vitest" | ||
|
||
describe("lessThanOrEqualToDate", () => { | ||
const schema = S.DateFromSelf.pipe(S.lessThanOrEqualToDate(new Date(0))) | ||
|
||
it("decoding", async () => { | ||
await Util.expectDecodeUnknownSuccess( | ||
schema, | ||
new Date(-1) | ||
) | ||
await Util.expectDecodeUnknownSuccess( | ||
schema, | ||
new Date(0) | ||
) | ||
|
||
await Util.expectDecodeUnknownFailure( | ||
schema, | ||
new Date(1), | ||
`a date before or equal to 1970-01-01T00:00:00.000Z | ||
└─ Predicate refinement failure | ||
└─ Expected a date before or equal to 1970-01-01T00:00:00.000Z, actual 1970-01-01T00:00:00.001Z` | ||
) | ||
}) | ||
}) |
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