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

set milliseconds to zero when handling time change in react-datepicker #1361

Merged
merged 2 commits into from
Dec 10, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

- Convert `EuiIcon` to TypeScript ([#1355](https://github.com/elastic/eui/pull/1355))

**Bug fixes**

- `react-datepicker` set milliseconds to zero when selecting time ([#1361](https://github.com/elastic/eui/pull/1361))

## [`5.5.1`](https://github.com/elastic/eui/tree/v5.5.1)

**Bug fixes**
Expand Down
18 changes: 13 additions & 5 deletions packages/react-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,10 @@ function safeDateFormat(date, _ref2) {
function setTime(date, _ref3) {
var hour = _ref3.hour,
minute = _ref3.minute,
second = _ref3.second;
second = _ref3.second,
millisecond = _ref3.millisecond;

date.set({ hour: hour, minute: minute, second: second });
date.set({ hour: hour, minute: minute, second: second, millisecond: millisecond });
return date;
}

Expand All @@ -801,6 +802,10 @@ function setYear(date, year) {

// ** Date Getters **

function getMillisecond(date) {
return get$1(date, "millisecond");
}

function getSecond(date) {
return get$1(date, "second");
}
Expand Down Expand Up @@ -2651,7 +2656,8 @@ var Time = function (_React$Component) {
var closestTime = setTime(newDate(), {
hour: Math.floor(closestMinutes / 60),
minute: closestMinutes % 60,
second: 0
second: 0,
millisecond: 0
});
this.setState({ preSelection: closestTime });
}
Expand Down Expand Up @@ -8240,7 +8246,8 @@ var DatePicker = function (_React$Component) {
changedDate = setTime(newDate(changedDate), {
hour: getHour(selected),
minute: getMinute(selected),
second: getSecond(selected)
second: getSecond(selected),
millisecond: getMillisecond(selected)
});
}
if (!_this.props.inline) {
Expand Down Expand Up @@ -8274,7 +8281,8 @@ var DatePicker = function (_React$Component) {
var changedDate = setTime(cloneDate(selected), {
hour: getHour(time),
minute: getMinute(time),
second: 0
second: 0,
millisecond: 0
});

_this.setState({
Expand Down
19 changes: 14 additions & 5 deletions packages/react-datepicker/docs-site/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26921,7 +26921,8 @@
changedDate = (0, _date_utils.setTime)((0, _date_utils.newDate)(changedDate), {
hour: (0, _date_utils.getHour)(selected),
minute: (0, _date_utils.getMinute)(selected),
second: (0, _date_utils.getSecond)(selected)
second: (0, _date_utils.getSecond)(selected),
millisecond: (0, _date_utils.getMillisecond)(selected)
});
}
if (!_this.props.inline) {
Expand Down Expand Up @@ -26955,7 +26956,8 @@
var changedDate = (0, _date_utils.setTime)((0, _date_utils.cloneDate)(selected), {
hour: (0, _date_utils.getHour)(time),
minute: (0, _date_utils.getMinute)(time),
second: 0
second: 0,
millisecond: 0
});

_this.setState({
Expand Down Expand Up @@ -29869,6 +29871,7 @@
exports.setMonth = setMonth;
exports.setYear = setYear;
exports.setUTCOffset = setUTCOffset;
exports.getMillisecond = getMillisecond;
exports.getSecond = getSecond;
exports.getMinute = getMinute;
exports.getHour = getHour;
Expand Down Expand Up @@ -30029,9 +30032,10 @@
function setTime(date, _ref3) {
var hour = _ref3.hour,
minute = _ref3.minute,
second = _ref3.second;
second = _ref3.second,
millisecond = _ref3.millisecond;

date.set({ hour: hour, minute: minute, second: second });
date.set({ hour: hour, minute: minute, second: second, millisecond: millisecond });
return date;
}

Expand All @@ -30049,6 +30053,10 @@

// ** Date Getters **

function getMillisecond(date) {
return get(date, "millisecond");
}

function getSecond(date) {
return get(date, "second");
}
Expand Down Expand Up @@ -48724,7 +48732,8 @@
var closestTime = (0, _date_utils.setTime)((0, _date_utils.newDate)(), {
hour: Math.floor(closestMinutes / 60),
minute: closestMinutes % 60,
second: 0
second: 0,
millisecond: 0
});
this.setState({ preSelection: closestTime });
}
Expand Down
8 changes: 6 additions & 2 deletions packages/react-datepicker/src/date_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export function safeDateFormat(date, { dateFormat, locale }) {

// ** Date Setters **

export function setTime(date, { hour, minute, second }) {
date.set({ hour, minute, second });
export function setTime(date, { hour, minute, second, millisecond }) {
date.set({ hour, minute, second, millisecond });
return date;
}

Expand All @@ -116,6 +116,10 @@ export function setUTCOffset(date, offset) {

// ** Date Getters **

export function getMillisecond(date) {
return get(date, "millisecond");
}

export function getSecond(date) {
return get(date, "second");
}
Expand Down
7 changes: 5 additions & 2 deletions packages/react-datepicker/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isAfter,
equals,
setTime,
getMillisecond,
getSecond,
getMinute,
getHour,
Expand Down Expand Up @@ -443,7 +444,8 @@ export default class DatePicker extends React.Component {
changedDate = setTime(newDate(changedDate), {
hour: getHour(selected),
minute: getMinute(selected),
second: getSecond(selected)
second: getSecond(selected),
millisecond: getMillisecond(selected),
});
}
if (!this.props.inline) {
Expand Down Expand Up @@ -484,7 +486,8 @@ export default class DatePicker extends React.Component {
const changedDate = setTime(cloneDate(selected), {
hour: getHour(time),
minute: getMinute(time),
second: 0
second: 0,
millisecond: 0,
});

this.setState({
Expand Down
7 changes: 5 additions & 2 deletions packages/react-datepicker/src/time.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export default class Time extends React.Component {
const closestTime = setTime(newDate(), {
hour: Math.floor(closestMinutes / 60),
minute: closestMinutes % 60,
second: 0
second: 0,
millisecond: 0,
});
this.setState({ preSelection: closestTime });
}
Expand All @@ -107,7 +108,7 @@ export default class Time extends React.Component {
componentDidUpdate() {
// scroll to the preSelected time
const scrollToElement = this.preselectedLi;

if (scrollToElement) {
// an element matches the selected time, scroll to it
scrollToElement.scrollIntoView({
Expand Down Expand Up @@ -164,6 +165,8 @@ export default class Time extends React.Component {
return;
}



this.props.onChange(time);
};

Expand Down
1 change: 1 addition & 0 deletions src-docs/src/views/date_picker/time_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class extends Component {
showTimeSelect
selected={this.state.startDate}
onChange={this.handleChange}
dateFormat="MM/DD/YYYY HH:mm.ss.SSS"
/>
</EuiFormRow>

Expand Down