diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js index 1b17233..f5af5e6 100644 --- a/jquery-ui-timepicker-addon.js +++ b/jquery-ui-timepicker-addon.js @@ -32,6 +32,8 @@ function Timepicker() { currentText: 'Now', closeText: 'Done', ampm: false, + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], timeFormat: 'hh:mm tt', timeSuffix: '', timeOnlyTitle: 'Choose Time', @@ -163,6 +165,8 @@ $.extend(Timepicker.prototype, { }, timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); }); + tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { return val.toUpperCase() }); + tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { return val.toUpperCase() }); tp_inst.hour = tp_inst._defaults.hour; tp_inst.minute = tp_inst._defaults.minute; @@ -219,10 +223,11 @@ $.extend(Timepicker.prototype, { .replace(/m{1,2}/ig, '(\\d?\\d)') .replace(/s{1,2}/ig, '(\\d?\\d)') .replace(/l{1}/ig, '(\\d?\\d?\\d)') - .replace(/t{1,2}/ig, '(am|pm|a|p)?') + .replace(/t{1,2}/ig, this._getPatternAmpm()) .replace(/z{1}/ig, '((\\+|-)\\d\\d\\d\\d)?') .replace(/\s/g, '\\s?') + this._defaults.timeSuffix + '$', order = this._getFormatPositions(), + ampm = '', treg; if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]); @@ -239,15 +244,20 @@ $.extend(Timepicker.prototype, { treg = timeString.match(new RegExp(regstr, 'i')); if (treg) { - if (order.t !== -1) - this.ampm = ((treg[order.t] === undefined || treg[order.t].length === 0) ? - '' : - (treg[order.t].charAt(0).toUpperCase() == 'A') ? 'AM' : 'PM').toUpperCase(); + if (order.t !== -1) { + if (treg[order.t] === undefined || treg[order.t].length === 0) { + ampm = ''; + this.ampm = ''; + } else { + ampm = $.inArray(treg[order.t].toUpperCase(), this.amNames) !== -1 ? 'AM' : 'PM'; + this.ampm = this._defaults[ampm == 'AM' ? 'amNames' : 'pmNames'][0]; + } + } if (order.h !== -1) { - if (this.ampm == 'AM' && treg[order.h] == '12') + if (ampm == 'AM' && treg[order.h] == '12') this.hour = 0; // 12am = 0 hour - else if (this.ampm == 'PM' && treg[order.h] != '12') + else if (ampm == 'PM' && treg[order.h] != '12') this.hour = (parseFloat(treg[order.h]) + 12).toFixed(0); // 12pm = 12 hour, any other pm = hour + 12 else this.hour = Number(treg[order.h]); } @@ -263,6 +273,20 @@ $.extend(Timepicker.prototype, { return false; }, + //######################################################################## + // pattern for standard and localized AM/PM markers + //######################################################################## + _getPatternAmpm: function() { + var markers = []; + o = this._defaults; + if (o.amNames) + $.merge(markers, o.amNames); + if (o.pmNames) + $.merge(markers, o.pmNames); + markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&') }); + return '(' + markers.join('|') + ')?'; + }, + //######################################################################## // figure out position of time elements.. cause js cant do named captures //######################################################################## @@ -706,7 +730,8 @@ $.extend(Timepicker.prototype, { minute = (this.minute_slider) ? this.minute_slider.slider('value') : false, second = (this.second_slider) ? this.second_slider.slider('value') : false, millisec = (this.millisec_slider) ? this.millisec_slider.slider('value') : false, - timezone = (this.timezone_select) ? this.timezone_select.val() : false; + timezone = (this.timezone_select) ? this.timezone_select.val() : false, + o = this._defaults; if (typeof(hour) == 'object') hour = false; if (typeof(minute) == 'object') minute = false; @@ -719,11 +744,15 @@ $.extend(Timepicker.prototype, { if (second !== false) second = parseInt(second,10); if (millisec !== false) millisec = parseInt(millisec,10); - var ampm = (hour < 12) ? 'AM' : 'PM'; + var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0]; // If the update was done in the input field, the input field should not be updated. // If the update was done using the sliders, update the input field. - var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || millisec != this.millisec || (this.ampm.length > 0 && this.ampm != ampm) || timezone != this.timezone); + var hasChanged = (hour != this.hour || minute != this.minute + || second != this.second || millisec != this.millisec + || (this.ampm.length > 0 + && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) + || timezone != this.timezone); if (hasChanged) { @@ -737,10 +766,10 @@ $.extend(Timepicker.prototype, { this._limitMinMaxDateTime(this.inst, true); } - if (this._defaults.ampm) this.ampm = ampm; + if (o.ampm) this.ampm = ampm; this._formatTime(); - if (this.$timeObj) this.$timeObj.text(this.formattedTime + this._defaults.timeSuffix); + if (this.$timeObj) this.$timeObj.text(this.formattedTime + o.timeSuffix); this.timeDefined = true; if (hasChanged) this._updateDateTime(); }, @@ -763,38 +792,35 @@ $.extend(Timepicker.prototype, { _formatTime: function(time, format, ampm) { if (ampm == undefined) ampm = this._defaults.ampm; time = time || { hour: this.hour, minute: this.minute, second: this.second, millisec: this.millisec, ampm: this.ampm, timezone: this.timezone }; - var tmptime = format || this._defaults.timeFormat.toString(); + var tmptime = (format || this._defaults.timeFormat).toString(); + var hour = parseInt(time.hour, 10); if (ampm) { - var hour12 = ((time.ampm == 'AM') ? (time.hour) : (time.hour % 12)); - hour12 = (Number(hour12) === 0) ? 12 : hour12; - tmptime = tmptime.toString() - .replace(/hh/g, ((hour12 < 10) ? '0' : '') + hour12) - .replace(/h/g, hour12) - .replace(/mm/g, ((time.minute < 10) ? '0' : '') + time.minute) - .replace(/m/g, time.minute) - .replace(/ss/g, ((time.second < 10) ? '0' : '') + time.second) - .replace(/s/g, time.second) - .replace(/l/g, ((time.millisec < 10) ? '00' : (time.millisec < 100) ? '0': '') + time.millisec) - .replace(/TT/g, time.ampm.toUpperCase()) - .replace(/Tt/g, time.ampm.toUpperCase()) - .replace(/tT/g, time.ampm.toLowerCase()) - .replace(/tt/g, time.ampm.toLowerCase()) - .replace(/T/g, time.ampm.charAt(0).toUpperCase()) - .replace(/t/g, time.ampm.charAt(0).toLowerCase()) - .replace(/z/g, time.timezone); - } else { - tmptime = tmptime.toString() - .replace(/hh/g, ((time.hour < 10) ? '0' : '') + time.hour) - .replace(/h/g, time.hour) - .replace(/mm/g, ((time.minute < 10) ? '0' : '') + time.minute) - .replace(/m/g, time.minute) - .replace(/ss/g, ((time.second < 10) ? '0' : '') + time.second) - .replace(/s/g, time.second) - .replace(/l/g, ((time.millisec < 10) ? '00' : (time.millisec < 100) ? '0': '') + time.millisec) - .replace(/z/g, time.timezone); - tmptime = $.trim(tmptime.replace(/t/gi, '')); + if (!$.inArray(time.ampm.toUpperCase(), this.amNames) !== -1) + hour = hour % 12; + if (hour === 0) + hour = 12; } + tmptime = tmptime.replace(/(?:hh?|mm?|ss?|[tT]{1,2}|[lz])/g, function(match) { + switch (match.toLowerCase()) { + case 'hh': return ('0' + hour).slice(-2); + case 'h': return hour; + case 'mm': return ('0' + time.minute).slice(-2); + case 'm': return time.minute; + case 'ss': return ('0' + time.second).slice(-2); + case 's': return time.second; + case 'l': return ('00' + time.millisec).slice(-3); + case 'z': return time.timezone; + case 't': case 'tt': + if (ampm) { + var _ampm = time.ampm; + if (match.length == 1) + _ampm = _ampm.charAt(0); + return match.charAt(0) == 'T' ? _ampm.toUpperCase() : _ampm.toLowerCase(); + } + return ''; + } + }); if (arguments.length) return tmptime; else this.formattedTime = tmptime; diff --git a/localization/jquery-ui-timepicker-ca.js b/localization/jquery-ui-timepicker-ca.js index 8e68bac..d4d9abb 100644 --- a/localization/jquery-ui-timepicker-ca.js +++ b/localization/jquery-ui-timepicker-ca.js @@ -12,6 +12,8 @@ currentText: 'Ara', closeText: 'Tancar', timeFormat: 'hh:mm', + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['ca']); diff --git a/localization/jquery-ui-timepicker-cs.js b/localization/jquery-ui-timepicker-cs.js index 589db81..74ef405 100644 --- a/localization/jquery-ui-timepicker-cs.js +++ b/localization/jquery-ui-timepicker-cs.js @@ -12,6 +12,8 @@ currentText: 'Nyní', closeText: 'Zavřít', timeFormat: 'h:m', + amNames: ['dop.', 'AM', 'A'], + pmNames: ['odp.', 'PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['cs']); diff --git a/localization/jquery-ui-timepicker-de.js b/localization/jquery-ui-timepicker-de.js index 5d28994..741298b 100644 --- a/localization/jquery-ui-timepicker-de.js +++ b/localization/jquery-ui-timepicker-de.js @@ -12,6 +12,8 @@ currentText: 'Jetzt', closeText: 'Fertig', timeFormat: 'hh:mm tt', + amNames: ['vorm.', 'AM', 'A'], + pmNames: ['nachm.', 'PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['de']); diff --git a/localization/jquery-ui-timepicker-el.js b/localization/jquery-ui-timepicker-el.js index e6a6cdd..207abb5 100644 --- a/localization/jquery-ui-timepicker-el.js +++ b/localization/jquery-ui-timepicker-el.js @@ -12,6 +12,8 @@ currentText: 'Τώρα', closeText: 'Κλείσιμο', timeFormat: 'hh:mm', + amNames: ['π.μ.', 'AM', 'A'], + pmNames: ['μ.μ.', 'PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['el']); diff --git a/localization/jquery-ui-timepicker-es.js b/localization/jquery-ui-timepicker-es.js index b5f69b8..2d76f9b 100644 --- a/localization/jquery-ui-timepicker-es.js +++ b/localization/jquery-ui-timepicker-es.js @@ -12,6 +12,8 @@ currentText: 'Ahora', closeText: 'Cerrar', timeFormat: 'hh:mm', + amNames: ['a.m.', 'AM', 'A'], + pmNames: ['p.m.', 'PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['es']); diff --git a/localization/jquery-ui-timepicker-et.js b/localization/jquery-ui-timepicker-et.js index 1dd67c1..fc86b34 100644 --- a/localization/jquery-ui-timepicker-et.js +++ b/localization/jquery-ui-timepicker-et.js @@ -12,6 +12,8 @@ currentText: 'Praegu', closeText: 'Valmis', timeFormat: 'hh:mm tt', + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['et']); diff --git a/localization/jquery-ui-timepicker-fr.js b/localization/jquery-ui-timepicker-fr.js index 6a76efa..ac8159d 100644 --- a/localization/jquery-ui-timepicker-fr.js +++ b/localization/jquery-ui-timepicker-fr.js @@ -12,6 +12,8 @@ currentText: 'Maintenant', closeText: 'Terminé', timeFormat: 'hh:mm', + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['fr']); diff --git a/localization/jquery-ui-timepicker-he.js b/localization/jquery-ui-timepicker-he.js index 44ea771..7f21e02 100644 --- a/localization/jquery-ui-timepicker-he.js +++ b/localization/jquery-ui-timepicker-he.js @@ -12,6 +12,8 @@ currentText: "עכשיו", closeText:"סגור", timeFormat: "hh:mm tt", + amNames: ['לפנה"צ', AM', 'A'], + pmNames: ['אחה"צ', PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional["he"]); diff --git a/localization/jquery-ui-timepicker-hu.js b/localization/jquery-ui-timepicker-hu.js index fa16414..956d986 100644 --- a/localization/jquery-ui-timepicker-hu.js +++ b/localization/jquery-ui-timepicker-hu.js @@ -12,6 +12,8 @@ currentText: 'Most', closeText: 'Kész', timeFormat: 'hh:mm tt', + amNames: ['de.', 'AM', 'A'], + pmNames: ['du.', 'PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['hu']); diff --git a/localization/jquery-ui-timepicker-id.js b/localization/jquery-ui-timepicker-id.js index c553425..e802738 100644 --- a/localization/jquery-ui-timepicker-id.js +++ b/localization/jquery-ui-timepicker-id.js @@ -12,6 +12,8 @@ currentText: 'Sekarang', closeText: 'OK', timeFormat: 'hh:mm tt', + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['id']); diff --git a/localization/jquery-ui-timepicker-it.js b/localization/jquery-ui-timepicker-it.js index 98d2bf4..d519670 100644 --- a/localization/jquery-ui-timepicker-it.js +++ b/localization/jquery-ui-timepicker-it.js @@ -12,6 +12,8 @@ currentText: 'Adesso', closeText: 'Chiudi', timeFormat: 'hh:mm', + amNames: ['m.', 'AM', 'A'], + pmNames: ['p.', 'PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['it']); diff --git a/localization/jquery-ui-timepicker-ja.js b/localization/jquery-ui-timepicker-ja.js index 33a404a..aa05d6a 100644 --- a/localization/jquery-ui-timepicker-ja.js +++ b/localization/jquery-ui-timepicker-ja.js @@ -12,6 +12,8 @@ currentText: '現時刻', closeText: '閉じる', timeFormat: 'hh:mm tt', + amNames: ['午前', 'AM', 'A'], + pmNames: ['午後', 'PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['ja']); diff --git a/localization/jquery-ui-timepicker-lt.js b/localization/jquery-ui-timepicker-lt.js index 17e0993..a67e267 100644 --- a/localization/jquery-ui-timepicker-lt.js +++ b/localization/jquery-ui-timepicker-lt.js @@ -12,6 +12,8 @@ currentText: 'Dabar', closeText: 'Uždaryti', timeFormat: 'hh:mm', + amNames: ['priešpiet', 'AM', 'A'], + pmNames: ['popiet', 'PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['lt']); diff --git a/localization/jquery-ui-timepicker-nl.js b/localization/jquery-ui-timepicker-nl.js index 2522026..181b911 100644 --- a/localization/jquery-ui-timepicker-nl.js +++ b/localization/jquery-ui-timepicker-nl.js @@ -12,6 +12,8 @@ currentText: 'Vandaag', closeText: 'Sluiten', timeFormat: 'hh:mm tt', + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['nl']); diff --git a/localization/jquery-ui-timepicker-ro.js b/localization/jquery-ui-timepicker-ro.js index aedfa3c..da66135 100644 --- a/localization/jquery-ui-timepicker-ro.js +++ b/localization/jquery-ui-timepicker-ro.js @@ -12,6 +12,8 @@ currentText: 'Acum', closeText: 'Închide', timeFormat: 'hh:mm', + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['ro']); diff --git a/localization/jquery-ui-timepicker-ru.js b/localization/jquery-ui-timepicker-ru.js index ced31c8..faae11d 100644 --- a/localization/jquery-ui-timepicker-ru.js +++ b/localization/jquery-ui-timepicker-ru.js @@ -12,6 +12,8 @@ currentText: 'Теперь', closeText: 'Закрыть', timeFormat: 'hh:mm tt', + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['ru']); diff --git a/localization/jquery-ui-timepicker-tr.js b/localization/jquery-ui-timepicker-tr.js index 4d2060e..bcbc1bb 100644 --- a/localization/jquery-ui-timepicker-tr.js +++ b/localization/jquery-ui-timepicker-tr.js @@ -12,6 +12,8 @@ currentText: 'Şu an', closeText: 'Tamam', timeFormat: 'hh:mm', + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['tr']); diff --git a/localization/jquery-ui-timepicker-vi.js b/localization/jquery-ui-timepicker-vi.js index 4812cb5..f049eb4 100644 --- a/localization/jquery-ui-timepicker-vi.js +++ b/localization/jquery-ui-timepicker-vi.js @@ -12,6 +12,8 @@ currentText: 'Hiện thời', closeText: 'Đóng' timeFormat: 'h:m', + amNames: ['SA', 'AM', 'A'], + pmNames: ['CH', 'PM', 'P'], ampm: false }; $.timepicker.setDefaults($.timepicker.regional['vi']);