Last active
June 4, 2023 08:21
-
-
Save nghiepdev/b9e85bc96a0a83b026960b5b12351f4c to your computer and use it in GitHub Desktop.
Typing for TimeString and DateString
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 Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; | |
type H = `${0 | 1}${Digit}` | `${2}${0 | 1 | 2 | 3}`; | |
type M = `${0 | 1 | 2 | 3 | 4 | 5}${Digit}`; | |
type S = `${0 | 1 | 2 | 3 | 4 | 5}${Digit}`; | |
export type TimeString = `${H}:${M}` | `${H}:${M}:${S}`; // 03:45 or 03:45:56 | |
type Mo = Exclude<`0${Digit}` | `1${0 | 1 | 2}`, '00'>; | |
type Da = Exclude<`${0 | 1 | 2}${Digit}` | `3${0 | 1}`, '00'>; | |
export type DateString = `${number}-${Mo}-${Da}`; // 2017-02-23 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment