clockpicker icon indicating copy to clipboard operation
clockpicker copied to clipboard

Picker does not work with type="time" inputs when twelvehour=true

Open cepm-nate opened this issue 10 years ago • 5 comments

When the option "twelvehour" = true, the text "AM"/"PM" is added to the output string.

This is great for TEXT inputs, but does not work for TIME inputs. TIME inputs expect a value in the format of HH:MM:SS.

The easiest way to account for this is down in the "ClockPicker.prototype.done" function:

  1. Only do the following steps if the TYPE of the input is "time".
  2. Increment the hours+12 if this.amOrPm==="PM".
  3. Do not include the "AM"/"PM" in the final output string.
  4. Append ":00" (Zero seconds) to the output string.

cepm-nate avatar Jan 21 '15 17:01 cepm-nate

The line to determine am/pm doesn't work. I changed it to this and it works fine: this.amOrPm = this.hours > 12 || period === 'pm' ? 'PM' : 'AM';

johngreep avatar Jun 03 '15 18:06 johngreep

Even after I made the corrections above, we were still having problems if they picked 12. Did they mean noon or midnight?

And after reading this http://www.simplecodeworks.com/IQ/midnight.html, I decided to switch to the 24 hour clock.

Seriously, go read it! :-)

cepm-nate avatar Jun 03 '15 21:06 cepm-nate

This is the code that works for me, replacing https://github.com/weareoutman/clockpicker/blob/gh-pages/src/clockpicker.js#L679:

        if (this.options.twelvehour) {
            if (this.input.attr('type') === 'time') {
                var hoursInMilitary = (this.amOrPm === 'PM') ? this.hours + 12 : this.hours;
                value = leadingZero(hoursInMilitary) + ':' + leadingZero(this.minutes);
                value = value + ':00';
            }
            else {
                value = value + this.amOrPm;
            }
        }

mattcasey avatar Jun 05 '15 14:06 mattcasey

I have the same problem... I don't want to edit the source though... I'll just use type=text for now.

rain01 avatar Jun 12 '15 00:06 rain01

Puedes editar las siguientes lineas https://github.com/weareoutman/clockpicker/blob/gh-pages/src/clockpicker.js#L465

`       this.hours = +value[0] || 0;
        if (this.options.twelvehour) {
            this.minutes = +value[1].split(' ')[0] || 0;
            this.amOrPm = +value[1].split(' ')[1] || 'AM';
        } else {
            this.minutes = +value[1] || 0;
        }
        this.spanHours.html(leadingZero(this.hours));
        this.spanMinutes.html(leadingZero(this.minutes));
        if (this.options.twelvehour) {
            this.spanAmPm.html(' ' + this.amOrPm);
        }

`

pok81694 avatar Dec 27 '16 23:12 pok81694