fix(util/duration): changed backend domain
This commit is contained in:
parent
5c7a3d71de
commit
7f307f080e
|
@ -106,7 +106,7 @@ export const pprintDateRange = (d1: string | Date | Dayjs, d2: string | Date | D
|
|||
|
||||
/**
|
||||
* Format the duration between two dates.
|
||||
* Example: "1 Tag, 2 Std"
|
||||
* Example: "3 Wo, 1 Tag, 2 Std, 53 Min"
|
||||
* @param date1
|
||||
* @param date2
|
||||
*/
|
||||
|
@ -114,19 +114,26 @@ export function formatDuration(date1: string | Date | Dayjs, date2: string | Dat
|
|||
const start = dayjs(date1)
|
||||
const end = dayjs(date2)
|
||||
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) {
|
||||
return `${dur.minutes()} Min`
|
||||
} else if (dur.asDays() < 1) {
|
||||
return `${dur.hours()} Std`
|
||||
} 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)`
|
||||
const parts = [];
|
||||
|
||||
if (weeks > 0) {
|
||||
parts.push(`${weeks} Wo`);
|
||||
}
|
||||
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(', ');
|
||||
}
|
Loading…
Reference in New Issue