Skip to content

Commit 522d0b4

Browse files
Fix looseParse timezone
1 parent b7aa216 commit 522d0b4

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -983,48 +983,49 @@
983983
/*
984984
* Public utility to parse time
985985
*/
986-
$.datepicker.parseTime = function(timeFormat, timeString, options) {
987-
988-
// pattern for standard and localized AM/PM markers
989-
var getPatternAmpm = function(amNames, pmNames) {
990-
var markers = [];
991-
if (amNames) {
992-
$.merge(markers, amNames);
993-
}
994-
if (pmNames) {
995-
$.merge(markers, pmNames);
996-
}
997-
markers = $.map(markers, function(val) {
998-
return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&');
999-
});
1000-
return '(' + markers.join('|') + ')?';
1001-
};
986+
$.datepicker.parseTime = function(timeFormat, timeString, options) {
987+
var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {});
1002988

1003-
// figure out position of time elements.. cause js cant do named captures
1004-
var getFormatPositions = function(timeFormat) {
1005-
var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z|'.*?')/g),
1006-
orders = {
1007-
h: -1,
1008-
m: -1,
1009-
s: -1,
1010-
l: -1,
1011-
t: -1,
1012-
z: -1
1013-
};
989+
// Strict parse requires the timeString to match the timeFormat exactly
990+
var strictParse = function(f, s, o){
1014991

1015-
if (finds) {
1016-
for (var i = 0; i < finds.length; i++) {
1017-
if (orders[finds[i].toString().charAt(0)] == -1) {
1018-
orders[finds[i].toString().charAt(0)] = i + 1;
1019-
}
992+
// pattern for standard and localized AM/PM markers
993+
var getPatternAmpm = function(amNames, pmNames) {
994+
var markers = [];
995+
if (amNames) {
996+
$.merge(markers, amNames);
1020997
}
1021-
}
1022-
return orders;
1023-
};
998+
if (pmNames) {
999+
$.merge(markers, pmNames);
1000+
}
1001+
markers = $.map(markers, function(val) {
1002+
return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&');
1003+
});
1004+
return '(' + markers.join('|') + ')?';
1005+
};
10241006

1025-
var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {});
1007+
// figure out position of time elements.. cause js cant do named captures
1008+
var getFormatPositions = function(timeFormat) {
1009+
var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z|'.*?')/g),
1010+
orders = {
1011+
h: -1,
1012+
m: -1,
1013+
s: -1,
1014+
l: -1,
1015+
t: -1,
1016+
z: -1
1017+
};
1018+
1019+
if (finds) {
1020+
for (var i = 0; i < finds.length; i++) {
1021+
if (orders[finds[i].toString().charAt(0)] == -1) {
1022+
orders[finds[i].toString().charAt(0)] = i + 1;
1023+
}
1024+
}
1025+
}
1026+
return orders;
1027+
};
10261028

1027-
var strictParse = function(f, s, o){
10281029
var regstr = '^' + f.toString()
10291030
.replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[lz]|'.*?')/g, function (match) {
10301031
switch (match.charAt(0).toLowerCase()) {
@@ -1118,6 +1119,7 @@
11181119
return false;
11191120
};// end strictParse
11201121

1122+
// First try JS Date, if that fails, use strictParse
11211123
var looseParse = function(f,s,o){
11221124
try{
11231125
var d = new Date('2012-01-01 '+ s);
@@ -1126,7 +1128,7 @@
11261128
minutes: d.getMinutes(),
11271129
seconds: d.getSeconds(),
11281130
millisec: d.getMilliseconds(),
1129-
timezone: d.getTimezoneOffset()
1131+
timezone: $.timepicker.timeZoneOffsetString(d)
11301132
};
11311133
}
11321134
catch(err){

0 commit comments

Comments
 (0)