MCPcopy Create free account
hub / github.com/Effect-TS/effect / parseTimeOfDay

Function parseTimeOfDay

packages/sql/pg/src/PgTypes.ts:600–614  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

598
599/** Microseconds since midnight. A day of them is well inside `Number`'s exact range. */
600const 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
616const formatTimeOfDay = (micros: number): string => {
617 const seconds = (micros / 1_000_000) | 0

Callers 1

PgTypes.tsFile · 0.85

Calls 3

failFunction · 0.70
NumberFunction · 0.50
execMethod · 0.45

Tested by

no test coverage detected