mirror of
https://github.com/open-reception/appointment-booking-software.git
synced 2026-09-29 04:04:51 +02:00
Added dummy flow to add appointments using the calendar
This commit is contained in:
@@ -1,15 +1,28 @@
|
||||
import { getLocale } from "$i18n/runtime";
|
||||
import type { TCalendarSlot } from "$lib/types/calendar";
|
||||
import { parseAbsoluteToLocal, toCalendarDateTime } from "@internationalized/date";
|
||||
|
||||
export const toDisplayDateTime = (date: Date) => {
|
||||
export const toDisplayDateTime = (date: Date, opts?: Intl.DateTimeFormatOptions) => {
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
const formatter = new Intl.DateTimeFormat(navigator.language, {
|
||||
dateStyle: "short",
|
||||
...(hours !== 0 || minutes !== 0 ? { timeStyle: "short" } : {}),
|
||||
});
|
||||
const formatter = new Intl.DateTimeFormat(
|
||||
getLocale(),
|
||||
opts ?? {
|
||||
dateStyle: "short",
|
||||
...(hours !== 0 || minutes !== 0 ? { timeStyle: "short" } : {}),
|
||||
},
|
||||
);
|
||||
return formatter.format(date);
|
||||
};
|
||||
|
||||
export const calendarItemToDate = (item: TCalendarSlot) => {
|
||||
const [year, month, day] = item.date.split("-").map(Number);
|
||||
const [hours, minutes] = item.start.split(":").map((it) => parseInt(it));
|
||||
const date = new Date(year, month - 1, day);
|
||||
date.setHours(hours, minutes, 0, 0);
|
||||
return date;
|
||||
};
|
||||
|
||||
export const toInputDateTime = (dateStr: string) => {
|
||||
return toCalendarDateTime(parseAbsoluteToLocal(dateStr));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user