/*
Copyright 2014, KISSY v1.49
MIT Licensed
build time: May 22 12:17
*/
KISSY.add("date/format",["date/gregorian","i18n!date"],function(y,B){function s(b,a,e){e.push({field:b,count:a})}function r(b,a,e,d){d=d||[];e=e||C;if(0<=b){if(100>b&&1<=a&&2>=a)return 10>b&&2===a&&d.push(E),d.push(b),d.join("");if(1E3<=b&&1E4>b){if(4===a)return d.push(b),d.join("");if(2===a&&2===e)return r(b%100,2,2,d)}}d.push(b+"");return d.join("")}function w(b,a,e){this.locale=a||D;for(var a=b.length,d=!1,g=[],c=null,p=0,k=-1,f=0;f<a;f++){var i=b.charAt(f);if("'"===i){if(f+1<a&&(i=b.charAt(f+
1),"'"===i)){f++;0!==p&&(s(k,p,g),k=-1,p=0);d&&(c+=i);continue}d?(g.push({text:c}),d=!1):(0!==p&&(s(k,p,g),k=-1,p=0),c="",d=!0)}else if(d)c+=i;else if("a"<=i&&"z">=i||"A"<=i&&"Z">=i){if(-1===j.indexOf(i))throw Error('Illegal pattern character "'+i+'"');-1===k||k===i?(k=i,p++):(s(k,p,g),k=i,p=1)}else 0!==p&&(s(k,p,g),k=-1,p=0),g.push({text:i})}if(d)throw Error("Unterminated quote");0!==p&&s(k,p,g);this.pattern=g;this.timezoneOffset=e}function F(b,a,e,d){switch(b){case "G":b=0<d.getYear()?1:0;a=e.eras[b];
break;case "y":b=d.getYear();0>=b&&(b=1-b);a=r(b,2,2!==a?C:2);break;case "M":b=d.getMonth();a=4<=a?e.months[b]:3===a?e.shortMonths[b]:r(b+1,a);break;case "k":a=r(d.getHourOfDay()||24,a);break;case "E":b=d.getDayOfWeek();a=4<=a?e.weekdays[b]:e.shortWeekdays[b];break;case "a":a=e.ampms[12<=d.getHourOfDay()?1:0];break;case "h":a=r(d.getHourOfDay()%12||12,a);break;case "K":a=r(d.getHourOfDay()%12,a);break;case "Z":a=d.getTimezoneOffset();e=[0>a?"-":"+"];a=Math.abs(a);e.push(r(Math.floor(a/60)%100,2),
r(a%60,2));a=e.join("");break;default:b=d.get(z[b]),a=r(b,a)}return a}function x(b,a,e){var d=-1,g=-1,c,j=e.length;for(c=0;c<j;c++){var k=e[c],f=k.length,i;if(i=f>d)a:{i=b;for(var o=a,n=f,h=0;h<n;h++)if(i.charAt(o+h)!==k.charAt(h)){i=!1;break a}i=!0}i&&(d=f,g=c)}return 0<=g?{value:g,startIndex:a+d}:null}function t(b,a,e,d){var g=b;if(d){if(b.length<=a+e)return null;g=b.substring(a,e);if(!g.match(/^\d+$/))return null}else g=g.substring(a);b=parseInt(g,10);if(isNaN(b))a=null;else{for(var c=g.length,
e=0;e<c&&!(d=g.charAt(e),"0">d||"9"<d);e++);a={value:b,startIndex:a+e}}return a}var o=B("date/gregorian"),D=B("i18n!date"),C=Number.MAX_VALUE,A={FULL:0,LONG:1,MEDIUM:2,SHORT:3},j=Array(o.DAY_OF_WEEK_IN_MONTH+2).join("1"),z={},j=j.split("");j[0]="G";j[o.YEAR]="y";j[o.MONTH]="M";j[o.DAY_OF_MONTH]="d";j[o.HOUR_OF_DAY]="H";j[o.MINUTES]="m";j[o.SECONDS]="s";j[o.MILLISECONDS]="S";j[o.WEEK_OF_YEAR]="w";j[o.WEEK_OF_MONTH]="W";j[o.DAY_OF_YEAR]="D";j[o.DAY_OF_WEEK_IN_MONTH]="F";y.each(j,function(b,a){z[b]=
a});var j=j.join("")+"ahkKZE",E="0";w.prototype={format:function(b){var a=b.getTime(),b=new o(this.timezoneOffset,this.locale);b.setTime(a);for(var e=[],d=this.pattern,g=d.length,a=0;a<g;a++){var c=d[a];c.text?e.push(c.text):"field"in c&&e.push(F(c.field,c.count,this.locale,b))}return e.join("")},parse:function(b){var a=new o(this.timezoneOffset,this.locale),e,d,g={},c=!1,j=b.length,k=-1,f=0;d=0;var i=this.pattern,r=i.length;a:for(e=0;0>k&&e<r;e++){var n=i[e],h,l;d=f;if(h=n.text)if(l=h.length,l+f>
j)k=f;else{for(d=0;d<l;d++)if(h.charAt(d)!==b.charAt(d+f)){k=f;break a}f+=l}else if("field"in n){c=!1;if(h=i[e+1])"field"in h?c=!0:(h=h.text.charAt(0),"0"<=h&&"9">=h&&(c=!0));h=a;l=b;var q=n.field,n=n.count,s=this.locale,u=c,v=g,m=c=void 0,m=void 0;if(!(l.length<=f)){switch(q){case "G":if(c=x(l,f,s.eras))h.isSetYear()?0===c.value&&(m=h.getYear(),h.setYear(1-m)):v.era=c.value;break;case "y":if(c=t(l,f,n,u))m=c.value,"era"in v&&0===v.era&&(m=1-m),h.setYear(m);break;case "M":q=void 0;if(3<=n){if(c=x(l,
f,s[3===n?"shortMonths":"months"]))q=c.value}else if(c=t(l,f,n,u))q=c.value-1;c&&h.setMonth(q);break;case "k":(c=t(l,f,n,u))&&h.setHourOfDay(c.value%24);break;case "E":(c=x(l,f,s[3<n?"weekdays":"shortWeekdays"]))&&h.setDayOfWeek(c.value);break;case "a":if(c=x(l,f,s.ampms))h.isSetHourOfDay()?c.value&&(m=h.getHourOfDay(),12>m&&h.setHourOfDay((m+12)%24)):v.ampm=c.value;break;case "h":if(c=t(l,f,n,u))m=c.value%=12,v.ampm&&(m+=12),h.setHourOfDay(m);break;case "K":if(c=t(l,f,n,u))m=c.value,v.ampm&&(m+=
12),h.setHourOfDay(m);break;case "Z":q=l.charAt(f);if("-"===q)f++;else if("+"===q)f++;else break;if(c=t(l,f,2,!0)){q=60*c.value;f=c.startIndex;if(c=t(l,f,2,!0))q+=c.value;h.setTimezoneOffset(q)}break;default:(c=t(l,f,n,u))&&h.set(z[q],c.value)}c&&(f=c.startIndex)}f===d&&(k=f)}}return 0<=k?void 0:a}};y.mix(w,{Style:A,getInstance:function(b,a){return this.getDateTimeInstance(A.SHORT,A.SHORT,b,a)},getDateInstance:function(b,a,e){return this.getDateTimeInstance(b,void 0,a,e)},getDateTimeInstance:function(b,
a,e,d){var e=e||D,g="";void 0!==b&&(g=e.datePatterns[b]);b="";void 0!==a&&(b=e.timePatterns[a]);a=g;b&&(a=g?y.substitute(e.dateTimePattern,{date:g,time:b}):b);return new w(a,e,d)},getTimeInstance:function(b,a,e){return this.getDateTimeInstance(void 0,b,a,e)}});return w});
