moment-biz
Version:
Handle business days & weekends over multiple years
2 lines • 6.94 kB
JavaScript
!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 n(r){if(e[r])return e[r].exports;var a=e[r]={i:r,l:!1,exports:{}};return t[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var a in t)n.d(r,a,function(e){return t[e]}.bind(null,a));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(e,n){e.exports=t},function(t,e,n){"use strict";var r=n(0);n(4),n(5),n(7),t.exports.moment=r,t.exports.utils=n(8)},function(t,e,n){n(3),n(9),t.exports=n(1)},function(t,e,n){var r=n(0),a=n(1).utils;r.defineLocale("en-US",{parentLocale:"en",weekends:[0,6],holidays:[a.adjustIfWELikeInUSA("01-01"),a.xxDayOfMonth(3,1,1),function(t){return t%4==1?r("20-01","DD-MM").year(t):r.invalid()},a.xxDayOfMonth(3,1,2),a.lastDayOfMonth(1,5),a.adjustIfWELikeInUSA("04-07"),a.xxDayOfMonth(1,1,9),a.xxDayOfMonth(2,1,10),a.adjustIfWELikeInUSA("11-11"),a.xxDayOfMonth(4,4,11),"25-12"]})},function(t,e,n){"use strict";var r=n(0);t.exports=r.easter=function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:r().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 r(t.cache[e]);var n=Math.floor(e/100),a=e-19*Math.floor(e/19),o=Math.floor((n-17)/25),i=n-Math.floor(n/4)-Math.floor((n-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-n+Math.floor(n/4),f=i-(c-=7*Math.floor(c/7)),l=3+Math.floor((f+40)/44),u=f+28-31*Math.floor(l/4);return t.cache[e]=r({year:e,month:l-1,day:u}),r(t.cache[e])},r.fn.isEaster=function(){return r.easter(this.year()).dayOfYear()===this.dayOfYear()}},function(t,e,n){"use strict";(function(t){var e=n(0),r=new Function("try { return this === global; } catch(e) { return false; } "),a={};function o(o){var i=o.locale;r()&&(o.locale=function(r){if(!arguments.length||a[r]||2!==r.split("-").length)return i.call.apply(i,[this].concat(Array.prototype.slice.call(arguments)));var o=e.locale();try{var c=n(!function(){var t=new Error("Cannot find module 'path'");throw t.code="MODULE_NOT_FOUND",t}());n(6)(c.join(t,"../locale",r)),a[r]=!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 n(t){var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e}n.keys=function(){return[]},n.resolve=n,(t.exports=n).id=6},function(t,e,n){"use strict";var r=n(0);function a(t,e,n,a){for(var o=this,i=arguments.length,c=new Array(4<i?i-4:0),f=4;f<i;f++)c[f-4]=arguments[f];if(n<0)return this["add"===e?"subtract":"add"].apply(this,[-n,a].concat(c));var l=r(this)["add"===e?"startOf":"endOf"]("day"),u=this.localeData()._config.weekends||[0,6],s=Math.floor(n/(7-u.length));t.call(this,n+s*u.length,"day");var d=function(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(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(n%(7-u.length)).keys()).reduce(function(t,n){return t+(0<=u.indexOf((o.day()+("add"===e?7-n:n))%7))},0);if(d)for(t.call(this,d,"day");this.isWeekend();)t.call(this,1,"day");for(var y=r(this)["add"===e?"endOf":"startOf"]("day"),h=function(t){!t.isValid()||t.isWeekend()||"add"===e&&(t<=l||y<t)||"subtract"===e&&(l<t||t<=y)||(o[e](1,"businessday"),y=r(o)["add"===e?"endOf":"startOf"]("day"))},p=l.year();p<=this.year();++p)r.getHolidays(p,this.locale()).forEach(h);return this}var o=r.fn.add;r.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=r.fn.subtract;r.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,n){"use strict";var r=n(0),a=t.exports;r.getHolidays=function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:r().year(),e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:r.locale(),n=r().locale(e).localeData(),a=n._config.holidayFormat||"DD-MM";return(n._config.holidays||[]).map(function(n){return(n instanceof Function?n(t):r(n,a).year(t)).locale(e)})},r.fn.getHolidaysOfCurrentYear=function(){return r.getHolidays(this.year(),this.locale())},r.fn.isWeekend=function(){return 0<=(this.localeData()._config.weekends||[0,6]).indexOf(this.day())},r.fn.isHoliday=function(){var t=this;return function(t,e){for(var n=!1,r=0;!n&&r<t.length;++r)n=e(t[r]);return n}(this.getHolidaysOfCurrentYear(),function(e){return e.dayOfYear()===t.dayOfYear()})},r.fn.isFreeDay=function(){return this.isWeekend()||this.isHoliday()},r.fn.isBusinessDay=function(){return!this.isFreeDay()},a.adjustIfWELikeInUSA=function(t){return t=r(t,"DD-MM"),function(e){return t.year(e).day()%6?r(t):r(t).add(0===t.day()?1:-1,"day")}},a.xxDayOfMonth=function(t,e,n){var a=r().startOf("day").date(1).month(n-1);return function(n){var o=r(a).year(n),i=r(o);return o.day(e),o.add(7*(t+(o<i)-1),"day"),o}},a.lastDayOfMonth=function(t,e){var n=r().startOf("day").month(e-1);return function(a){var o=r(n).year(a);return o.endOf("month").startOf("day").day(t),o.month()!==e-1&&o.subtract(7,"days"),o}}},function(t,e,n){var r=n(0);r.locale("fr"),r.defineLocale("fr-FR",{parentLocale:"fr",weekends:[0,6],holidays:["01-01","01-05","08-05","14-07","11-11",function(t){return r.easter(t).add(1,"day")},function(t){return r.easter(t).add(39,"day")},function(t){return r.easter(t).add(50,"day")},"15-08","01-11","25-12"]})}])});
//# sourceMappingURL=moment-biz-with-locales.min.js.map