Skip to content

Conversation

MirrorAzure
Copy link

@MirrorAzure MirrorAzure commented Oct 14, 2024

A method similar to datetime.timedelta.total_seconds()
Returns total seconds of time object

@ghost
Copy link

ghost commented Oct 14, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Oct 14, 2024

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 skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Oct 14, 2024

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 skip news label instead.

@MirrorAzure MirrorAzure changed the title trivial: Add total_seconds() method to datetime.time gh-125435: Add total_seconds() method to datetime.time Oct 14, 2024
Copy link
Member

@picnixz picnixz left a 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
Copy link
Member

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):
Copy link
Member

Choose a reason for hiding this comment

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

  1. You should also update the C implementation.
  2. You should add tests.
  3. 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 +
Copy link
Member

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

@zware
Copy link
Member

zware commented Oct 14, 2024

Closing per #125435 (comment).

@zware zware closed this Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants