MCPcopy Index your code
hub / github.com/ByBrawe/opencode-loop / parseDuration

Function parseDuration

src/index.js:69–83  ·  view source on GitHub ↗
(value)

Source from the content-addressed store, hash-verified

67 .slice(0, 80) || "job"
68}
69
70function parseDuration(value) {
71 const input = String(value || "").trim()
72 if (input === "0") return 0
73 const match = input.match(/^(\d+)\s*(ms|s|sec|secs|second|seconds|m|min|mins|minute|minutes|h|hr|hrs|hour|hours|d|day|days)$/i)
74 if (!match) return null
75 const amount = Number.parseInt(match[1], 10)
76 const unit = match[2].toLowerCase()
77 if (!Number.isFinite(amount) || amount < 0) return null
78 if (unit === "ms") return amount
79 if (unit.startsWith("s")) return amount * 1000
80 if (unit.startsWith("m")) return amount * 60_000
81 if (unit.startsWith("h")) return amount * 3_600_000
82 if (unit.startsWith("d")) return amount * 86_400_000
83 return null
84}
85
86function durationToText(ms) {

Callers 3

parseCompactEveryFunction · 0.85
parseLoopArgsFunction · 0.85
presetDefaultsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected