Set default hours method is incorrect when min or max date exist in config
Environment
- flatpickr version used:
4.5.0 - Browser name and version:
Google Chrome 66 - OS and version:
macOS High Sierra 10.13.4
This is a follow up of bug ticket #1370
With v4.5.0, default hours is incorrectly calculated when minDate or maxDate are configured.
The issue was introduced with commit 69eea6f82a87254df09ad16c307d42911a74a9d6. The new setDefaultHours method is incorrect as it always calculates the hours/minutes as:
- the maximum between
minDatetime and default time - the minimum between
maxDatetime and default time
...but should only do so if the date of minDate is equal to the date selected or the date of maxDate is equal to the date selected.
Setup
Flatpickr instance configured with options defaultHour, defaultMinute and maxDate.
maxDate set to a date far in the future and its time set to 00:00:00 to make the bug more evident.
defaultHour: 8,
defaultMinute: 43,
maxDate: new Date('2020-01-01T00:00:00'),Pick today's date (which is thus before the maxDate).
Expected
Default hour and default minute values appear in the time picker section: 08:43:00.
Observed
Min date hour, minute and second values appear in the time picker section: 00:00:00
Reproduction
Source: flatpickr/flatpickr