-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-125435: Add total_seconds() method to datetime.time #125433
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
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
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.
I'm -0.5 on this feature because I don't think there's a real need to add such simple helper. In addition, if we were to add it, I'd prefer having a property rather than a method.
@@ -0,0 +1 @@ | |||
Add :meth:`datetime.time.total_seconds` method |
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.
You'll need to add a corresponding documentation entry for this one.
def fold(self): | ||
return self._fold | ||
|
||
def total_seconds(self): |
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.
- You should also update the C implementation.
- You should add tests.
- You should check corner cases where the arithmetic may be a fuzzy.
|
||
def total_seconds(self): | ||
"""Total seconds in the time.""" | ||
return ((self.hour * 3600 + self.minute * 60 + self.second) * 10**6 + |
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.
I don't think the multiply and divide operation is needed. You should write:
return self.hour * 3600 + self.minute * 60 + self.second + self.microsecond / 1e6
Closing per #125435 (comment). |
A method similar to datetime.timedelta.total_seconds()
Returns total seconds of time object