-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Display gaps between life lapses #6
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
base: main
Are you sure you want to change the base?
Conversation
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.
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.
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" })); | ||
| } |
Copilot
AI
Jun 25, 2025
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.
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.
| } | |
| } | |
| if seconds > 0 { | |
| parts.push(format!("{} second{}", seconds, if seconds == 1 { "" } else { "s" })); | |
| } |
This commit introduces the functionality to display the time duration
between consecutive life lapses in the output.
Modifications include:
end()accessor method to theLifeLapsestruct insrc/parse.rs.format_lifelapsesinsrc/pretty_print.rsto calculate thegap between the end of the previous lapse and the start of the current
one.
format_gap_durationinsrc/pretty_print.rsto create a formatted string for the gap duration.
chrono::DurationasChronoDurationinsrc/pretty_print.rsto be used for gap calculations.