Bug(release-4.22): incorrect duration calculation
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- frontend
Research direction
Start in frontend/public/components/utils/build-utils.ts, at displayDurationInWords around lines 3-33. Reproduce the duration calculation with a duration exceeding 60 hours, then update the behavior so long durations are represented correctly and invalid or negative values are handled as specified in the issue. Verify the resulting duration wording for days, hours, minutes, and seconds.
Written by the indexing model from the issue text.
Description
export const displayDurationInWords = (start: string, stop: string): string => {
if (!start) {
return '-';
}
const startTime = new Date(start).getTime();
const stopTime = stop ? new Date(stop).getTime() : new Date().getTime();
let duration = Math.round((stopTime - startTime) / 1000);
const time = [];
let durationInWords = '';
while (duration >= 60) {
time.push(duration % 60);
duration = Math.floor(duration / 60);
}
time.push(duration);
if (time[2]) {
durationInWords += `${time[2]} ${
time[2] > 1 ? i18next.t('public~hours') : i18next.t('public~hour')
} `;
}
if (time[1]) {
durationInWords += `${time[1]} ${
time[1] > 1 ? i18next.t('public~minutes') : i18next.t('public~minute')
} `;
}
if (time[0]) {
durationInWords += `${time[0]} ${
time[0] > 1 ? i18next.t('public~seconds') : i18next.t('public~second')
} `;
}
return durationInWords.trim();
};
Duration exceeding 60 hours causes an error
I'd suggest using the following calculation instead:
export const displayDurationInWords = (start: string, stop: string): string => {
if (!start) {
return '-';
}
const startTime = new Date(start).getTime();
const stopTime = stop ? new Date(stop).getTime() : new Date().getTime();
const duration = Math.max(0, Math.round((stopTime - startTime) / 1000));
if (!Number.isFinite(duration)) {
return '-';
}
const seconds = duration % 60;
const minutes = Math.floor(duration / 60) % 60;
const hours = Math.floor(duration / 3600) % 24;
const days = Math.floor(duration / 86400);
const durationInWords = [];
if (days) {
durationInWords.push(`${days} ${days > 1 ? i18next.t('public~days') : i18next.t('public~day')}`);
}
if (hours) {
durationInWords.push(
`${hours} ${hours > 1 ? i18next.t('public~hours') : i18next.t('public~hour')}`,
);
}
if (minutes) {
durationInWords.push(
`${minutes} ${minutes > 1 ? i18next.t('public~minutes') : i18next.t('public~minute')}`,
);
}
if (seconds || !durationInWords.length) {
durationInWords.push(
`${seconds} ${seconds === 1 ? i18next.t('public~second') : i18next.t('public~seconds')}`,
);
}
return durationInWords.join(' ');
};
- Dominant language
- TypeScript
- Stars
- 460
- Forks
- 756
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 88
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from openshift/console
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 67/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
All issues in openshift/console
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
fullcalendar/fullcalendar#8106 ·