fix(flex): correct one-minute flex calc (fall back to PlanHours/PaiedOutFlex when *InSeconds unset)#1616
Merged
Merged
Conversation
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>
There was a problem hiding this comment.
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
ApplyNettoFlexChainSecondPrecisionto fall back fromPlanHoursInSeconds/PaiedOutFlexInSecondsto roundedPlanHours * 3600/PaiedOutFlex * 3600when the seconds columns are0. - 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With
UseOneMinuteIntervals = true, the flex calculation is wrong.ApplyNettoFlexChainSecondPrecisionsubtractsPlanHoursInSecondsandPaiedOutFlexInSeconds, but those int second-columns are never populated in the punch-clock/planner/payout flows (only thedoublePlanHours/PaiedOutFlexare). They sit at 0, so:netto − planned. CumulativeSumFlexEndcompounds it (two days 7.67h + 6.33h displayed flex 14.00 instead of 0.67h / 1.33h).SumFlexEndnever decreases.The flag-OFF path is correct because it uses the
doublePlanHours/PaiedOutFlexdirectly.Fix (forward-only, C# only)
In
PlanRegistrationHelper.ApplyNettoFlexChainSecondPrecision, fall back to the populated double when the seconds column is 0:Handover/absence flows that legitimately populate the seconds columns are preserved (the
!= 0guard 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-settingPlanHoursInSeconds.Follow-up
Existing already-stored wrong
Flex/SumFlexEndrows forUseOneMinuteIntervalscustomers are repaired separately via a targeted script (forward-only on the data).🤖 Generated with Claude Code