Skip to content

Commit

Permalink
fix: fixed time formatting for french dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
syam babu committed Sep 30, 2024
1 parent 1bd7995 commit 3ce989d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils/dateRangeFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
import { Translation } from 'react-i18next';
import i18next from 'i18next';

dayjs.extend(utc);
dayjs.extend(timezone);
Expand All @@ -19,6 +20,9 @@ export function dateRangeFormatter(startdate, enddate, scheduleTimezone = 'Canad
// Check if the startdate has a time component by checking the format
const hasStartTime = startdate.includes('T') || startdate.includes(' ');
const isStartAndEndDaySame = isSameDay(startdate, enddate);
const locale = i18next.language;

const dateTimeFormat = locale === 'fr' ? 'DD MMM YYYY - HH:mm' : 'DD MMM YYYY - h:mm a';

const startDateTimeObj = hasStartTime
? dayjs.utc(startdate).tz(scheduleTimezone)
Expand All @@ -32,7 +36,7 @@ export function dateRangeFormatter(startdate, enddate, scheduleTimezone = 'Canad
// Format start date based on whether it has a time component
const formattedStartDate = noEndDateFlag
? hasStartTime
? startDateTimeObj.format('DD MMM YYYY - h:mm a')
? startDateTimeObj.format(dateTimeFormat)
: startDateTimeObj.format('DD MMM YYYY')
: startDateTimeObj.format('DD MMM YYYY');

Expand All @@ -46,7 +50,7 @@ export function dateRangeFormatter(startdate, enddate, scheduleTimezone = 'Canad

// Check if startdate and enddate are on the same day
if (isStartAndEndDaySame) {
const formattedStartDateTime = startDateTimeObj.format('DD MMM YYYY - h:mm a');
const formattedStartDateTime = startDateTimeObj.format(dateTimeFormat);
// const formattedEndTime = endDateObj.format('h:mm a');

// if (startDateTimeObj.isSame(endDateObj, 'minute')) {
Expand Down

0 comments on commit 3ce989d

Please sign in to comment.