[api] Add datetime util for start-end ranges

This commit is contained in:
Ferdinand Thiessen 2021-11-23 16:00:18 +01:00
parent 664def40fc
commit e4889ddac2
1 changed files with 11 additions and 0 deletions

View File

@ -25,6 +25,17 @@ export function asHour(date?: Date) {
return date ? formatDateTime(date, false, true) : ''; return date ? formatDateTime(date, false, true) : '';
} }
export function formatStartEnd(start: Date, end?: Date) {
const today = asDate(new Date());
const startDate = asDate(start);
const endDate = end ? asDate(end) : '';
return (
(today !== startDate ? `${startDate}, ` : '') +
asHour(start) +
(end ? ' - ' + (endDate !== startDate ? `${endDate}, ` : '') + asHour(end) : '')
);
}
export function startOfWeek(date: Date, startMonday = true) { export function startOfWeek(date: Date, startMonday = true) {
const start = new Date(date); const start = new Date(date);
const day = date.getDay() || 7; const day = date.getDay() || 7;