Skip to content

Commit

Permalink
feat: added overnight event identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
syam babu committed Jan 8, 2025
1 parent e215a23 commit 3214af2
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/utils/dateRangeFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,41 @@ export function dateRangeFormatter(startdate, enddate, scheduleTimezone = 'Canad
: startDateTimeObj.format('DD MMM YYYY');

if (!noEndDateFlag) {
// Check if the startdate has a time component by checking the format
// Check if the enddate has a time component by checking the format
const hasEndTime = enddate.includes('T') || enddate.includes(' ');
let endDateObj = hasEndTime ? dayjs.utc(enddate).tz(scheduleTimezone) : dayjs(enddate);

if (!endDateObj.isValid()) {
return 'Invalid end date format';
}

// Check if enddate is within 24 hours of startDateTimeObj
const diffInHours = endDateObj.diff(startDateTimeObj, 'hour');
const formattedStartDateTime = startDateTimeObj.format(dateTimeFormat);
const formattedEndDate = endDateObj.format('DD MMM YYYY');

if (diffInHours <= 24) {
const formattedEndTime = endDateObj.format('hh:mm A');

return formattedEndTime ? (
<>
{formattedStartDateTime.toUpperCase()} - {formattedEndTime}
{<sup style={{ fontSize: 'smaller' }}>+1</sup>}
</>
) : (
formattedStartDateTime.toUpperCase()
);
}

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

// if (startDateTimeObj.isSame(endDateObj, 'minute')) {
return formattedStartDateTime.toUpperCase();
// }

// return (
// <>
// {formattedStartDateTime.toUpperCase()} <Translation>{(t) => t('to')}</Translation>{' '}
// {formattedEndTime.toUpperCase()}
// </>
// );
}

const formattedEndDate = endDateObj.format('DD MMM YYYY');
if (formattedEndDate.toUpperCase() === formattedStartDate.toUpperCase()) {
return formattedStartDate.toUpperCase();
}

return (
<>
{formattedStartDate.toUpperCase()} <Translation>{(t) => t('to')}</Translation>{' '}
Expand Down

0 comments on commit 3214af2

Please sign in to comment.