Skip to content

Commit d33549c

Browse files
author
Wojciech Maj
committed
Fix native input failing with minDate/maxDate specified with non-zero seconds
1 parent 7638303 commit d33549c

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/DateTimeInput/NativeInput.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import PropTypes from 'prop-types';
44
import { getISOLocalDateTime } from '../shared/dates';
55
import { isMaxDate, isMinDate, isValueType } from '../shared/propTypes';
66

7-
const nativeValueParser = getISOLocalDateTime;
8-
97
export default class NativeInput extends PureComponent {
108
get step() {
119
const { valueType } = this.props;
@@ -22,10 +20,25 @@ export default class NativeInput extends PureComponent {
2220
}
2321
}
2422

23+
get nativeValueParser() {
24+
const { valueType } = this.props;
25+
26+
switch (valueType) {
27+
case 'hour':
28+
return value => `${getISOLocalDateTime(value).slice(0, -6)}:00`;
29+
case 'minute':
30+
return value => getISOLocalDateTime(value).slice(0, -3);
31+
case 'second':
32+
return getISOLocalDateTime;
33+
default:
34+
throw new Error('Invalid valueType.');
35+
}
36+
}
37+
2538
stopPropagation = event => event.stopPropagation();
2639

2740
render() {
28-
const { step } = this;
41+
const { nativeValueParser, step } = this;
2942
const {
3043
disabled, maxDate, minDate, name, onChange, required, value,
3144
} = this.props;

0 commit comments

Comments
 (0)