UNPKG

moment-biz

Version:

Handle business days & weekends over multiple years

2 lines 6.16 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("moment")):"function"==typeof define&&define.amd?define("moment-biz",["moment"],e):"object"==typeof exports?exports["moment-biz"]=e(require("moment")):t["moment-biz"]=e(t.moment)}(window,function(t){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var a=e[n]={i:n,l:!1,exports:{}};return t[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var a in t)r.d(n,a,function(e){return t[e]}.bind(null,a));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(e,r){e.exports=t},function(t,e,r){"use strict";var n=r(0);r(2),r(3),r(5),t.exports.moment=n,t.exports.utils=r(6)},function(t,e,r){"use strict";var n=r(0);t.exports=n.easter=function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:n().year();if(t.cache||(t.cache={}),isNaN(+e))throw new TypeError("Value must be a number.");if(275760<e||e<-271820)throw new RangeError("Value must be between -271820 and 275760 due to technical limitations of Date constructor.");if((e=Math.floor(e))in t.cache)return n(t.cache[e]);var r=Math.floor(e/100),a=e-19*Math.floor(e/19),o=Math.floor((r-17)/25),i=r-Math.floor(r/4)-Math.floor((r-o)/3)+19*a+15;i-=30*Math.floor(i/30),i-=Math.floor(i/28)*(1-Math.floor(i/28)*Math.floor(29/(i+1))*Math.floor((21-a)/11));var c=e+Math.floor(e/4)+i+2-r+Math.floor(r/4),l=i-(c-=7*Math.floor(c/7)),f=3+Math.floor((l+40)/44),u=l+28-31*Math.floor(f/4);return t.cache[e]=n({year:e,month:f-1,day:u}),n(t.cache[e])},n.fn.isEaster=function(){return n.easter(this.year()).dayOfYear()===this.dayOfYear()}},function(t,e,r){"use strict";(function(t){var e=r(0),n=new Function("try { return this === global; } catch(e) { return false; } "),a={};function o(o){var i=o.locale;n()&&(o.locale=function(n){if(!arguments.length||a[n]||2!==n.split("-").length)return i.call.apply(i,[this].concat(Array.prototype.slice.call(arguments)));var o=e.locale();try{var c=r(!function(){var t=new Error("Cannot find module 'path'");throw t.code="MODULE_NOT_FOUND",t}());r(4)(c.join(t,"../locale",n)),a[n]=!0,e.locale(o)}finally{return i.call.apply(i,[this].concat(Array.prototype.slice.call(arguments)))}})}o(e),o(e.fn)}).call(this,"/")},function(t,e){function r(t){var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e}r.keys=function(){return[]},r.resolve=r,(t.exports=r).id=4},function(t,e,r){"use strict";var n=r(0);function a(t,e,r,a){for(var o=this,i=arguments.length,c=new Array(4<i?i-4:0),l=4;l<i;l++)c[l-4]=arguments[l];if(r<0)return this["add"===e?"subtract":"add"].apply(this,[-r,a].concat(c));var f=n(this)["add"===e?"startOf":"endOf"]("day"),u=this.localeData()._config.weekends||[0,6],s=Math.floor(r/(7-u.length));t.call(this,r+s*u.length,"day");var d=function(t){return function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}(Array(r%(7-u.length)).keys()).reduce(function(t,r){return t+(0<=u.indexOf((o.day()+("add"===e?7-r:r))%7))},0);if(d)for(t.call(this,d,"day");this.isWeekend();)t.call(this,1,"day");for(var y=n(this)["add"===e?"endOf":"startOf"]("day"),h=function(t){!t.isValid()||t.isWeekend()||"add"===e&&(t<=f||y<t)||"subtract"===e&&(f<t||t<=y)||(o[e](1,"businessday"),y=n(o)["add"===e?"endOf":"startOf"]("day"))},p=f.year();p<=this.year();++p)n.getHolidays(p,this.locale()).forEach(h);return this}var o=n.fn.add;n.fn.add=function(t,e){return"businessday"!==e&&"businessdays"!==e?o.call.apply(o,[this].concat(Array.prototype.slice.call(arguments))):a.call.apply(a,[this,o,"add"].concat(Array.prototype.slice.call(arguments)))};var i=n.fn.subtract;n.fn.subtract=function(t,e){return"businessday"!==e&&"businessdays"!==e?i.call.apply(i,[this].concat(Array.prototype.slice.call(arguments))):a.call.apply(a,[this,i,"subtract"].concat(Array.prototype.slice.call(arguments)))}},function(t,e,r){"use strict";var n=r(0),a=t.exports;n.getHolidays=function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:n().year(),e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:n.locale(),r=n().locale(e).localeData(),a=r._config.holidayFormat||"DD-MM";return(r._config.holidays||[]).map(function(r){return(r instanceof Function?r(t):n(r,a).year(t)).locale(e)})},n.fn.getHolidaysOfCurrentYear=function(){return n.getHolidays(this.year(),this.locale())},n.fn.isWeekend=function(){return 0<=(this.localeData()._config.weekends||[0,6]).indexOf(this.day())},n.fn.isHoliday=function(){var t=this;return function(t,e){for(var r=!1,n=0;!r&&n<t.length;++n)r=e(t[n]);return r}(this.getHolidaysOfCurrentYear(),function(e){return e.dayOfYear()===t.dayOfYear()})},n.fn.isFreeDay=function(){return this.isWeekend()||this.isHoliday()},n.fn.isBusinessDay=function(){return!this.isFreeDay()},a.adjustIfWELikeInUSA=function(t){return t=n(t,"DD-MM"),function(e){return t.year(e).day()%6?n(t):n(t).add(0===t.day()?1:-1,"day")}},a.xxDayOfMonth=function(t,e,r){var a=n().startOf("day").date(1).month(r-1);return function(r){var o=n(a).year(r),i=n(o);return o.day(e),o.add(7*(t+(o<i)-1),"day"),o}},a.lastDayOfMonth=function(t,e){var r=n().startOf("day").month(e-1);return function(a){var o=n(r).year(a);return o.endOf("month").startOf("day").day(t),o.month()!==e-1&&o.subtract(7,"days"),o}}}])}); //# sourceMappingURL=moment-biz.min.js.map