diff --git a/avalon.js b/avalon.js index 10b98be90..c03f213e3 100644 --- a/avalon.js +++ b/avalon.js @@ -4342,12 +4342,12 @@ } var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/, NUMBER_STRING = /^\d+$/ - var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/ + var riso8601= /^(\d{4})-?(\d+)-?(\d+)(?:T(\d+)(?::?(\d+)(?::?(\d+)(?:\.(\d+))?)?)?(Z|([+-])(\d+):?(\d+))?)?$/ // 1 2 3 4 5 6 7 8 9 10 11 function jsonStringToDate(string) { var match - if (match = string.match(R_ISO8601_STR)) { + if (match = string.match(riso8601)) { var date = new Date(0), tzHour = 0, tzMin = 0, @@ -4382,7 +4382,7 @@ var trimDate = date.trim() date = trimDate.replace(rfixYMD, function(a, b, c, d) { var array = d.length === 4 ? [d, b, c] : [b, c, d] - return array.join("/") + return array.join("-") }) date = jsonStringToDate(date) } diff --git a/avalon.min.js b/avalon.min.js index 5b14ea8e0..a6a747c9a 100644 --- a/avalon.min.js +++ b/avalon.min.js @@ -112,10 +112,10 @@ nd=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,od=/([^\#-~| |!])/g,Xa=avalon.filters={uppe "",f=function(b,c){var d=Math.pow(10,c);return""+Math.round(b*d)/d},f=(c?f(b,c):""+Math.round(b)).split(".");3b&&(e="-",b=-b);for(b=""+b;b.length-e)g+=e;0===g&&-12===e&&(g=12);return b(g, d,f)}}function d(b,c){return function(d,e){var f=d["get"+b](),g=(c?"SHORT"+b:b).toUpperCase();return e[g][f]}}function e(b){var c;if(c=b.match(k)){b=new Date(0);var d=0,e=0,f=c[8]?b.setUTCFullYear:b.setFullYear,g=c[8]?b.setUTCHours:b.setHours;c[9]&&(d=parseInt(c[9]+c[10],10),e=parseInt(c[9]+c[11],10));f.call(b,parseInt(c[1],10),parseInt(c[2],10)-1,parseInt(c[3],10));d=parseInt(c[4]||0,10)-d;e=parseInt(c[5]||0,10)-e;f=parseInt(c[6]||0,10);c=Math.round(1E3*parseFloat("0."+(c[7]||0)));g.call(b,d,e,f, c)}return b}var f={yyyy:c("FullYear",4),yy:c("FullYear",2,0,!0),y:c("FullYear",1),MMMM:d("Month"),MMM:d("Month",!0),MM:c("Month",2,1),M:c("Month",1,1),dd:c("Date",2),d:c("Date",1),HH:c("Hours",2),H:c("Hours",1),hh:c("Hours",2,-12),h:c("Hours",1,-12),mm:c("Minutes",2),m:c("Minutes",1),ss:c("Seconds",2),s:c("Seconds",1),sss:c("Milliseconds",3),EEEE:d("Day"),EEE:d("Day",!0),a:function(b,c){return 12>b.getHours()?c.AMPMS[0]:c.AMPMS[1]},Z:function(c){c=-1*c.getTimezoneOffset();return c=(0<=c?"+":"")+(b(Math[0< -c?"floor":"ceil"](c/60),2)+b(Math.abs(c%60),2))}},g=/((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/,h=/^\d+$/,k=/^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/,l=/^(\d+)\D(\d+)\D(\d+)/;Xa.date=function(b,c){var d=Xa.date.locate,k="",F=[],ua,m;c=c||"mediumDate";c=d[c]||c;"string"===typeof b&&(h.test(b)?b=parseInt(b,10):(b=b.trim().replace(l,function(b,c,d,e){return(4===e.length?[e,c,d]:[c,d,e]).join("/")}),b=e(b)), -b=new Date(b));"number"===typeof b&&(b=new Date(b));if("date"===avalon.type(b)){for(;c;)(m=g.exec(c))?(F=F.concat(m.slice(1)),c=F.pop()):(F.push(c),c=null);F.forEach(function(c){ua=f[c];k+=ua?ua(b,d):c.replace(/(^'|'$)/g,"").replace(/''/g,"'")});return k}};var m={AMPMS:{"0":"\u4e0a\u5348",1:"\u4e0b\u5348"},DAY:{"0":"\u661f\u671f\u65e5",1:"\u661f\u671f\u4e00",2:"\u661f\u671f\u4e8c",3:"\u661f\u671f\u4e09",4:"\u661f\u671f\u56db",5:"\u661f\u671f\u4e94",6:"\u661f\u671f\u516d"},MONTH:{"0":"1\u6708",1:"2\u6708", -2:"3\u6708",3:"4\u6708",4:"5\u6708",5:"6\u6708",6:"7\u6708",7:"8\u6708",8:"9\u6708",9:"10\u6708",10:"11\u6708",11:"12\u6708"},SHORTDAY:{"0":"\u5468\u65e5",1:"\u5468\u4e00",2:"\u5468\u4e8c",3:"\u5468\u4e09",4:"\u5468\u56db",5:"\u5468\u4e94",6:"\u5468\u516d"},fullDate:"y\u5e74M\u6708d\u65e5EEEE",longDate:"y\u5e74M\u6708d\u65e5",medium:"yyyy-M-d ah:mm:ss",mediumDate:"yyyy-M-d",mediumTime:"ah:mm:ss","short":"yy-M-d ah:mm",shortDate:"yy-M-d",shortTime:"ah:mm"};m.SHORTMONTH=m.MONTH;Xa.date.locate=m};var s= -avalon.modules={"ready!":{exports:avalon},avalon:{exports:avalon,state:2}};new function(){function b(b){return(b||"").replace(/[?#].*/,"")}function c(b){var c;try{a.b.c()}catch(d){c=d.stack,!c&&r.opera&&(c=(String(d).match(/of linked script \S+/g)||[]).join(" "))}if(c)return c=c.split(/[@ ]/g).pop(),c="("===c[0]?c.slice(1,-1):c.replace(/\s/,""),c.replace(/(:\d+)?:\d+$/i,"");c=(b?p:J).getElementsByTagName("script");for(var e=c.length,f;f=c[--e];)if((b||f.className===G)&&"interactive"===f.readyState)return f.className= +c?"floor":"ceil"](c/60),2)+b(Math.abs(c%60),2))}},g=/((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/,h=/^\d+$/,k=/^(\d{4})-?(\d+)-?(\d+)(?:T(\d+)(?::?(\d+)(?::?(\d+)(?:\.(\d+))?)?)?(Z|([+-])(\d+):?(\d+))?)?$/,l=/^(\d+)\D(\d+)\D(\d+)/;Xa.date=function(b,c){var d=Xa.date.locate,k="",F=[],ua,m;c=c||"mediumDate";c=d[c]||c;"string"===typeof b&&(h.test(b)?b=parseInt(b,10):(b=b.trim().replace(l,function(b,c,d,e){return(4===e.length?[e,c,d]:[c,d,e]).join("-")}),b=e(b)),b=new Date(b)); +"number"===typeof b&&(b=new Date(b));if("date"===avalon.type(b)){for(;c;)(m=g.exec(c))?(F=F.concat(m.slice(1)),c=F.pop()):(F.push(c),c=null);F.forEach(function(c){ua=f[c];k+=ua?ua(b,d):c.replace(/(^'|'$)/g,"").replace(/''/g,"'")});return k}};var m={AMPMS:{"0":"\u4e0a\u5348",1:"\u4e0b\u5348"},DAY:{"0":"\u661f\u671f\u65e5",1:"\u661f\u671f\u4e00",2:"\u661f\u671f\u4e8c",3:"\u661f\u671f\u4e09",4:"\u661f\u671f\u56db",5:"\u661f\u671f\u4e94",6:"\u661f\u671f\u516d"},MONTH:{"0":"1\u6708",1:"2\u6708",2:"3\u6708", +3:"4\u6708",4:"5\u6708",5:"6\u6708",6:"7\u6708",7:"8\u6708",8:"9\u6708",9:"10\u6708",10:"11\u6708",11:"12\u6708"},SHORTDAY:{"0":"\u5468\u65e5",1:"\u5468\u4e00",2:"\u5468\u4e8c",3:"\u5468\u4e09",4:"\u5468\u56db",5:"\u5468\u4e94",6:"\u5468\u516d"},fullDate:"y\u5e74M\u6708d\u65e5EEEE",longDate:"y\u5e74M\u6708d\u65e5",medium:"yyyy-M-d ah:mm:ss",mediumDate:"yyyy-M-d",mediumTime:"ah:mm:ss","short":"yy-M-d ah:mm",shortDate:"yy-M-d",shortTime:"ah:mm"};m.SHORTMONTH=m.MONTH;Xa.date.locate=m};var s=avalon.modules= +{"ready!":{exports:avalon},avalon:{exports:avalon,state:2}};new function(){function b(b){return(b||"").replace(/[?#].*/,"")}function c(b){var c;try{a.b.c()}catch(d){c=d.stack,!c&&r.opera&&(c=(String(d).match(/of linked script \S+/g)||[]).join(" "))}if(c)return c=c.split(/[@ ]/g).pop(),c="("===c[0]?c.slice(1,-1):c.replace(/\s/,""),c.replace(/(:\d+)?:\d+$/i,"");c=(b?p:J).getElementsByTagName("script");for(var e=c.length,f;f=c[--e];)if((b||f.className===G)&&"interactive"===f.readyState)return f.className= f.src}function d(b,c){for(var e in b)if("\u53f8\u5f92\u6b63\u7f8e"===b[e]&&2!==s[e].state&&(e===c||d(s[e].deps,c)))return!0}function e(){var b=l.length,c;a:for(;c=l[--b];){c=s[c];var d=c.deps,f;for(f in d)if(O.call(d,f)&&2!==s[f].state)continue a;2!==c.state&&(l.splice(b,1),k(c.id,c.args,c.factory),e())}}function f(c,d,e){var f=b(c.src);c.onload=c.onreadystatechange=c.onerror=null;if(d||e&&!s[f].state)setTimeout(function(){J.removeChild(c);c=null}),v("debug: \u52a0\u8f7d "+f+" \u5931\u8d25"+d+" "+ !s[f].state);else return!0}function g(c,d,e,f){if("ready!"===c||s[c]&&2===s[c].state)return c;var g;c=c.replace(/^\w+!/,function(b){g=b.slice(0,-1);return""});g=g||"js";g=U[g]||y;"object"===typeof u.shim[c]&&(f=u.shim[c]);u.paths[c]&&(c=u.paths[c]);if(/^(\w+)(\d)?:.*/.test(c))e=c;else{d=d.substr(0,d.lastIndexOf("/"));var h=c.charAt(0);if("."!==h&&"/"!==h)e=n+c;else if("./"===c.slice(0,2))e=d+c.slice(1);else if(".."===c.slice(0,2))for(e=d+"/"+c;t.test(e);)e=e.replace(t,"");else"/"===h?e=c:avalon.error("\u4e0d\u7b26\u5408\u6a21\u5757\u6807\u8bc6\u89c4\u5219: "+ c)}c=b(e);(d=g.ext)&&c.slice(0-d.length)!==d&&(e+=d);u.nocache&&(e+=(-1===e.indexOf("?")?"?":"&")+(new Date-0));return g(e,f)}function h(b,c,d){var e=p.createElement("script");e.className=G;e[w?"onload":"onreadystatechange"]=function(){if(w||/loaded|complete/i.test(e.readyState)){var g=m.pop();g&&g.delay(c);d&&d();f(e,!1,!w)&&v("debug: \u5df2\u6210\u529f\u52a0\u8f7d "+b)}};e.onerror=function(){f(e,!0)};e.src=b;J.insertBefore(e,J.firstChild);v("debug: \u6b63\u51c6\u5907\u52a0\u8f7d "+b)}function k(b, diff --git a/avalon.modern.js b/avalon.modern.js index 29a82bb14..ffebedcee 100644 --- a/avalon.modern.js +++ b/avalon.modern.js @@ -3550,12 +3550,12 @@ } var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/, NUMBER_STRING = /^\d+$/ - var R_ISO8601_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/ + var riso8601= /^(\d{4})-?(\d+)-?(\d+)(?:T(\d+)(?::?(\d+)(?::?(\d+)(?:\.(\d+))?)?)?(Z|([+-])(\d+):?(\d+))?)?$/ // 1 2 3 4 5 6 7 8 9 10 11 function jsonStringToDate(string) { var match - if (match = string.match(R_ISO8601_STR)) { + if (match = string.match(riso8601)) { var date = new Date(0), tzHour = 0, tzMin = 0, @@ -3590,7 +3590,7 @@ var trimDate = date.trim() date = trimDate.replace(rfixYMD, function(a, b, c, d) { var array = d.length === 4 ? [d, b, c] : [b, c, d] - return array.join("/") + return array.join("-") }) date = jsonStringToDate(date) } diff --git a/avalon.modern.min.js b/avalon.modern.min.js index dcc26e999..c1ac79ad7 100644 --- a/avalon.modern.min.js +++ b/avalon.modern.min.js @@ -91,8 +91,8 @@ b.replace(e,function(b,c,d){b=d.charAt(0);return c+"="+b+"javascript:void(0)"+b} d,e){b=(b+"").replace(/[^0-9+\-Ee.]/g,"");b=!isFinite(+b)?0:+b;c=!isFinite(+c)?0:Math.abs(c);e=e||",";d=d||".";var f="",f=function(b,c){var d=Math.pow(10,c);return""+Math.round(b*d)/d},f=(c?f(b,c):""+Math.round(b)).split(".");3b&&(e="-",b=-b);for(b=""+b;b.length-e)g+=e;0===g&&-12===e&&(g=12);return b(g,d,f)}}function d(b,c){return function(d,e){var f=d["get"+b](),g=(c?"SHORT"+b:b).toUpperCase();return e[g][f]}}function e(b){var c;if(c=b.match(k)){b=new Date(0);var d=0,e=0,f=c[8]?b.setUTCFullYear:b.setFullYear,g=c[8]?b.setUTCHours:b.setHours;c[9]&&(d=parseInt(c[9]+c[10],10),e=parseInt(c[9]+c[11],10));f.call(b,parseInt(c[1],10),parseInt(c[2],10)-1,parseInt(c[3],10));d=parseInt(c[4]|| 0,10)-d;e=parseInt(c[5]||0,10)-e;f=parseInt(c[6]||0,10);c=Math.round(1E3*parseFloat("0."+(c[7]||0)));g.call(b,d,e,f,c)}return b}var f={yyyy:c("FullYear",4),yy:c("FullYear",2,0,!0),y:c("FullYear",1),MMMM:d("Month"),MMM:d("Month",!0),MM:c("Month",2,1),M:c("Month",1,1),dd:c("Date",2),d:c("Date",1),HH:c("Hours",2),H:c("Hours",1),hh:c("Hours",2,-12),h:c("Hours",1,-12),mm:c("Minutes",2),m:c("Minutes",1),ss:c("Seconds",2),s:c("Seconds",1),sss:c("Milliseconds",3),EEEE:d("Day"),EEE:d("Day",!0),a:function(b, -c){return 12>b.getHours()?c.AMPMS[0]:c.AMPMS[1]},Z:function(c){c=-1*c.getTimezoneOffset();return c=(0<=c?"+":"")+(b(Math[0b.getHours()?c.AMPMS[0]:c.AMPMS[1]},Z:function(c){c=-1*c.getTimezoneOffset();return c=(0<=c?"+":"")+(b(Math[0这是模板1

生成于{{ 1373021259229 | date("yyyy MM dd:HH:mm:ss")}}

生成于{{ "1373021259229" | date("yyyy MM dd:HH:mm:ss")}}

生成于{{ "2014-06-10 15:21:2" | date("yyyy!MM!dd:HH:mm:ss!")}}

- +

生成于{{ "2014-06-10T15:21:2" | date("yyyy!MM!dd:HH:mm:ss!")}}

值得注意的是,new Date可传的格式类型非常多,但不是所有浏览器都支持这么多,详看这里