Skip to content

Commit

Permalink
fix: added date handling for single date overnight events. closes #1182
Browse files Browse the repository at this point in the history
  • Loading branch information
syam babu committed Sep 24, 2024
1 parent 5e1347d commit 517857a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/utils/dateTimeTypeHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ import { dateTypes } from '../constants/dateTypes';

export const dateTimeTypeHandler = (startDate, startDateTime, endDate, endDateTime, isRecurring) => {
if (isRecurring) return dateTypes.MULTIPLE;
else if ((startDate || startDateTime) && !endDate && !endDateTime) return dateTypes.SINGLE;
else if ((startDate || startDateTime) && endDateTime && !endDate) {
if (startDate && moment(startDate).isSame(endDateTime, 'day')) return dateTypes.SINGLE;
else if (startDate && !moment(startDate).isSame(endDateTime, 'day')) return dateTypes.RANGE;
else if (startDateTime && moment(startDateTime).isSame(endDateTime, 'day')) return dateTypes.SINGLE;
else if (startDateTime && !moment(startDateTime).isSame(endDateTime, 'day')) return dateTypes.RANGE;
} else if ((startDate || startDateTime) && !endDateTime && endDate) return dateTypes.RANGE;

const start = startDateTime || startDate;
const end = endDateTime || endDate;

// only start is provided
if (start && !end) return dateTypes.SINGLE;

// if both start and end are present
if (start && end) {
// If start and end are the same day, or within 24 hours
if (moment(start).isSame(end, 'day') || moment(end).diff(moment(start), 'hours') < 24) return dateTypes.SINGLE;

return dateTypes.RANGE;
}
};

0 comments on commit 517857a

Please sign in to comment.