Unfortunately this fails due to the type being too difficult for typescript to represent (which makes sense), but this was still a fun type.
Created
February 9, 2023 18:54
-
-
Save slinkardbrandon/81270f7001c251dbd282f04d19cce313 to your computer and use it in GitHub Desktop.
Typescript ISO Date Type
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
type OneThroughSix = 1 | 2 | 3 | 4 | 5 | 6; | |
type OneThroughNine = OneThroughSix | 7 | 8 | 9; | |
type ZeroThroughNine = 0 | OneThroughNine; | |
type ISOYear = `19${ZeroThroughNine}${ZeroThroughNine}` | `20${ZeroThroughNine}${ZeroThroughNine}`; | |
type ISOMonth = `0${OneThroughNine}` | `10` | `11` | `12`; | |
type ISODay = `0${ZeroThroughNine}` | `1${ZeroThroughNine}` | `2${ZeroThroughNine}` | `30` | `31`; | |
type ISOHours = `0${OneThroughNine}` | `1${OneThroughNine}` | `20` | `21` | `22` | `23` | `24`; | |
type ISOSecondsAndMinutes = | |
| `0${ZeroThroughNine}` | |
| `1${ZeroThroughNine}` | |
| `2${ZeroThroughNine}` | |
| `3${ZeroThroughNine}` | |
| `4${ZeroThroughNine}` | |
| `5${ZeroThroughNine}`; | |
type ISOMilliseconds = `${ZeroThroughNine}${ZeroThroughNine}${ZeroThroughNine}`; | |
export type ISOTimeString = | |
`${ISOHours}:${ISOSecondsAndMinutes}:${ISOSecondsAndMinutes}.${ISOMilliseconds}`; | |
export type ISODateString = `${ISOYear}-${ISOMonth}-${ISODay}`; | |
export type ISODateTimeString = `${ISODateString}T${ISOTimeString}Z`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment