Skip to content

Fix work minutes calculation to handle same start and end times#38

Merged
jeyongsong merged 2 commits intomainfrom
fix-same-start-end-zero-hours
Mar 17, 2026
Merged

Fix work minutes calculation to handle same start and end times#38
jeyongsong merged 2 commits intomainfrom
fix-same-start-end-zero-hours

Conversation

@jeyongsong
Copy link
Member

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:

  • Updated SalaryCalculator.calculateWorkMinutes to 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:

  • Changed time comparison logic in WorkdayService to use !clockOut.isBefore(clockIn) instead of clockOut.isAfter(clockIn), ensuring correct handling when times are equal. [1] [2]

Test coverage enhancements:

  • Added a unit test to SalaryCalculatorTest to verify that identical clock-in and clock-out times return 0 minutes.
  • Added a unit test to EarningsCalculatorTest to verify that identical clock-in and clock-out times result in zero earnings.

Copilot AI review requested due to automatic review settings March 17, 2026 15:58
@github-actions
Copy link

Test Results

34 tests   34 ✅  0s ⏱️
 3 suites   0 💤
 3 files     0 ❌

Results for commit 50c91eb.

@jeyongsong jeyongsong merged commit bf737ac into main Mar 17, 2026
5 checks passed
@jeyongsong jeyongsong deleted the fix-same-start-end-zero-hours branch March 17, 2026 15:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.calculateWorkMinutes to return 0 minutes when clock-in equals clock-out, and treat only strictly-negative durations as overnight shifts.
  • Adjusted WorkdayService time 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.

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