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

Method parseDate

packages/effect/src/encoding/Toml.ts:268–288  ·  view source on GitHub ↗
(token: string)

Source from the content-addressed store, hash-verified

266 }
267
268 private parseDate(token: string): Date | string | undefined {
269 const dateTime = dateTimePattern.exec(token)
270 if (dateTime !== null) {
271 const [, date, rawTime, offset] = dateTime
272 const time = withSeconds(rawTime)
273 // `Date` cannot represent a leap second, so offset date-times reject `:60`
274 const offsetValid = offset === undefined || (isValidOffset(offset) && time.slice(6, 8) !== "60")
275 if (!isValidDate(date) || !isValidTime(time) || !offsetValid) {
276 this.fail(`Invalid date-time '${token}'`)
277 }
278 return offset === undefined ? `${date}T${time}` : new Date(`${date}T${time}${offset.toUpperCase()}`)
279 }
280 if (localDatePattern.test(token)) {
281 return isValidDate(token) ? token : this.fail(`Invalid date-time '${token}'`)
282 }
283 if (localTimePattern.test(token)) {
284 const time = withSeconds(token)
285 return isValidTime(time) ? time : this.fail(`Invalid date-time '${token}'`)
286 }
287 return undefined
288 }
289
290 private parseNumber(token: string): number | undefined {
291 const normalized = token.replace(/_/g, "")

Callers 1

parseValueMethod · 0.95

Calls 7

failMethod · 0.95
withSecondsFunction · 0.85
isValidOffsetFunction · 0.85
isValidDateFunction · 0.85
isValidTimeFunction · 0.85
sliceMethod · 0.80
execMethod · 0.45

Tested by

no test coverage detected