X-Git-Url: https://git.josue.xyz/?p=dotfiles%2F.git;a=blobdiff_plain;f=.config%2Fcoc%2Fextensions%2Fnode_modules%2Fcoc-prettier%2Fnode_modules%2Ftable%2Fnode_modules%2Fajv%2Flib%2Fruntime%2Ftimestamp.ts;h=1625f9a40f4443fde14743a6a8ecb6c1dc8fb819;hp=fed0e3be3915cbd2ff2e4933d6df332527da7e78;hb=3be0a9efc698a9570a44456009afc6014812625a;hpb=d2f432cc757f42f0318fdddcab8c00b240d47088 diff --git a/.config/coc/extensions/node_modules/coc-prettier/node_modules/table/node_modules/ajv/lib/runtime/timestamp.ts b/.config/coc/extensions/node_modules/coc-prettier/node_modules/table/node_modules/ajv/lib/runtime/timestamp.ts index fed0e3be..1625f9a4 100644 --- a/.config/coc/extensions/node_modules/coc-prettier/node_modules/table/node_modules/ajv/lib/runtime/timestamp.ts +++ b/.config/coc/extensions/node_modules/coc-prettier/node_modules/table/node_modules/ajv/lib/runtime/timestamp.ts @@ -1,28 +1,45 @@ -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 +const DT_SEPARATOR = /t|\s/i +const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/ +const TIME = /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:z|([+-]\d\d)(?::?(\d\d))?)$/i const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] -export default function validTimestamp(str: string): boolean { +export default function validTimestamp(str: string, allowDate: boolean): boolean { // http://tools.ietf.org/html/rfc3339#section-5.6 - const matches: string[] | null = DATE_TIME.exec(str) + const dt: string[] = str.split(DT_SEPARATOR) + return ( + (dt.length === 2 && validDate(dt[0]) && validTime(dt[1])) || + (allowDate && dt.length === 1 && validDate(dt[0])) + ) +} + +function validDate(str: string): boolean { + const matches: string[] | null = DATE.exec(str) if (!matches) return false const y: number = +matches[1] const m: number = +matches[2] const d: number = +matches[3] - const hr: number = +matches[4] - const min: number = +matches[5] - const sec: number = +matches[6] - const tzH: number = +(matches[7] || 0) - const tzM: number = +(matches[8] || 0) return ( m >= 1 && m <= 12 && d >= 1 && (d <= DAYS[m] || // leap year: https://tools.ietf.org/html/rfc3339#appendix-C - (m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0))) && - ((hr <= 23 && min <= 59 && sec <= 59) || - // leap second - (hr - tzH === 23 && min - tzM === 59 && sec === 60)) + (m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0))) + ) +} + +function validTime(str: string): boolean { + const matches: string[] | null = TIME.exec(str) + if (!matches) return false + const hr: number = +matches[1] + const min: number = +matches[2] + const sec: number = +matches[3] + const tzH: number = +(matches[4] || 0) + const tzM: number = +(matches[5] || 0) + return ( + (hr <= 23 && min <= 59 && sec <= 59) || + // leap second + (hr - tzH === 23 && min - tzM === 59 && sec === 60) ) }