Last active
January 13, 2022 17:58
-
-
Save Eosis/35fae49813e21fd46c64de94ad936fc4 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
// Backend TimestampCodec | |
import * as T from 'io-ts' | |
import { DateTime } from 'luxon' | |
import * as admin from 'firebase-admin' | |
export const LuxonDateTimeT = new T.Type<DateTime, admin.firestore.Timestamp, unknown>( | |
'LuxonDateTimeT', | |
(u: unknown): u is DateTime => u instanceof DateTime, | |
(u: unknown, c: T.Context) => { | |
if (!(u instanceof admin.firestore.Timestamp)) { | |
return T.failure(u, c) | |
} | |
return T.success(DateTime.fromJSDate(u.toDate())) | |
}, | |
(a: DateTime) => admin.firestore.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