diff --git a/bun.lockb b/bun.lockb index dc82173..54b5621 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 777cd5e..f15f662 100644 --- a/package.json +++ b/package.json @@ -56,15 +56,15 @@ "clean:node": "rm -rf node_modules" }, "dependencies": { - "remeda": "^2.6.0", - "type-fest": "^4.23.0" + "remeda": "^2.11.0", + "type-fest": "^4.25.0" }, "devDependencies": { - "bun-types": "^1.1.21", - "npm-check-updates": "^16.14.20", + "bun-types": "^1.1.24", + "npm-check-updates": "^17.0.6", "npm-sort": "^0.0.4", - "tsup": "^8.2.3", - "tsx": "^4.16.2", + "tsup": "^8.2.4", + "tsx": "^4.17.0", "typescript": "^5.5.4" }, "optionalDependencies": { diff --git a/src/Schema/DateTime.ts b/src/Schema/DateTime.ts new file mode 100644 index 0000000..8964f2c --- /dev/null +++ b/src/Schema/DateTime.ts @@ -0,0 +1,52 @@ +import { ParseResult, Schema } from "@effect/schema" +import { DateTime } from "effect" + + +export const DateTimeUtcFromDate = Schema.transformOrFail( + Schema.DateFromSelf, + Schema.DateTimeUtcFromSelf, + + { + strict: true, + + decode: (date, _, ast) => ParseResult.try({ + try: () => DateTime.unsafeMake(date), + + catch: e => new ParseResult.Type( + ast, + date, + e instanceof Error ? e.message : undefined, + ), + }), + + encode: dateTimeUtc => ParseResult.succeed( + DateTime.toDateUtc(dateTimeUtc) + ), + }, +) + +export const DateTimeZonedFromDate = (options: { + readonly timeZone: number | string | DateTime.TimeZone + readonly adjustForTimeZone?: boolean | undefined +}) => Schema.transformOrFail( + Schema.DateFromSelf, + Schema.DateTimeZonedFromSelf, + + { + strict: true, + + decode: (date, _, ast) => ParseResult.try({ + try: () => DateTime.unsafeMakeZoned(date, options), + + catch: e => new ParseResult.Type( + ast, + date, + e instanceof Error ? e.message : undefined, + ), + }), + + encode: dateTime => ParseResult.succeed( + DateTime.toDate(dateTime) + ), + }, +) diff --git a/src/Schema/index.ts b/src/Schema/index.ts index e3fa60a..8e5942f 100644 --- a/src/Schema/index.ts +++ b/src/Schema/index.ts @@ -1,4 +1,5 @@ export * from "./Class" +export * from "./DateTime" export * from "./Jsonifiable" export * from "./Kind" export * as MobX from "./MobX"