forked from taylorhakes/fecha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fecha.strict.min.js
1 lines (1 loc) · 4.7 KB
/
fecha.strict.min.js
1
(function(e){"use strict";var n={};var t=/d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;var r="\\d\\d?";var u="\\d{3}";var o="\\d{4}";var a="[^\\s]+";var i=/\[([^]*?)\]/gm;var s=function(){};function f(e){return e.replace(/[|\\{()[^$+*?.-]/g,"\\$&")}function m(e,n){var t=[];for(var r=0,u=e.length;r<u;r++){t.push(e[r].substr(0,n))}return t}function d(e){return function(n,t,r){var u=r[e].indexOf(t.charAt(0).toUpperCase()+t.substr(1).toLowerCase());if(~u){n.month=u}}}function c(e,n){e=String(e);n=n||2;while(e.length<n){e="0"+e}return e}var l=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];var h=["January","February","March","April","May","June","July","August","September","October","November","December"];var M=m(h,3);var g=m(l,3);n.i18n={dayNamesShort:g,dayNames:l,monthNamesShort:M,monthNames:h,amPm:["am","pm"],DoFn:function e(n){return n+["th","st","nd","rd"][n%10>3?0:(n-n%10!==10)*n%10]}};var D={D:function(e){return e.getDate()},DD:function(e){return c(e.getDate())},Do:function(e,n){return n.DoFn(e.getDate())},d:function(e){return e.getDay()},dd:function(e){return c(e.getDay())},ddd:function(e,n){return n.dayNamesShort[e.getDay()]},dddd:function(e,n){return n.dayNames[e.getDay()]},M:function(e){return e.getMonth()+1},MM:function(e){return c(e.getMonth()+1)},MMM:function(e,n){return n.monthNamesShort[e.getMonth()]},MMMM:function(e,n){return n.monthNames[e.getMonth()]},YY:function(e){return String(e.getFullYear()).substr(2)},YYYY:function(e){return e.getFullYear()},h:function(e){return e.getHours()%12||12},hh:function(e){return c(e.getHours()%12||12)},H:function(e){return e.getHours()},HH:function(e){return c(e.getHours())},m:function(e){return e.getMinutes()},mm:function(e){return c(e.getMinutes())},s:function(e){return e.getSeconds()},ss:function(e){return c(e.getSeconds())},S:function(e){return Math.round(e.getMilliseconds()/100)},SS:function(e){return c(Math.round(e.getMilliseconds()/10),2)},SSS:function(e){return c(e.getMilliseconds(),3)},a:function(e,n){return e.getHours()<12?n.amPm[0]:n.amPm[1]},A:function(e,n){return e.getHours()<12?n.amPm[0].toUpperCase():n.amPm[1].toUpperCase()},ZZ:function(e){var n=e.getTimezoneOffset();return(n>0?"-":"+")+c(Math.floor(Math.abs(n)/60)*100+Math.abs(n)%60,4)}};var Y={D:[r,function(e,n){e.day=n}],Do:[r+a,function(e,n){e.day=parseInt(n,10)}],M:[r,function(e,n){e.month=n-1}],YY:[r,function(e,n){var t=new Date,r=+(""+t.getFullYear()).substr(0,2);e.year=""+(n>68?r-1:r)+n}],h:[r,function(e,n){e.hour=n}],m:[r,function(e,n){e.minute=n}],s:[r,function(e,n){e.second=n}],YYYY:[o,function(e,n){e.year=n}],S:["\\d",function(e,n){e.millisecond=n*100}],SS:["\\d{2}",function(e,n){e.millisecond=n*10}],SSS:[u,function(e,n){e.millisecond=n}],d:[r,s],ddd:[a,s],MMM:[a,d("monthNamesShort")],MMMM:[a,d("monthNames")],a:[a,function(e,n,t){var r=n.toLowerCase();if(r===t.amPm[0]){e.isPm=false}else if(r===t.amPm[1]){e.isPm=true}}],ZZ:["[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d",function(e,n){var t=(n+"").match(/([\+\-]|\d\d)/gi),r;if(t){r=+(t[1]*60)+parseInt(t[2],10);e.timezoneOffset=t[0]==="+"?r:-r}}]};Y.dd=Y.d;Y.dddd=Y.ddd;Y.DD=Y.D;Y.mm=Y.m;Y.hh=Y.H=Y.HH=Y.h;Y.MM=Y.M;Y.ss=Y.s;Y.A=Y.a;n.masks={default:"ddd MMM DD YYYY HH:mm:ss",shortDate:"M/D/YY",mediumDate:"MMM D, YYYY",longDate:"MMMM D, YYYY",fullDate:"dddd, MMMM D, YYYY",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"};n.format=function(e,r,u){var o=u||n.i18n;if(typeof e==="number"){e=new Date(e)}if(Object.prototype.toString.call(e)!=="[object Date]"||isNaN(e.getTime())){throw new Error("Invalid Date in fecha.format")}r=n.masks[r]||r||n.masks["default"];var a=[];r=r.replace(i,function(e,n){a.push(n);return"??"});r=r.replace(t,function(n){return n in D?D[n](e,o):n.slice(1,n.length-1)});return r.replace(/\?\?/g,function(){return a.shift()})};n.parse=function(e,r,u){var o=u||n.i18n;if(typeof r!=="string"){throw new Error("Invalid format in fecha.parse")}r=n.masks[r]||r;if(e.length>1e3){return false}var a={};var i=[];var s=f(r).replace(t,function(e){if(Y[e]){var n=Y[e];i.push(n[1]);return"("+n[0]+")"}return e});var m=e.match(new RegExp(s,"i"));if(!m){return false}for(var d=1;d<m.length;d++){i[d-1](a,m[d],o)}var c=new Date;if(a.isPm===true&&a.hour!=null&&+a.hour!==12){a.hour=+a.hour+12}else if(a.isPm===false&&+a.hour===12){a.hour=0}var l;if(a.timezoneOffset!=null){a.minute=+(a.minute||0)-+a.timezoneOffset;l=new Date(Date.UTC(a.year||c.getFullYear(),a.month||0,a.day||1,a.hour||0,a.minute||0,a.second||0,a.millisecond||0))}else{l=new Date(a.year||c.getFullYear(),a.month||0,a.day||1,a.hour||0,a.minute||0,a.second||0,a.millisecond||0)}return l};if(typeof module!=="undefined"&&module.exports){module.exports=n}else if(typeof define==="function"&&define.amd){define(function(){return n})}else{e.fecha=n}})(this);