diff --git a/CHANGELOG.md b/CHANGELOG.md index 93a1cc83..bf5088c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change history for ui-calendar +## [7.0.1] (https://github.com/folio-org/ui-calendar/tree/v7.0.1) (2021-11-11) +[Full Changelog](https://github.com/folio-org/ui-calendar/compare/v7.0.0...v7.0.1) + +* Fix long exception periods display wrong days and subsequent exception periods display on the wrong days. Refs UICAL-175. + ## [7.0.0] (https://github.com/folio-org/ui-calendar/tree/v7.0.0) (2021-09-30) [Full Changelog](https://github.com/folio-org/ui-calendar/compare/v6.1.2...v7.0.0) diff --git a/package.json b/package.json index d42b79ab..8226e1be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@folio/calendar", - "version": "7.0.0", + "version": "7.0.1", "description": "Opening hours", "repository": "folio-org/ui-calendar", "publishConfig": { diff --git a/src/settings/OpenExceptionalForm/ExceptionWrapper.js b/src/settings/OpenExceptionalForm/ExceptionWrapper.js index 5b1a56ec..d8ad840e 100644 --- a/src/settings/OpenExceptionalForm/ExceptionWrapper.js +++ b/src/settings/OpenExceptionalForm/ExceptionWrapper.js @@ -30,9 +30,7 @@ import { ALL_DAY, } from '../constants'; -import { - OFFSET_HOURS, -} from '../utils/time'; +import { setTimezoneOffset } from '../utils/time'; class ExceptionWrapper extends Component { static propTypes = { @@ -366,9 +364,8 @@ class ExceptionWrapper extends Component { for (let i = 0; i < moment(end) .diff(moment(start), 'days') + 1; i++) { - const today = moment(start) + const today = setTimezoneOffset(start) .add(i, 'days') - .add(OFFSET_HOURS, 'hours') .format('dddd') .toUpperCase(); @@ -460,10 +457,11 @@ class ExceptionWrapper extends Component { {eventContent} ; + const eventStart = setTimezoneOffset(start).add(i, 'days'); const tempObj = { id, - end: moment(start).add(i, 'days'), - start: moment(start).add(i, 'days'), + end: eventStart.clone(), + start: eventStart, title: eventTitle, exceptional, }; diff --git a/src/settings/OpenExceptionalForm/ExceptionalBigCalendar.js b/src/settings/OpenExceptionalForm/ExceptionalBigCalendar.js index c76041ce..cf3c0515 100644 --- a/src/settings/OpenExceptionalForm/ExceptionalBigCalendar.js +++ b/src/settings/OpenExceptionalForm/ExceptionalBigCalendar.js @@ -6,10 +6,6 @@ import { momentLocalizer, } from 'react-big-calendar'; -import { - OFFSET_HOURS, -} from '../utils/time'; - const localizer = momentLocalizer(moment); class ExceptionalBigCalendar extends Component { @@ -18,10 +14,6 @@ class ExceptionalBigCalendar extends Component { getEvent: PropTypes.func.isRequired, }; - accessor = (date) => { - return moment(date).clone().add(OFFSET_HOURS, 'hours').toDate(); - } - render() { const { myEvents, @@ -39,8 +31,6 @@ class ExceptionalBigCalendar extends Component { views={['month']} onSelectEvent={getEvent} style={{ height: '90vh' }} - startAccessor={(event) => this.accessor(event.start)} - endAccessor={(event) => this.accessor(event.end)} /> ); } diff --git a/src/settings/utils/time.js b/src/settings/utils/time.js index 484a7797..4965fa60 100644 --- a/src/settings/utils/time.js +++ b/src/settings/utils/time.js @@ -1,2 +1,9 @@ +import moment from 'moment'; + // eslint-disable-next-line import/prefer-default-export -export const OFFSET_HOURS = (new Date().getTimezoneOffset()) / 60; +export const setTimezoneOffset = (date) => { + const momentDate = moment(date); + const utcOffset = -(momentDate.utcOffset() / 60); + + return momentDate.add(utcOffset, 'hours'); +};