UNPKG

dutyhours

Version:

A tool to calculate total working hours in a given month, taking into account public holidays and configurable working days.

2 lines 1.35 kB
"use strict";var c=Object.create;var i=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var S=(t,e)=>{for(var o in e)i(t,o,{get:e[o],enumerable:!0})},l=(t,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of f(e))!g.call(t,n)&&n!==o&&i(t,n,{get:()=>e[n],enumerable:!(a=D(e,n))||a.enumerable});return t};var M=(t,e,o)=>(o=t!=null?c(m(t)):{},l(e||!t||!t.__esModule?i(o,"default",{value:t,enumerable:!0}):o,t)),p=t=>l(i({},"__esModule",{value:!0}),t);var N={};S(N,{default:()=>H});module.exports=p(N);var w=M(require("date-holidays"),1),O=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function T(t,e){let o=O[t];return e[`without${o}s`]?!1:e[`with${o}s`]?!0:t>=1&&t<=5}function k(t,e,o){let a=new w.default(o),n=new Date(t,e-1,1),s=new Date(t,e,0);return new Set(a.getHolidays(t).filter(({date:r,type:y})=>{let u=new Date(r);return u>=n&&u<=s&&y!=="observance"}).map(({date:r})=>new Date(r).toDateString()))}function F(t){let e=new Date,{country:o,hoursPerDay:a=8,month:n=e.getMonth()+1,year:s=e.getFullYear()}=t,r=k(s,n,o),y=new Date(s,n,0),u=0;for(let d=1;d<=y.getDate();d++){let h=new Date(s,n-1,d),b=h.getDay();!r.has(h.toDateString())&&T(b,t)&&(u+=a)}return u}var H=F; //# sourceMappingURL=index.cjs.map