.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / table / node_modules / ajv / lib / runtime / timestamp.ts
1 const DATE_TIME = /^(\d\d\d\d)-(\d\d)-(\d\d)(?:t|\s)(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:z|([+-]\d\d)(?::?(\d\d))?)$/i
2 const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
3
4 export default function validTimestamp(str: string): boolean {
5   // http://tools.ietf.org/html/rfc3339#section-5.6
6   const matches: string[] | null = DATE_TIME.exec(str)
7   if (!matches) return false
8   const y: number = +matches[1]
9   const m: number = +matches[2]
10   const d: number = +matches[3]
11   const hr: number = +matches[4]
12   const min: number = +matches[5]
13   const sec: number = +matches[6]
14   const tzH: number = +(matches[7] || 0)
15   const tzM: number = +(matches[8] || 0)
16   return (
17     m >= 1 &&
18     m <= 12 &&
19     d >= 1 &&
20     (d <= DAYS[m] ||
21       // leap year: https://tools.ietf.org/html/rfc3339#appendix-C
22       (m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0))) &&
23     ((hr <= 23 && min <= 59 && sec <= 59) ||
24       // leap second
25       (hr - tzH === 23 && min - tzM === 59 && sec === 60))
26   )
27 }
28
29 validTimestamp.code = 'require("ajv/dist/runtime/timestamp").default'