Skip to content

Commit 9321756

Browse files
committed
feat: add 9155-hard-validdate
1 parent ce38da8 commit 9321756

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// 参考 https://github.com/type-challenges/type-challenges/issues/11380
2+
type D30 =
3+
| `${0 | 1 | 2}${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}`
4+
| "10"
5+
| "20"
6+
| "30";
7+
type D31 = D30 | "31";
8+
type D28 = Exclude<D30, "29" | "30">;
9+
10+
type ValidDate<T extends string> = T extends `${
11+
| "01"
12+
| "03"
13+
| "05"
14+
| "07"
15+
| "08"
16+
| "10"
17+
| "12"}${D31}`
18+
? true
19+
: T extends `${"04" | "06" | "09" | "11"}${D30}`
20+
? true
21+
: T extends `${"02"}${D28}`
22+
? true
23+
: false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Equal, Expect } from "@type-challenges/utils";
2+
3+
type cases = [
4+
Expect<Equal<ValidDate<"0102">, true>>,
5+
Expect<Equal<ValidDate<"0131">, true>>,
6+
Expect<Equal<ValidDate<"1231">, true>>,
7+
Expect<Equal<ValidDate<"0229">, false>>,
8+
Expect<Equal<ValidDate<"0100">, false>>,
9+
Expect<Equal<ValidDate<"0132">, false>>,
10+
Expect<Equal<ValidDate<"1301">, false>>
11+
];

0 commit comments

Comments
 (0)