Skip to content

Commit 4084c8d

Browse files
authored
fix time to support 3m and 3s formats (#256)
1 parent fdf22bc commit 4084c8d

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

services/frontend/react_app/src/hooks/useGetRequestArrival.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,25 @@ export const useGetRequestArrival = (logs: Log[]) => {
1212
const parseDriverLogService = (entry: LogEntry) => {
1313
if (entry.service !== 'driver') return;
1414

15-
const timeRegex = /(\d+)m(\d+)s/;
16-
const match = entry.status.match(timeRegex);
15+
const rawTimeMatch = entry.status.match(/(\d+m\d+s|\d+m|\d+s)/);
1716

18-
if (!match) return;
17+
if (!rawTimeMatch) return; // No substring that looks like time
18+
19+
const rawTime = rawTimeMatch[0];
1920

20-
const minutes = parseInt(match[1], 10);
21-
const seconds = parseInt(match[2], 10);
21+
/**
22+
* Possible cases
23+
* 3m
24+
* 3m2s
25+
* 2s
26+
* */
27+
const timeRegex = /^(?:(\d+)m)?(?:(\d+)s)?$/;
28+
const match = rawTime.match(timeRegex);
29+
30+
if (!match) return;
2231

32+
const minutes = parseInt(match[1] || '0', 10);
33+
const seconds = parseInt(match[2] || '0', 10);
2334
return minutes * 60 + seconds;
2435
};
2536

0 commit comments

Comments
 (0)