Files
calendar/packages/features/bookings/Booker/utils/dates.tsx
T
e2ef8d2dc8 fix: correct language is used when booking with a modal + location icon visible in booker when using light mode (#14280)
* fix small frontend issues with Booker

This commit fixes the following:
- The "location" icon is now visible in light move when using the "in person (Organizer Address)" option

- The language in which the date and length is shown in modals now corresponds to the language of the creator of the calendar (before this is was always in english)

- If the text is too large for the modal, they will adapt into a collumn

-

* correct small mistakes

* chore: getDurationFormatted

---------

Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: Udit Takkar <udit222001@gmail.com>
2024-04-10 21:45:55 +00:00

83 lines
1.9 KiB
TypeScript

import { TimeFormat } from "@calcom/lib/timeFormat";
interface EventFromToTime {
date: string;
duration: number | null;
timeFormat: TimeFormat;
timeZone: string;
language: string;
}
interface EventFromTime {
date: string;
timeFormat: TimeFormat;
timeZone: string;
language: string;
}
export const formatEventFromTime = ({ date, timeFormat, timeZone, language }: EventFromTime) => {
const startDate = new Date(date);
const formattedDate = new Intl.DateTimeFormat(language, {
timeZone,
dateStyle: "full",
}).format(startDate);
const formattedTime = new Intl.DateTimeFormat(language, {
timeZone,
timeStyle: "short",
hour12: timeFormat === TimeFormat.TWELVE_HOUR ? true : false,
})
.format(startDate)
.toLowerCase();
return { date: formattedDate, time: formattedTime };
};
export const formatEventFromToTime = ({
date,
duration,
timeFormat,
timeZone,
language,
}: EventFromToTime) => {
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();
return { date: formattedDate, time: formattedTime };
};
export const FromToTime = (props: EventFromToTime) => {
const formatted = formatEventFromToTime(props);
return (
<>
{formatted.date}
<br />
{formatted.time}
</>
);
};
export const FromTime = (props: EventFromTime) => {
const formatted = formatEventFromTime(props);
return (
<>
{formatted.date}, {formatted.time}
</>
);
};