Min validation issue when using 24 format
See original GitHub issueIssue Description
Great work on the component. However, I’m having problem using it with 24 format at the moment due to the following behavior.
Consider the following case: Format: 24 min: 11:40 am setting value 12:40 (not stating am/pm as this is 24format) Expected behavior: set value without error current behavior: ‘Selected time doesn’t match min or max value’
In my opinion this is what is going on
setting the value in ngx-timepicker.directive.ts:
const time = TimeAdapter.formatTime(value, this._format);
if (TimeAdapter.isTimeAvailable(time, <DateTime>this._min, <DateTime>this._max, 'minutes', this._timepicker.minutesGap)) {
leads to time evaluating to ‘12:40’ and in the isTimeAvailable function:
const convertedTime = this.convertTimeToDateTime(time);
The convertTimeToDateTime function is using format 12 by default.
static convertTimeToDateTime(time: string, format = 12): DateTime {
const timeMask = (format === 24) ? TimeFormat.TWENTY_FOUR_SHORT : TimeFormat.TWELVE_SHORT;
return DateTime.fromFormat(this.parseTime(time, format), timeMask); }
which means that parseTime will be called with parameters ‘12:40’, 12
leading to isPM ending with the wrong value:
const isPM = +h > 12;
h is 12, m is 40, 12:40 is pm, however isPM will be false and parseTime will return ‘12:40 AM’
If I’m not mistaken luxon parses this as 00:40 AM.
00:40 AM is less than 11:40 so the timepicker is complaining.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Fixed. Update to v3.0.3
I see. I’ll fix it and let you know