(str: string)
| 175 | * @returns A Dayjs Duration object representing the total time. |
| 176 | */ |
| 177 | const 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. |
no outgoing calls
no test coverage detected