Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 3c4f088

Browse files
committed
fix (admin): show minutes for reservation duration
1 parent 4c0316b commit 3c4f088

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

apps/admin-ui/src/component/reservations/requested/util.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ describe("createTag", () => {
124124

125125
const mockT = ((x: string) => x) as TFunction;
126126
const tag = createTagString(res, mockT);
127-
expect(tag).toContain("dayShort.0, dayShort.1, dayShort.3 12:00-14:00, 2t");
127+
expect(tag).toContain(
128+
"dayShort.0, dayShort.1, dayShort.3 12:00-14:00, common.hoursUnit"
129+
);
128130
expect(tag).toContain("1.4.2023-1.7.2023");
129131
expect(tag).toContain("Foobar");
130132
});
@@ -145,7 +147,7 @@ describe("createTag", () => {
145147
const tag = createTagString(res, mockT);
146148
expect(tag).not.toContain("dayShort.0, dayShort.1, dayShort.3");
147149
expect(tag).toContain("1.4.2023");
148-
expect(tag).toContain("12:00-14:00, 2t");
150+
expect(tag).toContain("12:00-14:00, common.hoursUnit");
149151
expect(tag).toContain("dayShort.5");
150152
expect(tag).toContain("Foobar");
151153
});

apps/admin-ui/src/component/reservations/requested/util.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,19 @@ export const reservationDuration = (start: Date, end: Date): string => {
6363
return `${differenceInHours(end, start)}`;
6464
};
6565

66-
const reservationDurationString = (start: string, end: string): string => {
66+
const reservationDurationString = (
67+
start: string,
68+
end: string,
69+
t: TFunction
70+
): string => {
6771
const startDate = new Date(start);
6872
const endDate = new Date(end);
6973

70-
return `${differenceInHours(endDate, startDate)}`;
74+
const h = differenceInHours(endDate, startDate);
75+
const m = differenceInMinutes(endDate, startDate) - h * 60;
76+
return `${t("common.hoursUnit", { count: h })} ${
77+
m !== 0 ? t("common.minutesUnit", { count: m }) : ""
78+
}`;
7179
};
7280

7381
export const reservationUnitName = (
@@ -255,12 +263,13 @@ export const createTagString = (reservation: ReservationType, t: TFunction) => {
255263

256264
const durationTag = `${reservationDurationString(
257265
reservation.begin,
258-
reservation.end
266+
reservation.end,
267+
t
259268
)}`;
260269

261270
const reservationTagline = `${
262271
reservation.recurringReservation ? recurringDateTag : singleDateTimeTag
263-
}, ${durationTag}t ${
272+
}, ${durationTag} ${
264273
recurringTag.length > 0 ? " | " : ""
265274
} ${recurringTag} | ${unitTag}`;
266275

apps/admin-ui/src/i18n/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const translations: ITranslations = {
128128
volumeUnit: [" kpl", " ", " "],
129129
personUnit_one: ["{{count}} henkilö"],
130130
personUnit_other: ["{{count}} henkeä"],
131-
hoursUnit: ["{{count}} h"],
131+
hoursUnit: ["{{count}} t"],
132132
hoursUnitLong_one: ["{{count}} tunti"],
133133
hoursUnitLong_other: ["{{count}} tuntia"],
134134
minutesUnit: ["{{count}} min"],

0 commit comments

Comments
 (0)