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

Function parseZone

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

Source from the content-addressed store, hash-verified

625
626/** Parses a trailing time zone into seconds east of UTC. */
627const parseZone = (text: string): number => {
628 const match = zoneRegex.exec(text)
629 if (match === null) {
630 return fail(`Expected a time zone offset, received "${text}"`)
631 }
632 if (match[1] === undefined) return 0
633 const minutes = match[3] === undefined ? 0 : Number(match[3])
634 const trailingSeconds = match[4] === undefined ? 0 : Number(match[4])
635 const seconds = Number(match[2]) * 3600 + minutes * 60 + trailingSeconds
636 if (minutes > 59 || trailingSeconds > 59 || seconds >= TZDISP_LIMIT_SECONDS) {
637 return fail(`Time zone offset out of range, received "${text}"`)
638 }
639 return match[1] === "-" ? -seconds : seconds
640}
641
642const formatZone = (secondsEast: number): string => {
643 const sign = secondsEast < 0 ? "-" : "+"

Callers 1

PgTypes.tsFile · 0.85

Calls 3

failFunction · 0.70
NumberFunction · 0.50
execMethod · 0.45

Tested by

no test coverage detected