1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-10 11:20:19 +00:00
musix-oss/node_modules/date-and-time/date-and-time.min.js
2019-10-10 16:43:04 +03:00

16 lines
5.7 KiB
JavaScript

/*
date-and-time.js (c) KNOWLEDGECODE | MIT
*/
(function(p){var d={},l={},g={},h="en",q={MMMM:"January February March April May June July August September October November December".split(" "),MMM:"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),dddd:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),ddd:"Sun Mon Tue Wed Thu Fri Sat".split(" "),dd:"Su Mo Tu We Th Fr Sa".split(" "),A:["a.m.","p.m."]},r={YYYY:function(a){return("000"+a.getFullYear()).slice(-4)},YY:function(a){return("0"+a.getFullYear()).slice(-2)},
Y:function(a){return""+a.getFullYear()},MMMM:function(a){return this.res.MMMM[a.getMonth()]},MMM:function(a){return this.res.MMM[a.getMonth()]},MM:function(a){return("0"+(a.getMonth()+1)).slice(-2)},M:function(a){return""+(a.getMonth()+1)},DD:function(a){return("0"+a.getDate()).slice(-2)},D:function(a){return""+a.getDate()},HH:function(a){return("0"+a.getHours()).slice(-2)},H:function(a){return""+a.getHours()},A:function(a){return this.res.A[11<a.getHours()|0]},hh:function(a){return("0"+(a.getHours()%
12||12)).slice(-2)},h:function(a){return""+(a.getHours()%12||12)},mm:function(a){return("0"+a.getMinutes()).slice(-2)},m:function(a){return""+a.getMinutes()},ss:function(a){return("0"+a.getSeconds()).slice(-2)},s:function(a){return""+a.getSeconds()},SSS:function(a){return("00"+a.getMilliseconds()).slice(-3)},SS:function(a){return("0"+(a.getMilliseconds()/10|0)).slice(-2)},S:function(a){return""+(a.getMilliseconds()/100|0)},dddd:function(a){return this.res.dddd[a.getDay()]},ddd:function(a){return this.res.ddd[a.getDay()]},
dd:function(a){return this.res.dd[a.getDay()]},Z:function(a){a=a.utc?0:a.getTimezoneOffset()/.6;return(0<a?"-":"+")+("000"+Math.abs(a-a%100*.4)).slice(-4)},post:function(a){return a}},t={YYYY:function(a){return this.exec(/^\d{1,4}/,a)},YY:function(a){a=this.exec(/^\d\d?/,a);a.value+=70>a.value?2E3:100>a.value?1900:0;return a},MMMM:function(a){a=this.find(this.res.MMMM,a);a.value++;return a},MMM:function(a){a=this.find(this.res.MMM,a);a.value++;return a},MM:function(a){return this.exec(/^\d\d/,a)},
M:function(a){return this.exec(/^\d\d?/,a)},DD:function(a){return this.exec(/^\d\d/,a)},D:function(a){return this.exec(/^\d\d?/,a)},HH:function(a){return this.exec(/^\d\d/,a)},H:function(a){return this.exec(/^\d\d?/,a)},A:function(a){return this.find(this.res.A,a)},hh:function(a){return this.exec(/^\d\d/,a)},h:function(a){return this.exec(/^\d\d?/,a)},mm:function(a){return this.exec(/^\d\d/,a)},m:function(a){return this.exec(/^\d\d?/,a)},ss:function(a){return this.exec(/^\d\d/,a)},s:function(a){return this.exec(/^\d\d?/,
a)},SSS:function(a){return this.exec(/^\d{1,3}/,a)},SS:function(a){a=this.exec(/^\d\d?/,a);a.value*=10;return a},S:function(a){a=this.exec(/^\d/,a);a.value*=100;return a},h12:function(a,c){return(12===a?0:a)+12*c},exec:function(a,c){var b=(a.exec(c)||[""])[0];return{value:b|0,length:b.length}},find:function(a,c){for(var b=-1,d=0,e=0,k=a.length,f;e<k;e++)f=a[e],!c.indexOf(f)&&f.length>d&&(b=e,d=f.length);return{value:b,length:d}},pre:function(a){return a}},n=function(a,c,b){var d=function(a,b,c){var d=
function(a){a&&(this.res=a)};d.prototype=a;d.prototype.constructor=d;a=new d(c);for(var e in b||{})b.hasOwnProperty(e)&&(c=b[e],a[e]=c.slice?c.slice():c);return a},e={res:d(c.res,b.res)};e.formatter=d(c.formatter,b.formatter,e.res);e.parser=d(c.parser,b.parser,e.res);l[a]=e};d.format=function(a,c,b){var m=d.addMinutes(a,b?a.getTimezoneOffset():0),e=l[h].formatter;m.utc=b;return c.replace(/\[[^\[\]]*]|\[.*\][^\[]*\]|([A-Za-z])\1*|./g,function(a){return e[a]?e.post(e[a](m,c)):a.replace(/\[(.*)]/,"$1")})};
d.preparse=function(a,c){var b=l[h].parser,d=/([A-Za-z])\1*|./g,e,k=0,f={Y:1970,M:1,D:1,H:0,A:0,h:0,m:0,s:0,S:0,_index:0,_length:0,_match:0};a=b.pre(a);for(c=c.replace(/\[[^\[\]]*]|\[.*\][^\[]*\]/g,function(a){return a.replace(/./g," ").slice(2)});e=d.exec(c);)if(e=e[0],b[e]){var g=b[e](a.slice(k),c);if(!g.length)break;k+=g.length;f[e.charAt(0)]=g.value;f._match++}else if(e===a.charAt(k)||" "===e)k++;else break;f.H=f.H||b.h12(f.h,f.A);f._index=k;f._length=a.length;return f};d.isValid=function(a,c){var b=
"string"===typeof a?d.preparse(a,c):a,g=[31,28+d.isLeapYear(b.Y)|0,31,30,31,30,31,31,30,31,30,31][b.M-1];return!(1>b._index||1>b._length||b._index-b._length||1>b._match||1>b.Y||9999<b.Y||1>b.M||12<b.M||1>b.D||b.D>g||23<b.H||0>b.H||59<b.m||0>b.m||59<b.s||0>b.s||999<b.S||0>b.S)};d.parse=function(a,c,b){a=d.preparse(a,c);return d.isValid(a)?(a.M-=100>a.Y?22801:1,b=b?new Date(Date.UTC(a.Y,a.M,a.D,a.H,a.m,a.s,a.S)):new Date(a.Y,a.M,a.D,a.H,a.m,a.s,a.S)):new Date(NaN)};d.addYears=function(a,c){return d.addMonths(a,
12*c)};d.addMonths=function(a,c){var b=new Date(a.getTime());b.setMonth(b.getMonth()+c);return b};d.addDays=function(a,c){var b=new Date(a.getTime());b.setDate(b.getDate()+c);return b};d.addHours=function(a,c){return d.addMilliseconds(a,36E5*c)};d.addMinutes=function(a,c){return d.addMilliseconds(a,6E4*c)};d.addSeconds=function(a,c){return d.addMilliseconds(a,1E3*c)};d.addMilliseconds=function(a,c){return new Date(a.getTime()+c)};d.subtract=function(a,c){var b=a.getTime()-c.getTime();return{toMilliseconds:function(){return b},
toSeconds:function(){return b/1E3|0},toMinutes:function(){return b/6E4|0},toHours:function(){return b/36E5|0},toDays:function(){return b/864E5|0}}};d.isLeapYear=function(a){return!(a%4)&&!!(a%100)||!(a%400)};d.isSameDay=function(a,c){return d.format(a,"YYYYMMDD")===d.format(c,"YYYYMMDD")};d.locale=function(a,c){c?n(a,{res:q,formatter:r,parser:t},c):a&&(h=a);return h};d.extend=function(a){n(h,l[h],a)};d.plugin=function(a,c){g[a]=g[a]||c;!c&&g[a]&&d.extend(g[a])};d.locale(h,{});"object"===typeof module&&
"object"===typeof module.exports?module.exports=d:"function"===typeof define&&define.amd?define([],function(){return d}):p.date=d})(this);