Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions __tests__/helpers/locale/locale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,18 @@ describe('Locale Tests', () => {
describe('formatMinutesForLocale', () => {
it('Should format minutes only.', () => {
mockMDHLanguage = "en-US";
const result = formatMinutesForLocale(45);
expect(result).toBe("45m");
expect(formatMinutesForLocale(45.4)).toBe("45m");
expect(formatMinutesForLocale(45.5)).toBe("46m");
});
it('Should format hours only.', () => {
mockMDHLanguage = "en-US";
expect(formatMinutesForLocale(119.5)).toBe("2h");
expect(formatMinutesForLocale(120.4)).toBe("2h");
});
it('Should format hours/minutes.', () => {
mockMDHLanguage = "en-US";
const result = formatMinutesForLocale(94);
expect(result).toBe("1h 34m");
expect(formatMinutesForLocale(94.4)).toBe("1h 34m");
expect(formatMinutesForLocale(94.5)).toBe("1h 35m");
});
it('Should format by locale.', () => {
mockMDHLanguage = "de-DE";
Expand Down
17 changes: 12 additions & 5 deletions src/helpers/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,19 @@ export function formatNumberForLocale(value: number | undefined, fractionDigits?

/** e.g., 7h 5m */
export function formatMinutesForLocale(value: number) {
var hours = Math.floor(value / 60);
var displayValue = hours > 0 ? (`${hours}${language("hours-abbreviation")} `) : "";
if (Math.round(value - (hours * 60)) !== 0) {
displayValue = `${displayValue}${(Math.round(value - (hours * 60)))}${language("minutes-abbreviation")}`;
const totalMinutes = Math.round(value);

const displayHours = Math.floor(totalMinutes / 60);
const displayMinutes = totalMinutes % 60;

const displayParts = [];
if (displayHours !== 0) {
displayParts.push(`${displayHours}${language('hours-abbreviation')}`);
}
if (displayMinutes !== 0) {
displayParts.push(`${displayMinutes}${language('minutes-abbreviation')}`);
}
return displayValue;
return displayParts.join(' ');
}

export function capitalizeFirstLetterForLocale(str: string) {
Expand Down
Loading