cal.pub0.org/packages/features/bookings/Booker/utils/dates.tsx

39 lines
954 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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}
</>
);
};