Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/_pydatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,7 @@ class time:
utcoffset()
tzname()
dst()
total_seconds()

Properties (readonly):
hour, minute, second, microsecond, tzinfo, fold
Expand Down Expand Up @@ -1473,6 +1474,11 @@ def tzinfo(self):
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.

"""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

self.microsecond) / 10**6

# Standard conversions, __hash__ (and helpers)

# Comparisons of time objects with other.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Loading