-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(parental-leave): Remove daysToUse from VMST from calculation #16774
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces significant modifications to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts
(0 hunks)libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.ts
(1 hunks)
💤 Files with no reviewable changes (1)
- libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts
🧰 Additional context used
📓 Path-based instructions (1)
libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.ts (1)
Pattern libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
const calculatedLength = period.daysToUse | ||
? Number(period.daysToUse) | ||
: Math.round(periodLength * percentage) | ||
const calculatedLength = Math.round(periodLength * percentage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Potential cumulative rounding errors in calculateDaysUsedByPeriods
By rounding each period's calculated length individually using Math.round(periodLength * percentage)
, there's a risk of cumulative rounding errors affecting the total days calculated. It might be more accurate to sum the unrounded values and apply rounding to the final total to ensure precision.
Apply this diff to adjust the rounding:
-export const calculateDaysUsedByPeriods = (periods: Period[]) =>
- Math.round(
- periods.reduce((total, period) => {
- const start = parseISO(period.startDate)
- const end = parseISO(period.endDate)
- const percentage = Number(period.ratio) / 100
- const periodLength = calculatePeriodLength(
- start,
- end,
- undefined,
- period.months,
- )
- const calculatedLength = Math.round(periodLength * percentage)
-
- return total + calculatedLength
- }, 0),
- )
+export const calculateDaysUsedByPeriods = (periods: Period[]) => {
+ const totalDays = periods.reduce((total, period) => {
+ const start = parseISO(period.startDate)
+ const end = parseISO(period.endDate)
+ const percentage = Number(period.ratio) / 100
+ const periodLength = calculatePeriodLength(
+ start,
+ end,
+ undefined,
+ period.months,
+ )
+ const calculatedLength = periodLength * percentage
+
+ return total + calculatedLength
+ }, 0)
+ return Math.round(totalDays)
+}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const calculatedLength = Math.round(periodLength * percentage) | |
export const calculateDaysUsedByPeriods = (periods: Period[]) => { | |
const totalDays = periods.reduce((total, period) => { | |
const start = parseISO(period.startDate) | |
const end = parseISO(period.endDate) | |
const percentage = Number(period.ratio) / 100 | |
const periodLength = calculatePeriodLength( | |
start, | |
end, | |
undefined, | |
period.months, | |
) | |
const calculatedLength = periodLength * percentage | |
return total + calculatedLength | |
}, 0) | |
return Math.round(totalDays) | |
} |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #16774 +/- ##
==========================================
- Coverage 36.55% 36.55% -0.01%
==========================================
Files 6892 6892
Lines 143767 143763 -4
Branches 40964 40961 -3
==========================================
- Hits 52557 52555 -2
+ Misses 91210 91208 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
|
Datadog ReportAll test runs ✅ 5 Total Test Services: 0 Failed, 5 Passed Test Services
|
Remove daysToUse from VMST from calculation of rights and period days
Attach a link to issue if relevant
What
Specify what you're trying to achieve
Why
Specify why you need to achieve this
Screenshots / Gifs
Attach Screenshots / Gifs to help reviewers understand the scope of the pull request
Checklist:
Summary by CodeRabbit
New Features
Bug Fixes
Documentation