(match: RegExpMatchArray)
| 971 | * Used instead of `Date.parse` because of browser discrepancies. |
| 972 | */ |
| 973 | export function isoStringToDate(match: RegExpMatchArray): Date { |
| 974 | const date = new Date(0); |
| 975 | let tzHour = 0; |
| 976 | let tzMin = 0; |
| 977 | |
| 978 | // match[8] means that the string contains "Z" (UTC) or a timezone like "+01:00" or "+0100" |
| 979 | const dateSetter = match[8] ? date.setUTCFullYear : date.setFullYear; |
| 980 | const timeSetter = match[8] ? date.setUTCHours : date.setHours; |
| 981 | |
| 982 | // if there is a timezone defined like "+01:00" or "+0100" |
| 983 | if (match[9]) { |
| 984 | tzHour = Number(match[9] + match[10]); |
| 985 | tzMin = Number(match[9] + match[11]); |
| 986 | } |
| 987 | dateSetter.call(date, Number(match[1]), Number(match[2]) - 1, Number(match[3])); |
| 988 | const h = Number(match[4] || 0) - tzHour; |
| 989 | const m = Number(match[5] || 0) - tzMin; |
| 990 | const s = Number(match[6] || 0); |
| 991 | // The ECMAScript specification (https://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.11) |
| 992 | // defines that `DateTime` milliseconds should always be rounded down, so that `999.9ms` |
| 993 | // becomes `999ms`. |
| 994 | const ms = Math.floor(parseFloat('0.' + (match[7] || 0)) * 1000); |
| 995 | timeSetter.call(date, h, m, s, ms); |
| 996 | return date; |
| 997 | } |
| 998 | |
| 999 | export function isDate(value: any): value is Date { |
| 1000 | return value instanceof Date && !isNaN(value.valueOf()); |
no outgoing calls
no test coverage detected
searching dependent graphs…