UNPKG

dutyhours

Version:

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

3 lines 3.97 kB
#!/usr/bin/env node import p from"date-holidays";var w=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function b(e,t){let n=w[e];return t[`without${n}s`]?!1:t[`with${n}s`]?!0:e>=1&&e<=5}function f(e,t,n){let l=new p(n),o=new Date(e,t-1,1),s=new Date(e,t,0);return new Set(l.getHolidays(e).filter(({date:i,type:c})=>{let a=new Date(i);return a>=o&&a<=s&&c!=="observance"}).map(({date:i})=>new Date(i).toDateString()))}function k(e){let t=new Date,{country:n,hoursPerDay:l=8,month:o=t.getMonth()+1,year:s=t.getFullYear()}=e,i=f(s,o,n),c=new Date(s,o,0),a=0;for(let u=1;u<=c.getDate();u++){let m=new Date(s,o-1,u),g=m.getDay();!i.has(m.toDateString())&&b(g,e)&&(a+=l)}return a}var h=k;import{Option as y,program as r}from"commander";var d={name:"dutyhours",version:"1.0.5",description:"A tool to calculate total working hours in a given month, taking into account public holidays and configurable working days.",keywords:["working-hours"],bugs:{url:"https://github.com/kamdz/dutyhours/issues"},publishConfig:{access:"public"},repository:{type:"git",url:"git+https://github.com/kamdz/dutyhours.git"},license:"MIT",author:{name:"Kamil Dzwonkowski",email:"npm@kamdz.dev",url:"https://github.com/kamdz"},type:"module",exports:{".":{import:"./dist/index.js",require:"./dist/index.cjs"}},main:"./dist/index.cjs",module:"./dist/index.js",types:"./dist/index.d.ts",bin:"./dist/cli.js",files:["dist","package.json","README.md","CHANGELOG.md","LICENSE"],scripts:{build:"tsup",cli:"tsx bin/cli.ts",commit:"cz",dev:"tsx watch src/index.ts",dx:"npx @kamdz/dx",format:"prettier --write --ignore-unknown .",lint:"eslint . --fix","lint-staged":"lint-staged",prepare:"husky",start:"tsx src/index.ts",test:"jest --coverage --passWithNoTests","type-check":"tsc --noEmit"},"lint-staged":{"**/*.{ts,tsx,js,jsx,cjs,mjs,}":["eslint --fix"],"**/*.{ts,tsx,js,jsx,json,md,cjs,mjs,yml,yaml}":["prettier --write --ignore-unknown"]},config:{commitizen:{path:"./node_modules/cz-conventional-changelog"}},release:{branches:["main"],plugins:["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator",["@semantic-release/changelog",{changelogFile:"CHANGELOG.md"}],"@semantic-release/npm",["@semantic-release/git",{assets:["package.json","CHANGELOG.md"],message:"chore(release): ${nextRelease.version} \n\n${nextRelease.notes}"}],"@semantic-release/github"]},devDependencies:{"@commitlint/cli":"^19.6.1","@commitlint/config-conventional":"^19.6.0","@eslint/compat":"^1.2.5","@eslint/js":"^9.19.0","@ianvs/prettier-plugin-sort-imports":"^4.4.1","@semantic-release/changelog":"^6.0.3","@semantic-release/git":"^10.0.1","@types/fs-extra":"^11.0.4","@types/jest":"^29.5.14","@types/node":"^22.10.10",commitizen:"^4.3.1","cz-conventional-changelog":"^3.3.0",eslint:"^9.19.0","eslint-config-prettier":"^10.0.1","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.2.3",globals:"^15.14.0",husky:"^9.1.7",jest:"^29.7.0","lint-staged":"^15.4.3",prettier:"3.4.2","semantic-release":"^24.2.1","ts-jest":"^29.2.5",tsup:"^8.3.6",tsx:"^4.19.2",typescript:"^5.7.3","typescript-eslint":"^8.21.0"},packageManager:"yarn@4.5.1",dependencies:{commander:"^13.1.0","date-holidays":"^3.23.21"}};r.version(d.version).description(d.description).argument("<country>","The country code to determine the public holidays").option("-h, --hours","The number of working hours in a single working day").option("-m, --month <month>","The month (indexed from 1 to 12) to calculate working hours for. Defaults to the current month").option("-y, --year <year>","The year to calculate working hours for. Defaults to the current year").action((e,t)=>{console.log(h({country:e,...t}))});["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"].forEach(e=>{r.addOption(new y(`--with${e}s`,`Whether to include ${e}s as working days`)),r.addOption(new y(`--without${e}s`,`Whether to exclude ${e}s from working days`))});r.parse(process.argv); //# sourceMappingURL=cli.js.map