@@ -41,17 +41,35 @@ function parseNonNegativeNumber(value: unknown): number | null {
|
41 | 41 | } |
42 | 42 | |
43 | 43 | export function parsePsCpuTimeMs(raw: string): number | null { |
44 | | -const parts = raw.trim().split(":").map(Number); |
45 | | -if (parts.some((part) => !Number.isFinite(part) || part < 0)) { |
| 44 | +const match = raw.trim().match(/^(?:(\d+)-)?(\d+):(\d{2}(?:\.\d+)?)(?::(\d{2}(?:\.\d+)?))?$/u); |
| 45 | +if (!match) { |
46 | 46 | return null; |
47 | 47 | } |
48 | | -if (parts.length === 2) { |
49 | | -return Math.round((parts[0] * 60 + parts[1]) * 1000); |
| 48 | +const [, daysRaw, firstRaw, secondRaw, thirdRaw] = match; |
| 49 | +if (daysRaw !== undefined && thirdRaw === undefined) { |
| 50 | +return null; |
| 51 | +} |
| 52 | +const days = daysRaw === undefined ? 0 : Number(daysRaw); |
| 53 | +const first = Number(firstRaw); |
| 54 | +const second = Number(secondRaw); |
| 55 | +const third = thirdRaw === undefined ? 0 : Number(thirdRaw); |
| 56 | +const values = [days, first, second, third]; |
| 57 | +if (values.some((part) => !Number.isFinite(part) || part < 0)) { |
| 58 | +return null; |
| 59 | +} |
| 60 | +if (thirdRaw !== undefined && !Number.isInteger(second)) { |
| 61 | +return null; |
| 62 | +} |
| 63 | +if (second >= 60 || (thirdRaw !== undefined && third >= 60)) { |
| 64 | +return null; |
| 65 | +} |
| 66 | +if (daysRaw !== undefined && thirdRaw !== undefined) { |
| 67 | +return Math.round((days * 24 * 60 * 60 + first * 60 * 60 + second * 60 + third) * 1000); |
50 | 68 | } |
51 | | -if (parts.length === 3) { |
52 | | -return Math.round((parts[0] * 60 * 60 + parts[1] * 60 + parts[2]) * 1000); |
| 69 | +if (thirdRaw !== undefined) { |
| 70 | +return Math.round((first * 60 * 60 + second * 60 + third) * 1000); |
53 | 71 | } |
54 | | -return null; |
| 72 | +return Math.round((first * 60 + second) * 1000); |
55 | 73 | } |
56 | 74 | |
57 | 75 | export function parsePsRssBytes(raw: string): number | null { |
|