diff --git a/.size-snapshot.json b/.size-snapshot.json index 106af6dd2..95eac0f5e 100644 --- a/.size-snapshot.json +++ b/.size-snapshot.json @@ -1,18 +1,18 @@ { "./dist/react-big-calendar.js": { - "bundled": 546245, - "minified": 168830, - "gzipped": 51923 + "bundled": 547318, + "minified": 169022, + "gzipped": 51994 }, "./dist/react-big-calendar.min.js": { - "bundled": 474113, - "minified": 146999, - "gzipped": 46091 + "bundled": 475186, + "minified": 147191, + "gzipped": 46160 }, "dist/react-big-calendar.esm.js": { - "bundled": 227148, - "minified": 102549, - "gzipped": 25488, + "bundled": 228177, + "minified": 102819, + "gzipped": 25562, "treeshaked": { "rollup": { "code": 64942, diff --git a/package.json b/package.json index ff0931a80..f8f2c0812 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rbc-fork-react-big-calendar", - "version": "0.33.30", + "version": "0.33.40", "description": "Calendar! with events", "author": { "name": "Jason Quense", diff --git a/src/localizer.js b/src/localizer.js index 1f9e503f1..1f3d7cebf 100644 --- a/src/localizer.js +++ b/src/localizer.js @@ -26,6 +26,7 @@ import { } from './utils/dates' const localePropType = PropTypes.oneOfType([PropTypes.string, PropTypes.func]) +const MILLI_SECOND_IN_24_HOURS = 24 * 60 * 60 * 1000; // 24 hours * 60 minutes * 60 seconds * 1000 milliseconds function _format(localizer, formatter, value, format, culture) { let result = @@ -92,6 +93,10 @@ function continuesAfter(start, end, last) { : gt(end, last, 'minutes') } +function areDatesMoreThan24HoursApart(date1, date2) { + return Math.abs(date1.getTime() - date2.getTime()) >= MILLI_SECOND_IN_24_HOURS; +} + // These two are used by eventLevels function sortEvents({ evtA: { start: aStart, end: aEnd, allDay: aAllDay }, @@ -107,9 +112,28 @@ function sortEvents({ // same day if (aAllDay && !bAllDay) { return -1; // All-day event a goes before non-all-day event b - } else if (!aAllDay && bAllDay) { + } + + if (!aAllDay && bAllDay) { return 1; // Non-all-day event a goes after all-day event b } + if (durB - durA) { // zero would not enter this if statement + // multi-day event + const eventAIsMoreThan24Hours = areDatesMoreThan24HoursApart(aEnd, aStart) + const eventBIsMoreThan24Hours = areDatesMoreThan24HoursApart(bEnd, bStart) + if (eventAIsMoreThan24Hours && !eventBIsMoreThan24Hours) { + return -1; // Multi-day event a goes before single-day event b + } + if (!eventAIsMoreThan24Hours && eventBIsMoreThan24Hours) { + return 1; // Multi-day event a goes before single-day event b + } + if (!eventAIsMoreThan24Hours && !eventBIsMoreThan24Hours) { + // both under 24 hours -> check time + return +aStart - +bStart || // then sort by start time + +aEnd - +bEnd // then sort by end time + } + } + return ( durB - durA || // events spanning multiple days go first +aStart - +bStart || // then sort by start time