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=arguments.length>0&&void 0!==arguments[0]?arguments[0]:n().year();if(t.cache||(t.cache={}),isNaN(+e))throw new TypeError("Value must be a number.");if(e>275760||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,r.id=4},function(t,e,r){"use strict";function n(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")}()}var a=r(0);function o(t,e,r,o){for(var i=this,c=arguments.length,l=new Array(c>4?c-4:0),f=4;f<c;f++)l[f-4]=arguments[f];if(r<0)return this["add"===e?"subtract":"add"].apply(this,[-r,o].concat(l));var u=a(this)["add"===e?"startOf":"endOf"]("day"),s=this.localeData()._config.weekends||[0,6],d=Math.floor(r/(7-s.length));t.call(this,r+d*s.length,"day");var y=n(Array(r%(7-s.length)).keys()).reduce(function(t,r){return t+(s.indexOf((i.day()+("add"===e?7-r:r))%7)>=0)},0);if(y)for(t.call(this,y,"day");this.isWeekend();)t.call(this,1,"day");for(var h=a(this)["add"===e?"endOf":"startOf"]("day"),p=function(t){!t.isValid()||t.isWeekend()||"add"===e&&(t<=u||t>h)||"subtract"===e&&(t>u||t<=h)||(i[e](1,"businessday"),h=a(i)["add"===e?"endOf":"startOf"]("day"))},m=u.year();m<=this.year();++m)a.getHolidays(m,this.locale()).forEach(p);return this}var i=a.fn.add;a.fn.add=function(t,e){return"businessday"!==e&&"businessdays"!==e?i.call.apply(i,[this].concat(Array.prototype.slice.call(arguments))):o.call.apply(o,[this,i,"add"].concat(Array.prototype.slice.call(arguments)))};var c=a.fn.subtract;a.fn.subtract=function(t,e){return"businessday"!==e&&"businessdays"!==e?c.call.apply(c,[this].concat(Array.prototype.slice.call(arguments))):o.call.apply(o,[this,c,"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=arguments.length>0&&void 0!==arguments[0]?arguments[0]:n().year(),e=arguments.length>1&&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(this.localeData()._config.weekends||[0,6]).indexOf(this.day())>=0},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],n,t);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.js.map