(text: string)
| 598 | |
| 599 | /** Microseconds since midnight. A day of them is well inside `Number`'s exact range. */ |
| 600 | const parseTimeOfDay = (text: string): number => { |
| 601 | const match = timeRegex.exec(text) |
| 602 | if (match === null) { |
| 603 | return fail(`Expected a HH:MM[:SS[.ffffff]] time, received "${text}"`) |
| 604 | } |
| 605 | const hours = Number(match[1]) |
| 606 | const minutes = Number(match[2]) |
| 607 | const seconds = match[3] === undefined ? 0 : Number(match[3]) |
| 608 | const fraction = match[4] === undefined ? 0 : Number(match[4].padEnd(6, "0")) |
| 609 | const micros = (hours * 3600 + minutes * 60 + seconds) * 1_000_000 + fraction |
| 610 | if (hours > 24 || minutes > 59 || seconds > 60 || micros > MAX_TIME_MICROS_NUMBER) { |
| 611 | return fail(`Invalid time "${text}"`) |
| 612 | } |
| 613 | return micros |
| 614 | } |
| 615 | |
| 616 | const formatTimeOfDay = (micros: number): string => { |
| 617 | const seconds = (micros / 1_000_000) | 0 |
no test coverage detected