source: src/components/custom-date-range-picker/utils.ts@ 5d6f37a

main
Last change on this file since 5d6f37a was 5d6f37a, checked in by Naum Shapkarovski <naumshapkarovski@…>, 7 weeks ago

add customer

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import { isSameDay, isSameMonth, getYear } from 'date-fns';
2// utils
3import { fDate } from 'src/utils/format-time';
4
5// ----------------------------------------------------------------------
6
7export function shortDateLabel(startDate: Date | null, endDate: Date | null) {
8 const getCurrentYear = new Date().getFullYear();
9
10 const startDateYear = startDate ? getYear(startDate) : null;
11
12 const endDateYear = endDate ? getYear(endDate) : null;
13
14 const currentYear = getCurrentYear === startDateYear && getCurrentYear === endDateYear;
15
16 const sameDay = startDate && endDate ? isSameDay(new Date(startDate), new Date(endDate)) : false;
17
18 const sameMonth =
19 startDate && endDate ? isSameMonth(new Date(startDate), new Date(endDate)) : false;
20
21 if (currentYear) {
22 if (sameMonth) {
23 if (sameDay) {
24 return fDate(endDate, 'dd MMM yy');
25 }
26 return `${fDate(startDate, 'dd')} - ${fDate(endDate, 'dd MMM yy')}`;
27 }
28 return `${fDate(startDate, 'dd MMM')} - ${fDate(endDate, 'dd MMM yy')}`;
29 }
30
31 return `${fDate(startDate, 'dd MMM yy')} - ${fDate(endDate, 'dd MMM yy')}`;
32}
Note: See TracBrowser for help on using the repository browser.