question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Min validation issue when using 24 format

See original GitHub issue

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:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Agranomcommented, Apr 24, 2019

Fixed. Update to v3.0.3

1reaction
Agranomcommented, Apr 17, 2019

I see. I’ll fix it and let you know

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to validate time in 24-hour format using Regular Expression
Explanation: The given string doesn't be in the range of 00 to 59(i.e., minute is out of range), therefore it is not a...
Read more >
4.6. Validate Traditional Time Formats - Regular Expressions ...
You want to validate times in various traditional time formats, such as hh:mm and hh:mm:ss in both 12-hour and 24-hour formats. Solution. Hours...
Read more >
Php validating 24 hour time format - Stack Overflow
I found some regex examples but the 24 hour time I'm validating is always set to 00 for minutes and seconds. Only the...
Read more >
Validate Time in 24 Hours , Minutes format with regular ...
Validate Time in 24 Hours - Minutes format with regular expression,NO NAME 0053.
Read more >
<input type="time"> - HTML: HyperText Markup Language | MDN
In Chrome/Opera the time control is simple, with slots to enter hours and minutes in 12 or 24-hour format depending on operating system ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found