Skip to content

Conversation

@hiqua
Copy link
Owner

@hiqua hiqua commented Jun 25, 2025

This commit introduces the functionality to display the time duration
between consecutive life lapses in the output.

Modifications include:

  • Added a public end() accessor method to the LifeLapse struct in src/parse.rs.
  • Updated format_lifelapses in src/pretty_print.rs to calculate the
    gap between the end of the previous lapse and the start of the current
    one.
  • Added a helper function format_gap_duration in src/pretty_print.rs
    to create a formatted string for the gap duration.
  • Imported chrono::Duration as ChronoDuration in src/pretty_print.rs
    to be used for gap calculations.

This commit introduces the functionality to display the time duration
between consecutive life lapses in the output.

Modifications include:
- Added a public `end()` accessor method to the `LifeLapse` struct in `src/parse.rs`.
- Updated `format_lifelapses` in `src/pretty_print.rs` to calculate the
  gap between the end of the previous lapse and the start of the current
  one.
- Added a helper function `format_gap_duration` in `src/pretty_print.rs`
  to create a formatted string for the gap duration.
- Imported `chrono::Duration` as `ChronoDuration` in `src/pretty_print.rs`
  to be used for gap calculations.
This commit refines the functionality to display time durations
between consecutive life lapses and introduces unit tests for this feature.

Key changes:
- Modified `src/pretty_print.rs`:
    - Ensured that gap information is only printed if the gap duration
      is strictly positive.
    - Added a new test module (`mod tests`) with comprehensive unit tests
      for `format_gap_duration` and `format_lifelapses`. This includes
      testing various gap scenarios (positive gaps, zero gaps,
      no lapses, single lapse, and overlapping lapses).
    - Test helpers were created using the existing `get_life_chunk`
      function to ensure `LifeChunk` instances are created correctly
      for testing purposes.
- Reviewed `LifeLapse::end()` in `src/parse.rs` and confirmed its
  utility for providing the end time of a lapse. The public `extend()`
  method is now used in tests to construct `LifeLapse` instances with durations.

All existing and new tests pass.
@hiqua hiqua requested a review from Copilot June 25, 2025 04:57
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

This PR introduces functionality to display the time duration between consecutive life lapses. Key changes include:

  • Adding a public end() accessor to the LifeLapse struct in src/parse.rs.
  • Updating format_lifelapses in src/pretty_print.rs to calculate and insert gap durations.
  • Introducing a helper function format_gap_duration and corresponding tests to validate gap formatting.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/pretty_print.rs Added gap calculation logic in format_lifelapses and new helper function with tests.
src/parse.rs Exposed a new public end() accessor on the LifeLapse struct.
Comments suppressed due to low confidence (1)

src/pretty_print.rs:14

  • If the 'use time;' import is solely needed for tests, it might be helpful to clarify this usage in a comment or consider conditionally compiling it only for testing.
use time; // Added for tests

}
if minutes > 0 {
parts.push(format!("{} minute{}", minutes, if minutes == 1 { "" } else { "s" }));
}
Copy link

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

Currently, if the gap is less than a minute, the function returns 'Minimal gap'. Consider handling durations with seconds or adding documentation so that future maintainers understand this behavior.

Suggested change
}
}
if seconds > 0 {
parts.push(format!("{} second{}", seconds, if seconds == 1 { "" } else { "s" }));
}

Copilot uses AI. Check for mistakes.
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