Skip to content

fix(fields): fix NETWORKDAYS for reverse dates and time components [CLK-563323]#35

Merged
mysza merged 1 commit intomainfrom
grok/mysza/fix-fields-fix-networkdays-for-reverse-dates-and-time-components-to-main-4626
Mar 31, 2026
Merged

fix(fields): fix NETWORKDAYS for reverse dates and time components [CLK-563323]#35
mysza merged 1 commit intomainfrom
grok/mysza/fix-fields-fix-networkdays-for-reverse-dates-and-time-components-to-main-4626

Conversation

@mysza
Copy link
Copy Markdown
Contributor

@mysza mysza commented Mar 31, 2026

Summary

Fixes two bugs in the NETWORKDAYS formula (via formulajsProxy) that caused incorrect results for ClickUp formula custom fields:

  • Reverse direction (start > end): formulajs day-counting loop never runs when days <= 0, returning 0 or wrong values instead of a negative working-day count. Excel/Sheets returns the negation of the forward count.
  • Time-of-day on Date objects: formulajs uses Math.round on the ms difference between dates, so time components cause fractional results (e.g. 2.08 instead of 3) and off-by-one errors. Excel/Sheets ignores time-of-day entirely.

Fix

  • Strip time from Date inputs before passing to formulajs (strings and serial numbers are unaffected — formulajs.parseDate handles those correctly)
  • When the forward call returns <= 0, compute the reverse and negate to match Excel behavior

Examples

Formula Before After Excel
NETWORKDAYS("2013-12-05", "2013-12-04") 0 -2 -2
NETWORKDAYS("2013-12-05", "2013-11-04") -23 -24 -24
NETWORKDAYS(Aug7 23:00, Aug9 01:00) 2.08 3 3

Test plan

  • Added reverse-direction tests (mirrors of existing forward tests)
  • Added time-component tests using callVariable to inject Date objects with time-of-day
  • Verified all 48 date-time tests pass
  • Verified existing forward-direction NETWORKDAYS tests still pass

PRs in the Stack

(The stack is managed by git-grok.)

…LK-563323]

formulajs NETWORKDAYS has two bugs:
- When start > end, the day-counting loop never runs, returning wrong
  results instead of a negative working-day count
- Date objects with time-of-day produce fractional/off-by-one results
  due to Math.round on the ms difference

Fix by stripping time from Date inputs and computing the forward
result then negating when the initial call returns <= 0.
Copy link
Copy Markdown
Contributor

@Flexicon Flexicon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@mysza mysza merged commit c53162e into main Mar 31, 2026
3 checks passed
@mysza mysza deleted the grok/mysza/fix-fields-fix-networkdays-for-reverse-dates-and-time-components-to-main-4626 branch March 31, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants