vbv/client/src/components/dueDates/dueDatesUtils.ts

52 lines
1.3 KiB
TypeScript

import type { Dayjs } from "dayjs";
export const formatDate = (start: Dayjs, end: Dayjs) => {
const startDateString = getDateString(start);
const endDateString = getDateString(end);
// if start isundefined, dont show the day twice
if (!start.isValid() && !end.isValid()) {
return "Termin nicht festgelegt";
}
if (!start || (!start.isValid() && end.isValid())) {
return `${endDateString} ${getTimeString(end)} ${end.format("[Uhr]")}`;
}
if (!end || (!end.isValid() && start.isValid())) {
return `${startDateString} ${getTimeString(start)} ${start.format("[Uhr]")}`;
}
// if start and end are on the same day, dont show the day twice
if (startDateString === endDateString) {
return `${startDateString} ${getTimeString(start)} - ${getTimeString(
end
)} ${end.format("[Uhr]")}`;
}
return `${startDateString} ${getTimeString(start)} - ${endDateString} ${getTimeString(
end
)}`;
};
export const getTimeString = (date?: Dayjs) => {
if (date) {
return `${date.format("H:mm")}`;
}
return "";
};
export const getDateString = (date?: Dayjs) => {
if (date) {
return `${date.format("D. MMMM YYYY")}`;
}
return "";
};
export const getWeekday = (date: Dayjs) => {
if (date) {
return `${date.format("dd")}`;
}
return "";
};