Skip to content

Commit

Permalink
Merge pull request #12 from mikeyyyzhao/mike/vim-2205-start-time-of-a…
Browse files Browse the repository at this point in the history
…n-event-isnt-correctly-slotted-in

fixed events under 24 hours but multi day
  • Loading branch information
mikeyyyzhao authored Feb 22, 2024
2 parents df8973f + bc10474 commit 970b525
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
18 changes: 9 additions & 9 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
26 changes: 25 additions & 1 deletion src/localizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 },
Expand All @@ -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
Expand Down

0 comments on commit 970b525

Please sign in to comment.