Skip to content

fix(flex): correct one-minute flex calc (fall back to PlanHours/PaiedOutFlex when *InSeconds unset)#1616

Merged
renemadsen merged 1 commit into
stablefrom
fix/one-minute-flex-planhours
Jun 19, 2026
Merged

fix(flex): correct one-minute flex calc (fall back to PlanHours/PaiedOutFlex when *InSeconds unset)#1616
renemadsen merged 1 commit into
stablefrom
fix/one-minute-flex-planhours

Conversation

@renemadsen

Copy link
Copy Markdown
Member

Problem

With UseOneMinuteIntervals = true, the flex calculation is wrong. ApplyNettoFlexChainSecondPrecision subtracts PlanHoursInSeconds and PaiedOutFlexInSeconds, but those int second-columns are never populated in the punch-clock/planner/payout flows (only the double PlanHours / PaiedOutFlex are). They sit at 0, so:

  • Flex = full netto worked instead of netto − planned. Cumulative SumFlexEnd compounds it (two days 7.67h + 6.33h displayed flex 14.00 instead of 0.67h / 1.33h).
  • A flex payout subtracts 0, so SumFlexEnd never decreases.

The flag-OFF path is correct because it uses the double PlanHours / PaiedOutFlex directly.

Fix (forward-only, C# only)

In PlanRegistrationHelper.ApplyNettoFlexChainSecondPrecision, fall back to the populated double when the seconds column is 0:

planHoursSeconds    = PlanHoursInSeconds    != 0 ? PlanHoursInSeconds    : (int)Math.Round(PlanHours    * 3600)
paiedOutFlexSeconds = PaiedOutFlexInSeconds != 0 ? PaiedOutFlexInSeconds : (int)Math.Round(PaiedOutFlex * 3600)

Handover/absence flows that legitimately populate the seconds columns are preserved (the != 0 guard uses them verbatim).

Tests

Two new regression tests (Flex_FlagOn_PlanHoursInSecondsZero_FallsBackToPlanHours, SumFlex_FlagOn_PaiedOutFlexInSecondsZero_FallsBackToPaiedOutFlex) — both fail on the old code, pass on the fix. The existing FlagOn test masked the bug by pre-setting PlanHoursInSeconds.

Follow-up

Existing already-stored wrong Flex/SumFlexEnd rows for UseOneMinuteIntervals customers are repaired separately via a targeted script (forward-only on the data).

🤖 Generated with Claude Code

ApplyNettoFlexChainSecondPrecision (the UseOneMinuteIntervals flex chain)
subtracted PlanHoursInSeconds and PaiedOutFlexInSeconds, but those int columns
are never populated by the punch-clock/planner/flex-payout flows (only the double
PlanHours / PaiedOutFlex fields are). They were therefore 0, so flex collapsed to
the full netto worked and cumulative SumFlexEnd compounded the error (e.g. two
days 7.67h + 6.33h showed flex 14.00 instead of 0.67h / 1.33h). Paid-out flex was
likewise ignored, so SumFlexEnd never dropped on a payout.

Fall back to the populated double when the *InSeconds column is 0, matching the
flag-off path which already uses PlanHours / PaiedOutFlex:
  planHoursSeconds   = PlanHoursInSeconds   != 0 ? PlanHoursInSeconds   : round(PlanHours   * 3600)
  paiedOutFlexSeconds = PaiedOutFlexInSeconds != 0 ? PaiedOutFlexInSeconds : round(PaiedOutFlex * 3600)

Forward-only code fix. Adds two regression tests (the existing FlagOn test masked
the bug by pre-setting PlanHoursInSeconds). Existing-row data repaired separately.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 19, 2026 15:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes incorrect flex and cumulative flex (SumFlexEnd) calculations when UseOneMinuteIntervals = true by ensuring the second-precision flex chain uses the populated double fields (PlanHours, PaiedOutFlex) when their corresponding *InSeconds columns are left as 0 by punch-clock/planner/payout writers.

Changes:

  • Update ApplyNettoFlexChainSecondPrecision to fall back from PlanHoursInSeconds/PaiedOutFlexInSeconds to rounded PlanHours * 3600 / PaiedOutFlex * 3600 when the seconds columns are 0.
  • Add two regression tests to cover the “seconds columns unset” production scenario for both planned hours and paid-out flex.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
eFormAPI/Plugins/TimePlanning.Pn/TimePlanning.Pn/Infrastructure/Helpers/PlanRegistrationHelper.cs Adds guarded fallback seconds derivation to keep flag-on flex chain correct when seconds columns are not populated.
eFormAPI/Plugins/TimePlanning.Pn/TimePlanning.Pn.Test/PlanRegistrationHelperTests.cs Adds regression tests verifying correct fallback behavior for plan hours and paid-out flex in the one-minute chain.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@renemadsen renemadsen merged commit 3f7d50b into stable Jun 19, 2026
39 checks passed
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