Files
cal.diy/packages/features/bookings/Booker/utils/dates.tsx
T

39 lines
954 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import dayjs from "@calcom/dayjs";
import type { TimeFormat } from "@calcom/lib/timeFormat";
interface EventFromToTime {
date: string;
duration: number | null;
timeFormat: TimeFormat;
timeZone: string;
language: string;
}
export const formatEventFromToTime = ({
date,
duration,
timeFormat,
timeZone,
language,
}: EventFromToTime) => {
const start = dayjs(date).tz(timeZone);
const end = duration ? start.add(duration, "minute") : null;
const formattedDate = `${start.format("dddd")}, ${start
.toDate()
.toLocaleDateString(language, { dateStyle: "long" })}`;
const formattedTime = `${start.format(timeFormat)} ${end ? `– ${end.format(timeFormat)}` : ``}`;
return { date: formattedDate, time: formattedTime };
};
export const FromToTime = (props: EventFromToTime) => {
const formatted = formatEventFromToTime(props);
return (
<>
{formatted.date}
<br />
{formatted.time}
</>
);
};