1 import { format } from 'date-fns';
3 import { VIEWS } from '@proton/shared/lib/calendar/constants';
4 import { dateLocale } from '@proton/shared/lib/i18n';
6 const { DAY, WEEK, MONTH, YEAR, AGENDA, CUSTOM, MAIL, DRIVE, SEARCH } = VIEWS;
13 [AGENDA]: 'MMMM yyyy',
20 const getDateRangeText = (view: VIEWS, range: number, currentDate: Date, dateRange: Date[]) => {
21 const formatOptions = { locale: dateLocale };
22 const [from, to] = dateRange;
24 if (view === WEEK || range > 0) {
25 if (from.getMonth() === to.getMonth()) {
26 const rest = format(from, 'MMMM yyyy', formatOptions);
30 if (from.getFullYear() === to.getFullYear()) {
31 const fromString = format(from, 'MMM', formatOptions);
32 const toString = format(to, 'MMM', formatOptions);
33 const rest = format(from, 'yyyy', formatOptions);
34 return `${fromString} – ${toString} ${rest}`;
37 const fromString = format(from, 'MMM yyyy', formatOptions);
38 const toString = format(to, 'MMM yyyy', formatOptions);
39 return `${fromString} – ${toString}`;
42 return format(currentDate, FORMATS[view], formatOptions);
45 export default getDateRangeText;