MCPcopy
hub / github.com/angular/angular / parseDurationToMs

Function parseDurationToMs

packages/service-worker/config/src/duration.ts:12–48  ·  view source on GitHub ↗
(duration: string)

Source from the content-addressed store, hash-verified

10const PAIR_SPLIT = /^([0-9]+)([dhmsu]+)$/;
11
12export function parseDurationToMs(duration: string): number {
13 const matches: string[] = [];
14
15 let array: RegExpExecArray | null;
16 while ((array = PARSE_TO_PAIRS.exec(duration)) !== null) {
17 matches.push(array[0]);
18 }
19 return matches
20 .map((match) => {
21 const res = PAIR_SPLIT.exec(match);
22 if (res === null) {
23 throw new Error(`Not a valid duration: ${match}`);
24 }
25 let factor: number = 0;
26 switch (res[2]) {
27 case 'd':
28 factor = 86400000;
29 break;
30 case 'h':
31 factor = 3600000;
32 break;
33 case 'm':
34 factor = 60000;
35 break;
36 case 's':
37 factor = 1000;
38 break;
39 case 'u':
40 factor = 1;
41 break;
42 default:
43 throw new Error(`Not a valid duration unit: ${res[2]}`);
44 }
45 return parseInt(res[1]) * factor;
46 })
47 .reduce((total, value) => total + value, 0);
48}

Callers 2

processMethod · 0.90
processDataGroupsMethod · 0.90

Calls 3

reduceMethod · 0.80
mapMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…