MCPcopy Create free account
hub / github.com/simstudioai/sim / parseIso8601Duration

Function parseIso8601Duration

apps/sim/connectors/youtube/youtube.ts:85–97  ·  view source on GitHub ↗

* Parses an ISO 8601 duration (e.g. `PT1M30S`, `PT2H`, `P1DT2H`) into total seconds. * Returns null when the value is missing or unparseable.

(value: string | undefined)

Source from the content-addressed store, hash-verified

83 * Returns null when the value is missing or unparseable.
84 */
85function parseIso8601Duration(value: string | undefined): number | null {
86 if (!value) return null
87 const match = value.match(/^P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/)
88 if (!match) return null
89 const [, days, hours, minutes, seconds] = match
90 if (!days && !hours && !minutes && !seconds) return null
91 return (
92 Number(days ?? 0) * 86400 +
93 Number(hours ?? 0) * 3600 +
94 Number(minutes ?? 0) * 60 +
95 Number(seconds ?? 0)
96 )
97}
98
99/**
100 * Resolves a channel reference to its "uploads" playlist ID via `channels.list`.

Callers 1

videoToDocumentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected