fix(util/duration): changed backend domain

This commit is contained in:
Valentin Kolb 2024-05-14 17:54:10 +02:00
parent 5c7a3d71de
commit 7f307f080e
1 changed files with 21 additions and 14 deletions

View File

@ -106,7 +106,7 @@ export const pprintDateRange = (d1: string | Date | Dayjs, d2: string | Date | D
/** /**
* Format the duration between two dates. * Format the duration between two dates.
* Example: "1 Tag, 2 Std" * Example: "3 Wo, 1 Tag, 2 Std, 53 Min"
* @param date1 * @param date1
* @param date2 * @param date2
*/ */
@ -114,19 +114,26 @@ export function formatDuration(date1: string | Date | Dayjs, date2: string | Dat
const start = dayjs(date1) const start = dayjs(date1)
const end = dayjs(date2) const end = dayjs(date2)
const diff = end.diff(start) const diff = end.diff(start)
const dur = dayjs.duration(diff) const duration = dayjs.duration(diff)
const weeks = Math.floor(duration.asDays() / 7);
const days = duration.days() % 7;
const hours = duration.hours();
const minutes = duration.minutes();
if (dur.asHours() < 1) { const parts = [];
return `${dur.minutes()} Min`
} else if (dur.asDays() < 1) { if (weeks > 0) {
return `${dur.hours()} Std` parts.push(`${weeks} Wo`);
} else if (dur.asWeeks() < 1) {
const days = dur.days()
const hours = dur.hours()
return hours === 0 ? `${days} Tag(e)` : `${days} Tag(e), ${hours} Std`
} else {
const weeks = Math.floor(dur.asWeeks())
const days = dur.days()
return days === 0 ? `${weeks} Wo` : `${weeks} Wo, ${days} Tag(e)`
} }
if (days > 0 || weeks > 0) {
parts.push(`${days} Tag${days > 1 ? 'e' : ''}`);
}
if (hours > 0) {
parts.push(`${hours} Std`);
}
if (minutes > 0) {
parts.push(`${minutes} Min`);
}
return parts.join(', ');
} }