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

Ensure components return Date objects with 00:00:00 time #57

Merged
merged 1 commit into from
Jul 19, 2018
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
8 changes: 5 additions & 3 deletions src/client/components/DateInput/DateInput.DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Allows select date using mouse or keyboard.

Based on configured to OpusCapita defaults [react-day-picker](https://github.com/gpbl/react-day-picker)

**Important:** `DatePicker` returns `Date` object with 00:00:00 time.

### Props Reference

| Name | Type | Description |
Expand All @@ -29,7 +31,7 @@ Based on configured to OpusCapita defaults [react-day-picker](https://github.com
value={_scope.state.value}
dateFormat="dd/MM/yyyy"
locale="de"
onChange={_scope.handleChange.bind(_scope)}
onChange={_scope.handleChange}
/>

<hr />
Expand All @@ -39,7 +41,7 @@ Based on configured to OpusCapita defaults [react-day-picker](https://github.com
dateFormat="dd/MM/yyyy"
disabled={true}
locale="en"
onChange={_scope.handleChange.bind(_scope)}
onChange={_scope.handleChange}
/>

<hr />
Expand All @@ -49,7 +51,7 @@ Based on configured to OpusCapita defaults [react-day-picker](https://github.com
dateFormat="dd/MM/yyyy"
locale="fi"
onBlur={(e) => console.log('Blur!', e)}
onChange={_scope.handleChange.bind(_scope)}
onChange={_scope.handleChange}
onFocus={(e) => console.log('Focus!', e)}
showToLeft={true}
showToTop={true}
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/DateInput/DateInput.SCOPE.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DateInputScope extends Component {
};
}

handleChange(value) {
handleChange = (value) => {
this.setState({ value });
}

Expand Down
4 changes: 2 additions & 2 deletions src/client/components/DateInput/DateInput.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dayjs from '../../dayjs';
import getMessage from '../translations';
import isEqual from 'lodash/isEqual';
import { Portal } from 'react-portal';
import { getCoords, splitProps } from '../utils';
import { getCoords, splitProps, zeroTime } from '../utils';

let springPreset = presets.gentle;
let easeOutCubic = (t) => (--t) * t * t + 1; // eslint-disable-line no-param-reassign
Expand Down Expand Up @@ -170,7 +170,7 @@ class DateInput extends Component {
};

handleDateChange = value => {
this.props.onChange(value);
this.props.onChange(zeroTime(value));
this.setState({ error: null });
};

Expand Down
2 changes: 2 additions & 0 deletions src/client/components/DatePicker/DatePicker.DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ DatePicker shows the calendar button. When you click it, calendar appears. Allow

Based on configured to OpusCapita defaults [react-day-picker](https://github.com/gpbl/react-day-picker)

**Important:** `DatePicker` returns `Date` object with 00:00:00 time.

### Props Reference

| Name | Type | Description |
Expand Down
4 changes: 2 additions & 2 deletions src/client/components/DatePicker/DatePicker.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DayPicker from '../DayPicker';
import { spring, presets, Motion } from 'react-motion';
import isEqual from 'lodash/isEqual';
import { Portal } from 'react-portal';
import { getCoords, splitProps } from '../utils';
import { getCoords, splitProps, zeroTime } from '../utils';

let springPreset = presets.gentle;
let easeOutCubic = (t) => (--t) * t * t + 1; // eslint-disable-line no-param-reassign
Expand Down Expand Up @@ -82,7 +82,7 @@ class DatePicker extends Component {
};

handleDateChange = value => {
this.props.onChange(value);
this.props.onChange(zeroTime(value));
};

handleBodyClick = event => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Allows select date range using mouse.

**Important:** `DatePicker` returns `Date` object with 00:00:00 time.

### Props Reference

| Name | Type | Description |
Expand Down
6 changes: 4 additions & 2 deletions src/client/components/DateRangeInput/DateRangeInput.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dayjs from '../../dayjs';
import { spring, presets, Motion } from 'react-motion';
import getMessage from '../translations';
import { Portal } from 'react-portal';
import { getCoords, splitProps } from '../utils';
import { getCoords, splitProps, zeroTime } from '../utils';

let springPreset = presets.gentle;
let easeOutCubic = (t) => (--t) * t * t + 1; // eslint-disable-line no-param-reassign
Expand Down Expand Up @@ -186,7 +186,9 @@ class DateRangeInput extends Component {
this.props.onChange(normalizedRange);
};

handleDayClick = day => {
handleDayClick = dayValue => {
const day = zeroTime(dayValue);

let from = this.props.value[0];
let to = this.props.value[1];

Expand Down
7 changes: 4 additions & 3 deletions src/client/components/DayPicker/DayPicker.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ReactDayPicker from 'react-day-picker/lib/src/DayPicker';
import "react-day-picker/lib/style.css";
import localeUtils from '../../dayjs/reactDayPickerUtils';
import getMessage from '../translations';
import { splitProps } from '../utils';
import { splitProps, zeroTime } from '../utils';
import './DayPicker.less';

function Caption(props) {
Expand Down Expand Up @@ -107,7 +107,8 @@ class DayPicker extends Component {
};
}

handleDateChange = (date, captionIndex) => {
handleDateChange = (dateValue, captionIndex) => {
const date = zeroTime(dateValue);
if (this.props.isRange) {
let range = this.props.selectedDays[1];
let fromChanged = captionIndex === 0;
Expand All @@ -128,7 +129,7 @@ class DayPicker extends Component {
};

handleTodayClick = () => {
this.props.onChange(new Date());
this.props.onChange(zeroTime(new Date()));
};

render() {
Expand Down
7 changes: 7 additions & 0 deletions src/client/components/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ export const splitProps = (props, specificPropNames = []) => {
return [commonProps, specificProps];
}, [{}, {}]);
}

export const zeroTime = date => {
if (date instanceof Date) {
date.setHours(0, 0, 0);
}
return date;
}