Fix work minutes calculation to handle same start and end times#38
Merged
jeyongsong merged 2 commits intomainfrom Mar 17, 2026
Merged
Fix work minutes calculation to handle same start and end times#38jeyongsong merged 2 commits intomainfrom
jeyongsong merged 2 commits intomainfrom
Conversation
Test Results34 tests 34 ✅ 0s ⏱️ Results for commit 50c91eb. |
There was a problem hiding this comment.
Pull request overview
Refines work-time and earnings calculations to correctly handle edge cases where clock-in and clock-out times are identical, aligning “overnight shift” detection to only cases where clock-out is strictly before clock-in.
Changes:
- Updated
SalaryCalculator.calculateWorkMinutesto return0minutes when clock-in equals clock-out, and treat only strictly-negative durations as overnight shifts. - Adjusted
WorkdayServicetime comparisons to consider equal times as “not overnight” (!isBefore), preventing incorrect same-time handling. - Added unit tests covering same clock-in/clock-out behavior for both minutes and earnings calculations.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/test/kotlin/com/moa/service/EarningsCalculatorTest.kt | Adds a unit test ensuring identical clock-in/out results in 0 earnings. |
| src/test/kotlin/com/moa/entity/SalaryCalculatorTest.kt | Adds a unit test ensuring identical clock-in/out results in 0 work minutes. |
| src/main/kotlin/com/moa/service/WorkdayService.kt | Updates equality handling in time comparisons to avoid misclassifying equal times as overnight. |
| src/main/kotlin/com/moa/entity/SalaryType.kt | Updates calculateWorkMinutes logic and KDoc to reflect correct same-time/overnight behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
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.
This pull request refines the calculation logic for work minutes and daily earnings, especially in cases where the clock-in and clock-out times are the same. It clarifies handling of overnight shifts, ensures accurate time comparisons, and adds corresponding unit tests to verify the new behavior.
Improvements to work time calculation:
SalaryCalculator.calculateWorkMinutesto treat only cases where clock-out is strictly before clock-in as overnight shifts, and to return 0 minutes when clock-in and clock-out are the same.Clarifications and fixes to time comparison logic:
WorkdayServiceto use!clockOut.isBefore(clockIn)instead ofclockOut.isAfter(clockIn), ensuring correct handling when times are equal. [1] [2]Test coverage enhancements:
SalaryCalculatorTestto verify that identical clock-in and clock-out times return 0 minutes.EarningsCalculatorTestto verify that identical clock-in and clock-out times result in zero earnings.