-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.ts
More file actions
33 lines (28 loc) · 1.17 KB
/
utils.ts
File metadata and controls
33 lines (28 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { TestPlansQueryBuilderFieldNames } from "./constants/TestPlansQueryBuilder.constants";
export function isTimeField(
queryBuilderFieldName: TestPlansQueryBuilderFieldNames
): boolean {
return (
queryBuilderFieldName === TestPlansQueryBuilderFieldNames.CreatedAt
|| queryBuilderFieldName === TestPlansQueryBuilderFieldNames.UpdatedAt
|| queryBuilderFieldName === TestPlansQueryBuilderFieldNames.PlannedStartDate
|| queryBuilderFieldName === TestPlansQueryBuilderFieldNames.EstimatedEndDate
);
}
export const transformDuration = (totalSeconds: number): string => {
const timeUnits = [
{ label: 'day', secondsInUnit: 86400 },
{ label: 'hr', secondsInUnit: 3600 },
{ label: 'min', secondsInUnit: 60 },
{ label: 'sec', secondsInUnit: 1 },
];
const parts: string[] = [];
for (const { label, secondsInUnit } of timeUnits) {
const count = Math.floor(totalSeconds / secondsInUnit);
if (count > 0) {
parts.push(`${count} ${label}${count > 1 ? 's' : ''}`);
totalSeconds %= secondsInUnit;
}
}
return parts.length > 0 ? parts.join(', ') : '0 sec';
};