Created
January 13, 2022 17:39
-
-
Save Eosis/979b9003f67452b7ac020621b43cebcc to your computer and use it in GitHub Desktop.
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
// Client LuxonTimestampCodec: | |
import * as T from 'io-ts' | |
import { DateTime } from 'luxon' | |
import { Timestamp } from 'firebase/firestore' | |
const LuxonDateTimeT = new T.Type<DateTime, Timestamp, unknown>( | |
'LuxonDateTimeT', | |
(u: unknown): u is DateTime => u instanceof DateTime, | |
(u: unknown, c: T.Context) => { | |
if (!(u instanceof Timestamp)) { | |
return T.failure(u, c) | |
} | |
return T.success(DateTime.fromJSDate(u.toDate()).setZone('UTC')) | |
}, | |
(a: DateTime) => Timestamp.fromDate(a.toJSDate()), | |
) | |
const JustStartTimeT = T.type({ | |
startTime: LuxonDateTimeT, | |
}) | |
export default JustStartTimeT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment