feat(business-days): count Saturday with includeSaturday - #573
hyanmandian wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (10)
🚧 Files skipped from review as they are similar to previous changes (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughAdded the optional ChangesBusiness-day Saturday option
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Feature 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 15 files. (3 skipped: 3 unsupported.) ✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Comment |
Tree-shaking report✅ No size regression. 7 grew out of 158 exports.
What changed (7)
All exports (158)
How this is measuredEvery export is imported alone into an esbuild consumer bundle (minified, tree-shaken) built from the head and from the base of this pull request; the sizes are the resulting bundles, gzip is their gzipped size. 🔴 marks a regression: a pre-existing export that grew more than 20% and more than 256 B, or the bundle importing every pre-existing export growing more than 5%. 🟡 is growth under the threshold, 🟢 a decrease, ⚪ no change, 🆕 an export that does not exist on the base (never a regression), 🗑️ an export that was removed. An intentional increase is accepted with the |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## claude/business-day-helpers #573 +/- ##
=============================================================
Coverage 100.00% 100.00%
=============================================================
Files 187 187
Lines 2093 2097 +4
Branches 622 624 +2
=============================================================
+ Hits 2093 2097 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
be1f445 to
3a4bb06
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
The Docstring Coverage pre-merge warning is a false positive here, declining it. The one function it analysed is Every exported function and every key of the exported type this PR touches does carry full JSDoc, including the new |
The business day family counts Monday to Friday minus holidays, which is the
banking count. The payroll deadline of CLT art. 459 § 1º ("até o quinto dia útil
do mês subsequente ao vencido") is not counted that way: labour inspection reads
it through Instrução Normativa MTP nº 2/2021, art. 14, I, "na contagem dos dias
será incluído o sábado, excluindo-se o domingo e o feriado, inclusive o
municipal", so the fifth business day of the labour count can fall a day before
the banking one.
includeSaturday is a new key on the shared BusinessDayOptions, so isBusinessDay,
addBusinessDays, subBusinessDays, differenceInBusinessDays, getNextBusinessDay,
getNthBusinessDay and getLastBusinessDayOfMonth all honour it. It defaults to
false, the current behaviour, so no existing call changes. With it on, Sunday
and holidays are still excluded, which means a holiday that falls on a Saturday
is still not a business day.
The one part of the article it cannot cover is "inclusive o municipal":
getHolidays carries national and state holidays only, and Lei 9.093/1995 art. 2º
leaves the municipal feriados religiosos to each municipality's own law. The
JSDoc and both docs say so instead of implying the option gives the full rule.
The weekday test also stops going through a module level Set, which the
tree-shaking rule in CONTRIBUTING.md asks modules to avoid.
3a4bb06 to
5619d05
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
What
Today
isBusinessDayand the whole family count Monday to Friday minus holidays. That is the banking count, and it is the wrong one for the payroll deadline of CLT art. 459 § 1º ("até o quinto dia útil do mês subsequente ao vencido"): labour inspection reads that deadline through Instrução Normativa MTP nº 2/2021, art. 14, I, which says verbatim "na contagem dos dias será incluído o sábado, excluindo-se o domingo e o feriado, inclusive o municipal". So the labour "quinto dia útil" can fall a day earlier than the banking one: in March 2024 it is Wednesday the 6th (Saturday 2 March counts), while the banking one is Thursday the 7th.This PR adds
includeSaturdayto the sharedBusinessDayOptions. It defaults tofalse, which is exactly today's behaviour, so nothing existing changes. Every utility of the family honours it, since they all evaluate days throughisBusinessDaywith the caller'soptions.With the option on, Sunday and holidays are still excluded, exactly as the article says, so a holiday that falls on a Saturday is still not a business day (Finados on Saturday 2 November 2024, Independência on Saturday 7 September 2024, Dia do Evangélico on Saturday 30 November 2024 in the DF).
On top of #561's shared day walk
#561 now also replaces the
setDateday walk ofaddBusinessDays,differenceInBusinessDaysandgetNthBusinessDaywith one internal,_internals/each-local-day, which walks integer day offsets and yields each day at noon, so it cannot hang inPacific/Apia,Pacific/Fakaofo,Pacific/Kwajalein,Pacific/KiritimatiorPacific/Enderbury. This PR is rebased on that.includeSaturdayneeds no code in the walk: every util callsisBusinessDay(candidate, options)on the dayseachLocalDayyields, so the option goes through the shared walk unchanged. Tests pin it underTZ=Pacific/Apiaacross the missing Friday 30 December 2011, against the same calls underUTC:getNthBusinessDay(new Date(2011, 11, 15), -2, { includeSaturday: true })is Thu 2011-12-29 in Apia (Fri 30th skipped, Sat 31st counted) and Fri 2011-12-30 in UTC; December 2011 has 26 such business days in Apia and 27 in UTC.differenceInBusinessDays(new Date(2011, 11, 1), new Date(2011, 11, 31), { includeSaturday: true })is-25in Apia and-26in UTC.subBusinessDays(new Date(2012, 0, 2, 12), 2, { includeSaturday: true })is Thu 2011-12-29 12:00 in Apia.Why
includeSaturdayand not something elseincludeOptional: a boolean that widens what counts, named after what it includes.saturdays: booleandoes not say what setting it does;includeSaturdaydoes.clt,laborLaw,payroll,in2/2021). A name like that would promise the whole rule of art. 14, I, and this library cannot deliver the "inclusive o municipal" half of it (see Open points).includeSaturdaypromises exactly what it does.falseis the default, so the existing Monday-to-Friday answer is what every current call keeps getting.API
No signature changes. One new optional key on the existing shared type:
Sources
Read in full, not from memory:
getHolidaysdoes not carry them.The national and state holidays the count subtracts are unchanged and keep the sources already cited in
getHolidays/isBusinessDay.Verification
npm run check— pass (format, lint, types).npm run test -- --run— 6277 passed (after the rebase on feat(business-days): add getNthBusinessDay, getNextBusinessDay and getLastBusinessDayOfMonth, and fix the day walk that hangs in five time zones #561).npm run test:coverage— 100% statements/branches/functions/lines.npm run test:bun/npm run test:deno— passed before the rebase (6244); after it, left to CI.npm run build— pass, attw and publint clean.npm run check:api:update— the report gains exactly one line,includeSaturday?: boolean;; committed.npm run check:unused— pass.npm run check:duplication— 0 clones.npm run check:tree-shaking— pass.npm run check:commits— 0 problems.npm run test:mutationon each touched source file (before the rebase; the rebase changed no line of this PR's source, only its tests):is-business-day.ts100% (55 killed),add-business-days.ts100%,sub-business-days.ts100%,difference-in-business-days.ts100%,get-nth-business-day.ts100%,get-next-business-day.ts100%,get-last-business-day-of-month.ts100%. No survivors, no new Stryker disables.npm run build:llmsrun,docs/llms.txtanddocs/llms-full.txtcommitted.Tests
Every expectation is a literal date counted by hand against the holiday tables, including:
isBusinessDay), Friday 5 January + 1 landing on it, Monday 8 January - 1 landing on it, 31 August 2024 as the last business day of August, the 26 business days January 2024 has with Saturdays (22 + the Saturdays 6, 13, 20 and 27) against the 22 without them.stateCode: "DF". September 2024 exercises both at once: the 11th business day is Saturday the 14th with the option (Saturday the 7th skipped as Independência) and Monday the 16th without it.describe("no breaking change")block pinning that an absent,falseorundefinedincludeSaturday, and anoptionscarrying onlystateCodeorincludeOptional, all still answerfalsefor a Saturday.should agree with getHolidays and the weekend ruleproperty now ranges overincludeSaturdaytoo.Open points
getHolidayshas national and state holidays only, so withincludeSaturday: truea municipal holiday is counted here as an ordinary business day while the labour inspection would exclude it. A count that has to be exact for one municipality still needs those days removed on top of this option. This is stated in the JSDoc ofisBusinessDayandgetNthBusinessDayand in bothdocs/utilities.mdfiles rather than glossed over. Adding a municipal holiday dataset is a separate piece of work.includeSaturday(for example the string"false") enables the option, the same way a non-boolean truthyincludeOptionalbehaves today. That is existing house behaviour for these flags, not something this PR changes; the never-throws property covers hostile values.isBusinessDayno longer builds a module levelnew Set([0, 6])for the weekend check, replaced by two plain number constants, which is what the tree-shaking rule inCONTRIBUTING.mdasks modules to do. Behaviour is identical.CI
Rebased onto the current tip of #561 and force-pushed: every check green on
5619d05(Build, Check, Stryker, Node 20/22/24/26, Bun, Deno, the four browsers). The firstCheckrun failed inAudit dependencieswithaudit-ciexiting oncode undefinedbefore any project code ran, a registry hiccup; the rerun passed.Summary by CodeRabbit
New Features
includeSaturdayoption to business-day utilities.false, preserving existing banking-day behavior.Documentation