Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UICAL-132: Calendar hours displaying on wrong day of week #318

Merged
merged 1 commit into from
Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Update to stripes v6. Refs UICAL-128.
* Move moment from a regular to a peer and dev dependencies. Refs UICAL-122.
* Increment `@folio/stripes-cli` to `v2`. Refs UICAL-131.
* Calendar hours displaying on wrong day of week (offset by a day). Refs UICAL-132.

## [5.0.0](https://github.com/folio-org/ui-calendar/tree/v5.0.0) (2020-10-08)
[Full Changelog](https://github.com/folio-org/ui-calendar/compare/v4.0.0...v5.0.0)
Expand Down
34 changes: 5 additions & 29 deletions src/settings/OpenExceptionalForm/ExceptionalBigCalendar.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React, { Component } from 'react';
import moment from 'moment';
import PropTypes from 'prop-types';
import {
reduce,
cloneDeep,
} from 'lodash';
import {
Calendar,
momentLocalizer,
Expand All @@ -18,31 +14,11 @@ class ExceptionalBigCalendar extends Component {
getEvent: PropTypes.func.isRequired,
};

/* *
* Fix for https://github.com/intljusticemission/react-big-calendar/issues/118
* */
getEvents = () => {
const { myEvents } = this.props;

const localPcTimezoneOffset = (new Date().getTimezoneOffset()) / 60;

return reduce(myEvents, (events, event) => {
const transformedEvent = cloneDeep(event);

if (transformedEvent.end) {
transformedEvent.end.add(localPcTimezoneOffset, 'h');
}

if (transformedEvent.start) {
transformedEvent.start.add(localPcTimezoneOffset, 'h');
}

return [...events, transformedEvent];
}, []);
};

render() {
const { getEvent } = this.props;
const {
myEvents,
getEvent,
} = this.props;

return (
<Calendar
Expand All @@ -51,7 +27,7 @@ class ExceptionalBigCalendar extends Component {
popup
toolbar
showMultiDayTimes
events={this.getEvents()}
events={myEvents}
views={['month']}
onSelectEvent={getEvent}
style={{ height: '90vh' }}
Expand Down