/*! * UltraDate.js v2.2.2 (http://hrdaya.github.io/UltraDate.js/) * * Copyright 2015 yu-ki higa (https://github.com/hrdaya) * Licensed under MIT (https://github.com/hrdaya/UltraDate.js/blob/master/LICENSE) */ function UltraDate(a,b,c,d,e,f,g){"use strict";var h=function(a){return a=parseInt(a,10),isNaN(a)?0:a};if(this instanceof UltraDate)switch(this.__value=void 0,arguments.length){case 0:this.__value=new Date;break;case 1:this.__value=new Date(a);break;default:this.__value=new Date(h(a),h(b),h(c),h(d),h(e),h(f),h(g))}else switch(arguments.length){case 0:return new UltraDate;case 1:return new UltraDate(a);default:return new UltraDate(a,b,c,d,e,f,g)}}!function(){"use strict";var a="yyyy/MM/dd",b="def",c=[],d={def:{get:function(){return{}}}},e={def:{firstYear:null,longDay:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDay:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],longMonth:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonth:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],smallNoon:["am","pm"],largeNoon:["AM","PM"],era:function(a){return{longName:"A.D.",shortName:"AD",alphaName:"A",year:a.getFullYear()}},eraStrict:function(a){return this.era(a)}}},f=function(a){return a=parseInt(a,10),isNaN(parseInt(a,10))?0:a},g=function(a,b){return b=parseInt(b,10),b=isNaN(b)?2:b,2>b?a:(new Array(b).join("0")+a).slice(-1*b)},h=function(a){return a=void 0===a?new UltraDate:new UltraDate(a)},i=function(a,b,c){b=parseInt(b,10),(isNaN(b)||0>b&&b>6)&&(b=4),b=0===b?0:7-b;var d=new Date(c);d.setHours(0,0,0,0);var e=d.getDay();a=parseInt(a,10),(isNaN(a)||0>a&&a>6)&&(a=1),0!==a&&(e-=a,0>e&&(e+=7)),e=7-(e+1);var f=new Date(c.getFullYear(),0,1),g=(d-f)/864e5+1+b+e;return 0===b?Math.ceil(g/7):Math.floor(g/7)};UltraDate.now=function(){return Date.now?Date.now():(new Date).getTime()},UltraDate.parse=function(a){return Date.parse(a)},UltraDate.UTC=function(){return Date.UTC.apply(null,[].slice.apply(arguments))},UltraDate.getISOLastWeekNum=function(a){a=void 0===a?(new Date).getFullYear():f(a);var b=new UltraDate(a,11,31);return b.getISODay()<4?b.addDate(-1*b.getISODay()).getISOWeek():b.getISOWeek()},UltraDate.getUSLastWeekNum=function(a){return a=void 0===a?(new Date).getFullYear():f(a),new UltraDate(a,11,31).getUSWeek()},UltraDate.getHolidays=function(a,c){return a=void 0===a?(new Date).getFullYear():f(a),c=c?c:b,d.hasOwnProperty(c)?d[c].get(a):d.def.get(a)},UltraDate.getDefaultFormat=function(){return a},UltraDate.getDuplicate=function(){return c},UltraDate.setFormatOption=function(a,b){if("string"!=typeof a||"def"===a||""===a||"[object Object]"!==Object.prototype.toString.call(b))throw new Error("Data type of the argument is incorrect");e.hasOwnProperty(a)||(e[a]={}),b.hasOwnProperty("era")&&!b.hasOwnProperty("eraStrict")&&(b.eraStrict=b.era);for(var c=Object.keys(e.def),d=0,f=c.length;f>d;d++)e[a][c[d]]=b.hasOwnProperty(c[d])?b[c[d]]:e.def[c[d]];return this},UltraDate.setHolidayOption=function(a,b){if("string"!=typeof a||"def"===a||""===a||"[object Object]"!==Object.prototype.toString.call(b))throw new Error("Data type of the argument is incorrect");if(!b.hasOwnProperty("get"))throw new Error("get() does not exist");if("[object Function]"!==Object.prototype.toString.call(b.get))throw new Error("get is not Function");return d[a]=b,this},UltraDate.setDefaultLocale=function(a){if("string"!=typeof a||""===a)throw new Error("Data type of the argument is incorrect");return b=a,this},UltraDate.prototype={constructor:UltraDate,copy:function(){return new UltraDate(this.__value)},format:function(a,c,d){if("string"!=typeof a)return a;d="string"!=typeof d||""===d?b:d;var f=e.hasOwnProperty(d)?e[d]:e.def,h=c===!0?f.eraStrict(this):f.era(this),i=this.getHours()<12?0:1,j={yyyy:this.getFullYear(),yy:g(this.getFullYear()),eeee:g(h.year,4),eee:g(h.year,3),ee:g(h.year),e:h.year,EEEE:1===h.year&&f.firstYear||g(h.year,4),EEE:1===h.year&&f.firstYear||g(h.year,3),EE:1===h.year&&f.firstYear||g(h.year),E:1===h.year&&f.firstYear||h.year,ggg:h.longName,gg:h.shortName,g:h.alphaName,MMMM:f.longMonth[this.getMonth()],MMM:f.shortMonth[this.getMonth()],MM:g(this.getRealMonth()),M:this.getRealMonth(),dddd:this.getOrdinalDate(),ddd:g(this.getOrdinalDate(),3),dd:g(this.getDate()),d:this.getDate(),HH:g(this.getHours()),H:this.getHours(),hh:g(this.getHours()-12*i),h:this.getHours()-12*i,mm:g(this.getMinutes()),m:this.getMinutes(),ss:g(this.getSeconds()),s:this.getSeconds(),fff:g(this.getMilliseconds(),3),f:this.getMilliseconds(),TT:f.largeNoon[i],tt:f.smallNoon[i],www:this.getDayCountsInMonth(),ww:g(this.getISOWeek()),w:this.getISOWeek(),WW:g(this.getUSWeek()),W:this.getUSWeek(),DDD:f.longDay[this.getDay()],DD:f.shortDay[this.getDay()],D:this.getISODay()},k="_____-----_____-----_____-----_____-----_____-----_____";a=a.replace(/("")/g,k);for(var l=a.split('"'),m=new RegExp("("+Object.keys(j).join("|")+")","g"),n=0,o=l.length;o>n;n+=2)l[n]=l[n].replace(m,function(a){return j[a]});return a=l.join(""),a.replace(new RegExp("("+k+")","g"),'"')},addYear:function(a){return this.setFullYear(this.getFullYear()+f(a)),this},addMonth:function(a){return this.setMonth(this.getMonth()+f(a)),this},addDate:function(a){return this.setDate(this.getDate()+f(a)),this},addHours:function(a){return this.setHours(this.getHours()+f(a)),this},addMinutes:function(a){return this.setMinutes(this.getMinutes()+f(a)),this},addSeconds:function(a){return this.setSeconds(this.getSeconds()+f(a)),this},addMilliseconds:function(a){return this.setMilliseconds(this.getMilliseconds()+f(a)),this},setRealMonth:function(a){return this.setMonth(f(a)-1),this},setDayCountsInMonth:function(a,b){if(a=parseInt(a,10),b=parseInt(b,10),isNaN(a)||isNaN(b)||0>b&&b>6)throw new Error("Data type of the argument is incorrect");this.setDate(1);var c=b-this.getDay()+1;return c+=1>c?7*a:7*(a-1),this.setDate(c),this},setISOWeekDay:function(a,b,c){if(b=parseInt(b,10),isNaN(b)||0>b&&b>6)throw new Error("Data type of the argument is incorrect");c=void 0===c?this.getFullYear():f(c),this.setFullYear(c,0,1),b=0===b?6:b-1;var d=this.getDay()<2||4b&&b>6)throw new Error("Data type of the argument is incorrect");c=void 0===c?this.getFullYear():f(c),this.setFullYear(c,0,1);var d=0===this.getDay()?0:1;return this.setDayCountsInMonth(0,0).addDate(7*(f(a)-d)+b),this},setFirstDate:function(a){return this.clearTime().setFullYear(this.getFullYear(),this.getMonth()+f(a),1),this},setLastDate:function(a){return this.setFirstDate().addMonth(f(a)+1).setDate(0),this},setBeforeWeekday:function(a,b){for(;!this.isWeekday(a,b);)this.addDate(-1);return this},setAfterWeekday:function(a,b){for(;!this.isWeekday(a,b);)this.addDate(1);return this},setOrdinalDate:function(a){return this.setFullYear(this.getFullYear(),0,0),this.addDate(f(a)),this},setRoundingTime:function(a,b){a=f(a);var c=[5,10,15,30,60];if(c.indexOf(a)<0)throw new Error("Data type of the argument is incorrect");this.addMilliseconds(this.getTime()%6e4*-1);var d=this.getTime()%(6e4*a);switch(this.setMilliseconds(-1*d),f(b)){case 1:0!==d&&this.addMinutes(a);break;case 2:2*d>=6e4*a&&this.addMinutes(a)}return this},clearTime:function(){return this.setHours(0,0,0,0),this},getAge:function(a){var b=void 0===a?new UltraDate:new UltraDate(a),c=this.copy().clearTime(),d=b.clearTime().getFullYear()-c.clearTime().getFullYear();return c.setFullYear(b.getFullYear()),c>b?d-=1:d},getRealMonth:function(){return this.getMonth()+1},getDayCountsInMonth:function(){return Math.ceil(this.getDate()/7)},getISOWeekWithYear:function(){var a={year:this.getFullYear(),week:this.getISOWeek()};return 0===a.week?(a.year-=1,a.week=UltraDate.getISOLastWeekNum(a.year)):a.week>UltraDate.getISOLastWeekNum(a.year)&&(a.year+=1,a.week=1),a},getISOWeek:function(){return i(1,4,this)},getUSWeek:function(){return i(0,0,this)},getISODay:function(){return 0===this.getDay()?7:this.getDay()},getOrdinalDate:function(){var a=new Date(this.getFullYear(),0,0),b=this.copy().clearTime();return(b-a)/864e5},getLastDate:function(a){return this.copy().setLastDate(a).getDate()},getHoliday:function(b){var c=UltraDate.getHolidays(this.getFullYear(),b),d=this.format(a);return c.hasOwnProperty(d)?c[d]:""},diff:function(a){a=h(a);var b=a.getTime()-this.getTime(),c=b>=0;c||(b*=-1);var d=1e3,e=60*d,f=60*e,g=24*f,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;return i=b%d,m=b-i,m>0&&(j=m%e,n=m-j),n>0&&(k=n%f,o=n-k),o>0&&(l=o%g,p=o-l),{after:c,day:p/g,hour:l/f,minute:k/e,second:j/d,ms:i}},diffMonth:function(a){return a=h(a),12*a.getFullYear()+a.getMonth()-(12*this.getFullYear()+this.getMonth())},diffDate:function(a){a=h(a);var b=a.clearTime().getTime()-this.copy().clearTime().getTime();return b/864e5},isLeapYear:function(){var a=this.getFullYear();return a%4===0&&a%100!==0||a%400===0},isDayCountsInMonth:function(a,b){return this.getDayCountsInMonth()===f(a)&&this.getDay()===f(b)},isISOWeekDay:function(a,b){return this.getISOWeek()===f(a)&&this.getDay()===f(b)},isUSWeekDay:function(a,b){return this.getUSWeek()===f(a)&&this.getDay()===f(b)},isISOWeek:function(a){return this.getISOWeek()===f(a)},isUSWeek:function(a){return this.getUSWeek()===f(a)},isWeekday:function(a,b){switch(f(a)){case 0:return 6!==this.getDay()&&0!==this.getDay()&&!this.isHoliday(b);case 1:return 6!==this.getDay()&&0!==this.getDay();case 2:return 0!==this.getDay()&&!this.isHoliday(b);case 3:return 0!==this.getDay();case 4:return!this.isHoliday(b)}},isSameDate:function(a){return this.copy().clearTime().getTime()===h(a).clearTime().getTime()},isBeforeDate:function(a){return this.copy().clearTime()h(a).clearTime()},isBetween:function(a,b,c){return a=h(a),b=h(b),c===!0&&(a.clearTime(),b.clearTime().addDate(1).addMilliseconds(-1)),this>=a&&b>=this},isHoliday:function(b){var c=UltraDate.getHolidays(this.getFullYear(),b);return c.hasOwnProperty(this.format(a))},isValid:function(){return!isNaN(this.__value.getTime())}};for(var j=Object.getOwnPropertyNames(Date.prototype),k=0,l=j.length;l>k;k++)!function(a){"constructor"!==a&&(UltraDate.hasOwnProperty(a)&&c.push(a),UltraDate.prototype[a]=function(){return Date.prototype[a].apply(this.__value,Array.prototype.slice.call(arguments))})}(j[k])}();