Skip to content

Commit d1fce82

Browse files
committed
Fix min/max values not properly applied to HourInput, MinuteInput, SecondInput
Fixes #31
1 parent 8906237 commit d1fce82

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/DateTimeInput.jsx

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
getMonth,
2222
getSeconds,
2323
getYear,
24+
getHoursMinutesSeconds,
2425
convert12to24,
2526
convert24to12,
2627
} from './shared/dates';
@@ -179,7 +180,48 @@ export default class DateTimeInput extends PureComponent {
179180
);
180181
}
181182

183+
get maxTime() {
184+
const { maxDate } = this.props;
185+
186+
if (!maxDate) {
187+
return null;
188+
}
189+
190+
const { year, month, day } = this.state;
191+
192+
if (
193+
getYear(maxDate) !== year
194+
|| getMonth(maxDate) !== month
195+
|| getDay(maxDate) !== day
196+
) {
197+
return null;
198+
}
199+
200+
return getHoursMinutesSeconds(maxDate);
201+
}
202+
203+
get minTime() {
204+
const { minDate } = this.props;
205+
206+
if (!minDate) {
207+
return null;
208+
}
209+
210+
const { year, month, day } = this.state;
211+
212+
if (
213+
getYear(minDate) !== year
214+
|| getMonth(minDate) !== month
215+
|| getDay(minDate) !== day
216+
) {
217+
return null;
218+
}
219+
220+
return getHoursMinutesSeconds(minDate);
221+
}
222+
182223
get commonInputProps() {
224+
const { maxTime, minTime } = this;
183225
const {
184226
disabled,
185227
isWidgetOpen,
@@ -192,7 +234,9 @@ export default class DateTimeInput extends PureComponent {
192234
className,
193235
disabled,
194236
maxDate: maxDate || defaultMaxDate,
237+
maxTime,
195238
minDate: minDate || defaultMinDate,
239+
minTime,
196240
onChange: this.onChange,
197241
onKeyDown: this.onKeyDown,
198242
placeholder: '--',
@@ -438,12 +482,13 @@ export default class DateTimeInput extends PureComponent {
438482
return null;
439483
}
440484

441-
const { minute } = this.state;
485+
const { hour, minute } = this.state;
442486

443487
return (
444488
<MinuteInput
445489
key="minute"
446490
{...this.commonInputProps}
491+
hour={hour}
447492
maxDetail={maxDetail}
448493
value={minute}
449494
/>
@@ -458,13 +503,15 @@ export default class DateTimeInput extends PureComponent {
458503
return null;
459504
}
460505

461-
const { second } = this.state;
506+
const { hour, minute, second } = this.state;
462507

463508
return (
464509
<SecondInput
465510
key="second"
466511
{...this.commonInputProps}
512+
hour={hour}
467513
maxDetail={maxDetail}
514+
minute={minute}
468515
value={second}
469516
/>
470517
);

src/shared/dates.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export {
2121

2222
export {
2323
getISOLocalDate,
24+
getHoursMinutesSeconds,
2425
};
2526

2627
// eslint-disable-next-line import/prefer-default-export

0 commit comments

Comments
 (0)