MCPcopy Index your code
hub / github.com/Effect-TS/effect / fromIso

Function fromIso

packages/effect/src/Duration.ts:981–997  ·  view source on GitHub ↗
(iso: string)

Source from the content-addressed store, hash-verified

979 * @category conversions
980 */
981export const fromIso = (iso: string): Option.Option<Duration> => {
982 const result = DURATION_ISO_REGEX.exec(iso)
983 if (result == null) {
984 return Option.none()
985 }
986
987 const [years, months, weeks, days, hours, mins, secs] = result.slice(1, 8).map((_) => _ ? Number(_) : 0)
988 const value = years * 365 * 24 * 60 * 60 +
989 months * 30 * 24 * 60 * 60 +
990 weeks * 7 * 24 * 60 * 60 +
991 days * 24 * 60 * 60 +
992 hours * 60 * 60 +
993 mins * 60 +
994 secs
995
996 return Option.some(seconds(value))
997}
998
999const DURATION_ISO_REGEX =
1000 /^P(?!$)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?!$)(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/

Callers

nothing calls this directly

Calls 3

NumberInterface · 0.85
secondsFunction · 0.85
mapMethod · 0.65

Tested by

no test coverage detected