From 08eb8f497d7a1acde36b00772eb5e4f0b94915d3 Mon Sep 17 00:00:00 2001 From: InfinitiesLoop Date: Wed, 9 Jun 2010 12:04:18 -0700 Subject: [PATCH] Fixed formatting param issues. Added comments documenting use of string offset for twoDigitYearMax. --- README.md | 4 +++- jquery.glob.js | 21 ++++++++++++++------- jquery.glob.min.js | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c90dd2b..4163ac4 100644 --- a/README.md +++ b/README.md @@ -325,7 +325,9 @@ jQuery.cultures['default'] = { {"name":"A.D.","start":null,"offset":0} ], // when a two digit year is given, it will never be parsed as a four digit - // year great than this year (in the appropriate era for the culture) + // year greater than this year (in the appropriate era for the culture) + // Set it as a full year (e.g. 2029) or use an offset format starting from + // the current year: "+19" would correspond to 2029 if the current year 2010. twoDigitYearMax: 2029, // set of predefined date and time patterns used by the culture // these represent the format someone in this culture would expect diff --git a/jquery.glob.js b/jquery.glob.js index 698fc0c..eb91107 100644 --- a/jquery.glob.js +++ b/jquery.glob.js @@ -169,13 +169,18 @@ $.extend({ culture = $.findClosestCulture( culture ); var date; - if ( formats && formats.length ) { - for ( var i = 1, l = formats.length; i < l; i++ ) { - var format = formats[ i ]; - if ( format ) { - date = parseExact( value, format, cultureInfo ); - if ( date ) { - break; + if ( formats ) { + if ( typeof formats === "string" ) { + formats = [ formats ]; + } + if ( formats.length ) { + for ( var i = 0, l = formats.length; i < l; i++ ) { + var format = formats[ i ]; + if ( format ) { + date = parseExact( value, format, culture ); + if ( date ) { + break; + } } } } @@ -342,6 +347,8 @@ var en = cultures["default"] = cultures.en = $.extend(true, { ], // when a two digit year is given, it will never be parsed as a four digit // year greater than this year (in the appropriate era for the culture) + // Set it as a full year (e.g. 2029) or use an offset format starting from + // the current year: "+19" would correspond to 2029 if the current year 2010. twoDigitYearMax: 2029, // set of predefined date and time patterns used by the culture // these represent the format someone in this culture would expect diff --git a/jquery.glob.min.js b/jquery.glob.min.js index b61fb28..7d3668c 100644 --- a/jquery.glob.min.js +++ b/jquery.glob.min.js @@ -1 +1 @@ -(function(a){var e={"invariant":{}};a.extend({findClosestCulture:function(b){var c;if(!b)c=a.culture||a.cultures.invariant;else if(a.isPlainObject(b))c=b;else{for(var f=a.cultures,e=a.isArray(b)?b:[b],h=e.length,d=0;d1?parseInt(e[1],10):0;b=e[0];e=b.split(".");b=e[0];a=e.length>1?e[1]:"";var q;if(c>0){a=f(a,c,false);b+=a.slice(0,c);a=a.substr(c)}else if(c<0){c=-c;b=f(b,c+1);a=b.slice(-c,b.length)+a;b=b.slice(0,-c)}if(h>0)a=l["."]+(a.length>h?a.slice(0,h):f(a,h));else a="";var d=b.length-1,o=l[","],g="";while(d>=0){if(i===0||i>d)return b.slice(0,d+1)+(g.length?o+g+a:a);g=b.slice(d-i+1,d+1)+(g.length?o+g:"");d-=i;if(k1)e=parseInt(d.slice(1),10);var l=d.charAt(0).toUpperCase(),b;switch(l){case"D":i="n";if(e!==-1)c=f(""+c,e,true);if(j<0)c=-c;break;case"N":b=h;case"C":b=b||h.currency;case"P":b=b||h.percent;i=j<0?b.pattern[0]:b.pattern[1]||"n";if(e===-1)e=b.decimals;c=x(c*(l==="P"?100:1),e,b);break;default:a.error("Bad number format specifier: "+l)}for(var m=/n|\$|-|%/g,g="";true;){var o=m.lastIndex,k=m.exec(i);g+=i.slice(o,k?k.index:i.length);if(!k)break;switch(k[0]){case"n":g+=c;break;case"$":g+=h.currency.symbol;break;case"-":if(/[1-9]/.test(c))g+=h["-"];break;case"%":g+=h.percent.symbol}}return g}function b(a,c,b){return ab}function A(d,b){var e=new Date,f=g(e);if(b<100){var a=d.twoDigitYearMax;a=typeof a==="string"?(new Date).getFullYear()%100+parseInt(a,10):a;var c=j(e,d,f);b+=c-c%100;if(b>a)b-=100}return b}function g(e,c){if(!c)return 0;for(var b,d=e.getTime(),a=0,f=c.length;a=b)return a}return 0}function m(a){return a.split("\u00a0").join(" ").toUpperCase()}function c(b){return a.map(b,function(a){return m(a)})}function j(d,b,e,c){var a=d.getFullYear();if(!c&&b.eras)a-=b.eras[e].offset;return a}function z(g,d,h){var e,f=g.days,b=g._upperDays;if(!b)g._upperDays=b=[c(f[0]),c(f[1]),c(f[2])];d=m(d);if(h){e=a.inArray(d,b[1]);if(e===-1)e=a.inArray(d,b[2])}else e=a.inArray(d,b[0]);return e}function v(b,f,i){var d=b.months,j=b.monthsGenitive||b.months,e=b._upperMonths,g=b._upperMonthsGen;if(!e){b._upperMonths=e=[c(d[0]),c(d[1])];b._upperMonthsGen=g=[c(d[2]||d[0]),c(d[3]||d[1])]}f=m(f);var h=a.inArray(f,i?e[1]:e[0]);if(h<0)h=a.inArray(f,i?g[1]:g[0]);return h}function h(e,b){for(var d=0,a=false,c=0,g=e.length;c1&&c.length1?parseInt(e[1],10):0;b=e[0];e=b.split(".");b=e[0];a=e.length>1?e[1]:"";var q;if(c>0){a=f(a,c,false);b+=a.slice(0,c);a=a.substr(c)}else if(c<0){c=-c;b=f(b,c+1);a=b.slice(-c,b.length)+a;b=b.slice(0,-c)}if(h>0)a=l["."]+(a.length>h?a.slice(0,h):f(a,h));else a="";var d=b.length-1,o=l[","],g="";while(d>=0){if(i===0||i>d)return b.slice(0,d+1)+(g.length?o+g+a:a);g=b.slice(d-i+1,d+1)+(g.length?o+g:"");d-=i;if(k1)e=parseInt(d.slice(1),10);var l=d.charAt(0).toUpperCase(),b;switch(l){case"D":i="n";if(e!==-1)c=f(""+c,e,true);if(j<0)c=-c;break;case"N":b=h;case"C":b=b||h.currency;case"P":b=b||h.percent;i=j<0?b.pattern[0]:b.pattern[1]||"n";if(e===-1)e=b.decimals;c=x(c*(l==="P"?100:1),e,b);break;default:a.error("Bad number format specifier: "+l)}for(var m=/n|\$|-|%/g,g="";true;){var o=m.lastIndex,k=m.exec(i);g+=i.slice(o,k?k.index:i.length);if(!k)break;switch(k[0]){case"n":g+=c;break;case"$":g+=h.currency.symbol;break;case"-":if(/[1-9]/.test(c))g+=h["-"];break;case"%":g+=h.percent.symbol}}return g}function b(a,c,b){return ab}function A(d,b){var e=new Date,f=g(e);if(b<100){var a=d.twoDigitYearMax;a=typeof a==="string"?(new Date).getFullYear()%100+parseInt(a,10):a;var c=j(e,d,f);b+=c-c%100;if(b>a)b-=100}return b}function g(e,c){if(!c)return 0;for(var b,d=e.getTime(),a=0,f=c.length;a=b)return a}return 0}function m(a){return a.split("\u00a0").join(" ").toUpperCase()}function c(b){return a.map(b,function(a){return m(a)})}function j(d,b,e,c){var a=d.getFullYear();if(!c&&b.eras)a-=b.eras[e].offset;return a}function z(g,d,h){var e,f=g.days,b=g._upperDays;if(!b)g._upperDays=b=[c(f.names),c(f.namesAbbr),c(f.namesShort)];d=m(d);if(h){e=a.inArray(d,b[1]);if(e===-1)e=a.inArray(d,b[2])}else e=a.inArray(d,b[0]);return e}function v(b,e,j){var i=b.months,h=b.monthsGenitive||b.months,d=b._upperMonths,f=b._upperMonthsGen;if(!d){b._upperMonths=d=[c(i.names),c(i.namesAbbr)];b._upperMonthsGen=f=[c(h.names),c(h.namesAbbr)]}e=m(e);var g=a.inArray(e,j?d[1]:d[0]);if(g<0)g=a.inArray(e,j?f[1]:f[0]);return g}function h(e,b){for(var d=0,a=false,c=0,g=e.length;c1&&c.length