Skip to content

Commit 085024c

Browse files
committed
Added support for a timeSeparator option
Looks like is working, can change ':' with dot '.'. For me is useful to integrate with java locales At line 766 don't know syntax to include separator dynamically in RegEx however there are only two separators in all java locales: ':' and '.'. Next step could be similar work for AM/PM symbol (eg: Arabic م Greek μμ) and (harder perhaps) AM/PM before or after time, in Chinese for example is before 下午9:21
1 parent 14986bf commit 085024c

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

js/bootstrap-timepicker.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
this.template = options.template;
3030
this.appendWidgetTo = options.appendWidgetTo;
3131
this.showWidgetOnAddonClick = options.showWidgetOnAddonClick;
32-
32+
this.timeSeparator = options.timeSeparator;
3333
this._init();
3434
};
3535

@@ -269,10 +269,10 @@
269269
'</tr>'+
270270
'<tr>'+
271271
'<td>'+ hourTemplate +'</td> '+
272-
'<td class="separator">:</td>'+
272+
'<td class="separator">' + this.timeSeparator + '</td>'+
273273
'<td>'+ minuteTemplate +'</td> '+
274274
(this.showSeconds ?
275-
'<td class="separator">:</td>'+
275+
'<td class="separator">' + this.timeSeparator + '</td>'+
276276
'<td>'+ secondTemplate +'</td>'
277277
: '') +
278278
(this.showMeridian ?
@@ -323,7 +323,7 @@
323323
return '';
324324
}
325325

326-
return this.hour + ':' + (this.minute.toString().length === 1 ? '0' + this.minute : this.minute) + (this.showSeconds ? ':' + (this.second.toString().length === 1 ? '0' + this.second : this.second) : '') + (this.showMeridian ? ' ' + this.meridian : '');
326+
return this.hour + this.timeSeparator + (this.minute.toString().length === 1 ? '0' + this.minute : this.minute) + (this.showSeconds ? this.timeSeparator + (this.second.toString().length === 1 ? '0' + this.second : this.second) : '') + (this.showMeridian ? ' ' + this.meridian : '');
327327
},
328328

329329
hideWidget: function() {
@@ -763,10 +763,9 @@
763763
} else {
764764
meridian = 'AM';
765765
}
766-
767-
time = time.replace(/[^0-9\:]/g, '');
768-
769-
timeArray = time.split(':');
766+
// Don't know how to include dynamically a char do both [.:]
767+
time = time.replace(/[^0-9\:\.]/g, '');
768+
timeArray = time.split(this.timeSeparator);
770769

771770
hour = timeArray[0] ? timeArray[0].toString() : timeArray.toString();
772771
minute = timeArray[1] ? timeArray[1].toString() : '';
@@ -887,7 +886,7 @@
887886
if (this.defaultTime) {
888887
this.setDefaultTime(this.defaultTime);
889888
} else {
890-
this.setTime('0:0:0');
889+
this.setTime('0' + this.timeSeparator + '0' + this.timeSeparator + '0');
891890
}
892891
}
893892

@@ -969,9 +968,9 @@
969968
return;
970969
}
971970

972-
var t = this.$widget.find('input.bootstrap-timepicker-hour').val() + ':' +
971+
var t = this.$widget.find('input.bootstrap-timepicker-hour').val() + this.timeSeparator +
973972
this.$widget.find('input.bootstrap-timepicker-minute').val() +
974-
(this.showSeconds ? ':' + this.$widget.find('input.bootstrap-timepicker-second').val() : '') +
973+
(this.showSeconds ? this.timeSeparator + this.$widget.find('input.bootstrap-timepicker-second').val() : '') +
975974
(this.showMeridian ? this.$widget.find('input.bootstrap-timepicker-meridian').val() : '')
976975
;
977976

@@ -1089,7 +1088,8 @@
10891088
showMeridian: true,
10901089
template: 'dropdown',
10911090
appendWidgetTo: 'body',
1092-
showWidgetOnAddonClick: true
1091+
showWidgetOnAddonClick: true,
1092+
timeSeparator : ':'
10931093
};
10941094

10951095
$.fn.timepicker.Constructor = Timepicker;

0 commit comments

Comments
 (0)