Skip to content

Commit

Permalink
Merge pull request jdewit#10 from koenpunt/tweaks
Browse files Browse the repository at this point in the history
Trigger change() of element on value update, fixed issue where time was not shown in 24-hour format
  • Loading branch information
jdewit committed May 29, 2012
2 parents 3b405eb + af8619f commit 496d1c1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions js/bootstrap-timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
if (match) {
meridian = match[1];
}
// .split(/^([0-9]+):([0-9]+) (AM|PM)$/)
time = $.trim(time.replace(/(PM|AM)/i, ''));
var timeArray = time.split(':');

Expand All @@ -131,20 +132,22 @@
var dTime = new Date();
var hours = dTime.getHours();
var minutes = Math.floor(dTime.getMinutes() / this.minuteStep) * this.minuteStep;

var meridian = "AM";
if (hours === 0) {
hours = 12;
} else if (hours > 12) {
hours = hours - 12;
meridian = "PM";
} else {
meridian = "AM";
if ( this.showMeridian ) {
if (hours === 0) {
hours = 12;
} else if (hours > 12) {
hours = hours - 12;
meridian = "PM";
} else {
meridian = "AM";
}
}

this.hour = hours;
this.minute = minutes;
this.meridian = meridian;
} else if (defaultTime === 'value') {
this.setValues( this.$element.val() );
} else {
this.setValues(defaultTime);
}
Expand Down Expand Up @@ -174,7 +177,7 @@
, updateElement: function() {
var time = this.getTime();

this.$element.val(time);
this.$element.val(time).change();
}

, updateWidget: function() {
Expand Down

0 comments on commit 496d1c1

Please sign in to comment.