0.1.9 #10
12
package.json
12
package.json
@@ -56,15 +56,15 @@
|
|||||||
"clean:node": "rm -rf node_modules"
|
"clean:node": "rm -rf node_modules"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"remeda": "^2.6.0",
|
"remeda": "^2.11.0",
|
||||||
"type-fest": "^4.23.0"
|
"type-fest": "^4.25.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bun-types": "^1.1.21",
|
"bun-types": "^1.1.24",
|
||||||
"npm-check-updates": "^16.14.20",
|
"npm-check-updates": "^17.0.6",
|
||||||
"npm-sort": "^0.0.4",
|
"npm-sort": "^0.0.4",
|
||||||
"tsup": "^8.2.3",
|
"tsup": "^8.2.4",
|
||||||
"tsx": "^4.16.2",
|
"tsx": "^4.17.0",
|
||||||
"typescript": "^5.5.4"
|
"typescript": "^5.5.4"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
|
|||||||
52
src/Schema/DateTime.ts
Normal file
52
src/Schema/DateTime.ts
Normal file
@@ -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)
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
export * from "./Class"
|
export * from "./Class"
|
||||||
|
export * from "./DateTime"
|
||||||
export * from "./Jsonifiable"
|
export * from "./Jsonifiable"
|
||||||
export * from "./Kind"
|
export * from "./Kind"
|
||||||
export * as MobX from "./MobX"
|
export * as MobX from "./MobX"
|
||||||
|
|||||||
Reference in New Issue
Block a user