7

I need to create a "from… to" time selection and created 2 TimePicker components for that. Because the database behind it already exists since years and uses a 24 hour format, in my code, I'm setting

tpOpenFrom.setIs24HourView(true);
tpOpenTo.setIs24HourView(true);

My problem now is that as it seems, "24:00" can't be selected as a "to:" value, as after "23"(:00), the component switches "back" to "00"(:00), making it impossible to find out whether the user forgot to make an actual selection, like if "09:00" has been entered as "from" time and "00:00" as "to" time. Or if a selection of "00:00" to "00:00" has been made: has the user forgotten to enter anything or did he intend to define "opened around the clock"?

In 24 hour mode, the TimePicker should really allow 24:00 to be entered. The 24-hour clock system in ISO 8601 defines midnight as a special case, than can be referred to as both "00:00" and "24:00", so TimePicker should allow the hours to be set to 24 and automatically block the minutes to 00.

Does anyone have an idea how to achieve that utilizing the TimePicker?

richey
  • 3,890
  • 9
  • 35
  • 49
  • running into an analogous problem myself; but it seems every TimePicker on the planet ignores the ISO8601 5.3.2 disambiguation of 'midnight'. As you say, 00:00 and 24:00 are both valid values in a Time-only data representation, per ISO. – Tim Feb 05 '13 at 13:07

1 Answers1

3

I had the same problems with a bootstrap timepicker but the is not difficult to implement. I am using the timepicker of Joris de Wit (http://jdewit.github.io/bootstrap-timepicker/).

search for "24" and replace all occurences with "25", then search for "23" in the bootstrap-timepicker.js and replace them with "24".

if you want to allow times like 24:01, .., 24:59, you're done. If you only want to accept 24:00 but not 24 with minutes, go to line 133 where the getTime function is.

Put the following code in front of the existing return (but don't delete it):

if (this.hour == 24 && this.minute != 0) {
  this.setTime('00:' + this.minute);
  return '00:' + this.minute;
}

This will convert any 24:XX time to 00:XX.

Alexander Uhl
  • 184
  • 3
  • 7