Skip to content
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

Arbitrary start #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

nsilveri
Copy link

@nsilveri nsilveri commented May 28, 2024

I added the ability to set the minutes or seconds from which to start the timer in the case of a count-up.

use:

counter.set_minutes_start_time(minutes)
counter.start()

For the sake of speed, I reused the pause() function, so it's as if a resume() is executed when .start() is called.

Manual minutes set:
image

The timer starts from the set minutes
image

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @nsilveri - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 5 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -63,6 +65,18 @@ def resume(self):
self._time_started = self._time_started + pause_duration
self._paused = False

def set_minutes_start_time(self, minutes):
"""Set the start time manually in minutes."""
self._time_started = time.time() - (minutes * 60)
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Potential issue with negative time values.

If a negative value is passed to minutes, it will set _time_started to a future time. Consider adding validation to ensure minutes is non-negative.

self._time_paused = time.time()
self._paused = True

def set_seconds_start_time(self, seconds):
Copy link

Choose a reason for hiding this comment

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

issue (typo): Incorrect docstring for set_seconds_start_time.

The docstring for set_seconds_start_time incorrectly states 'Set the start time manually in minutes.' It should be 'Set the start time manually in seconds.'


def set_seconds_start_time(self, seconds):
"""Set the start time manually in minutes."""
self._time_started = time.time() - seconds
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Potential issue with negative time values.

If a negative value is passed to seconds, it will set _time_started to a future time. Consider adding validation to ensure seconds is non-negative.

@@ -63,6 +65,18 @@ def resume(self):
self._time_started = self._time_started + pause_duration
self._paused = False

def set_minutes_start_time(self, minutes):
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider combining set_minutes_start_time and set_seconds_start_time.

Both methods are very similar. You could create a single method that takes both minutes and seconds as optional parameters, defaulting to zero, to reduce code duplication.

Suggested change
def set_minutes_start_time(self, minutes):
def set_start_time(self, minutes=0, seconds=0):
"""Set the start time manually in minutes and seconds."""
self._time_started = time.time() - (minutes * 60 + seconds)

@@ -17,6 +17,8 @@ class CountTimer:
start(): start the timer
pause(): pause the timer
resume(): resume the timer
set_minutes_start_time(minutes): set the start time manually in minutes
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider adding validation details in the docstring.

It would be helpful to mention in the docstring that negative values for minutes and seconds are not allowed, assuming you add validation for this.

Suggested change
set_minutes_start_time(minutes): set the start time manually in minutes
set_minutes_start_time(minutes): set the start time manually in minutes (negative values not allowed)

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.

1 participant