MCPcopy Create free account
hub / github.com/DIYgod/RSSHub / parseDuration

Function parseDuration

lib/utils/parse-date.ts:177–192  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

175 * @returns A Dayjs Duration object representing the total time.
176 */
177const parseDuration = (str: string): plugin.Duration => {
178 let totalDuration = dayjs.duration(0);
179 // Remove spaces for regex unit matching
180 const cleanStr = str.replaceAll(/\s+/g, '');
181
182 for (const { unit, regExp } of UNIT_PATTERNS) {
183 const match = regExp.exec(cleanStr);
184 if (match) {
185 const val = Number(match[1]);
186 if (!Number.isNaN(val)) {
187 totalDuration = totalDuration.add(val, unit);
188 }
189 }
190 }
191 return totalDuration;
192};
193
194/**
195 * A wrapper around `dayjs()` to parse standard date formats.

Callers 2

processSemanticKeywordFunction · 0.70
parseRelativeDateFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected