2023-07-17 20:19:00 +00:00
|
|
|
import { TimeFormat } from "@calcom/lib/timeFormat";
|
2023-05-05 15:55:54 +00:00
|
|
|
|
|
|
|
interface EventFromToTime {
|
|
|
|
date: string;
|
|
|
|
duration: number | null;
|
|
|
|
timeFormat: TimeFormat;
|
|
|
|
timeZone: string;
|
|
|
|
language: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const formatEventFromToTime = ({
|
|
|
|
date,
|
|
|
|
duration,
|
|
|
|
timeFormat,
|
|
|
|
timeZone,
|
|
|
|
language,
|
|
|
|
}: EventFromToTime) => {
|
2023-07-17 20:19:00 +00:00
|
|
|
const startDate = new Date(date);
|
|
|
|
const endDate = duration
|
|
|
|
? new Date(new Date(date).setMinutes(startDate.getMinutes() + duration))
|
|
|
|
: startDate;
|
|
|
|
|
|
|
|
const formattedDate = new Intl.DateTimeFormat(language, {
|
|
|
|
timeZone,
|
|
|
|
dateStyle: "full",
|
|
|
|
}).formatRange(startDate, endDate);
|
|
|
|
|
|
|
|
const formattedTime = new Intl.DateTimeFormat(language, {
|
|
|
|
timeZone,
|
|
|
|
timeStyle: "short",
|
|
|
|
hour12: timeFormat === TimeFormat.TWELVE_HOUR ? true : false,
|
|
|
|
})
|
|
|
|
.formatRange(startDate, endDate)
|
|
|
|
.toLowerCase();
|
2023-05-05 15:55:54 +00:00
|
|
|
|
|
|
|
return { date: formattedDate, time: formattedTime };
|
|
|
|
};
|
|
|
|
|
|
|
|
export const FromToTime = (props: EventFromToTime) => {
|
|
|
|
const formatted = formatEventFromToTime(props);
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{formatted.date}
|
|
|
|
<br />
|
|
|
|
{formatted.time}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|