fix(date-time-utils): fix rounding error in util method that converts hours float to HHmm string

This commit is contained in:
Nic D. 2026-01-26 10:05:47 -05:00
parent e44d790a21
commit 42de823b87

View File

@ -21,7 +21,13 @@ export const getMinutes = (hours: number) => {
} }
export const getHoursMinutesStringFromHoursFloat = (hours: number): string => { export const getHoursMinutesStringFromHoursFloat = (hours: number): string => {
const flat_hours = Math.floor(hours); let flat_hours = Math.floor(hours);
const minutes = Math.round((hours - flat_hours) * 60); let minutes = Math.round((hours - flat_hours) * 60);
if (minutes === 60) {
flat_hours += 1;
minutes = 0;
}
return `${flat_hours}h${minutes > 1 ? ' ' + minutes : ''}` return `${flat_hours}h${minutes > 1 ? ' ' + minutes : ''}`
} }