From 4eda1ba9bb608400548ffb2dc73340cba45be845 Mon Sep 17 00:00:00 2001 From: MirrorAzure Date: Mon, 14 Oct 2024 09:52:28 +0300 Subject: [PATCH 1/3] Add total_seconds() method to datetime.time --- Lib/_pydatetime.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py index 78e03e32896740..36aaa2ed308903 100644 --- a/Lib/_pydatetime.py +++ b/Lib/_pydatetime.py @@ -1392,6 +1392,7 @@ class time: utcoffset() tzname() dst() + total_seconds() Properties (readonly): hour, minute, second, microsecond, tzinfo, fold @@ -1473,6 +1474,11 @@ def tzinfo(self): def fold(self): return self._fold + def total_seconds(self): + """Total seconds in the time.""" + return ((self.hour * 3600 + self.minute * 60 + self.second) * 10**6 + + self.microsecond) / 10**6 + # Standard conversions, __hash__ (and helpers) # Comparisons of time objects with other. From c8bf8400af93a1f15e501c8f1cbc3151b5062176 Mon Sep 17 00:00:00 2001 From: MirrorAzure Date: Mon, 14 Oct 2024 10:15:09 +0300 Subject: [PATCH 2/3] refactor: Fix trailing whitespaces --- Lib/_pydatetime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py index 36aaa2ed308903..86c9805b6e008e 100644 --- a/Lib/_pydatetime.py +++ b/Lib/_pydatetime.py @@ -1478,7 +1478,7 @@ def total_seconds(self): """Total seconds in the time.""" return ((self.hour * 3600 + self.minute * 60 + self.second) * 10**6 + self.microsecond) / 10**6 - + # Standard conversions, __hash__ (and helpers) # Comparisons of time objects with other. From 1b97bced4326025fb95337f3a0bb873d3786ffc4 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 08:20:19 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-10-14-08-20-18.gh-issue-125435.0bB-44.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-10-14-08-20-18.gh-issue-125435.0bB-44.rst diff --git a/Misc/NEWS.d/next/Library/2024-10-14-08-20-18.gh-issue-125435.0bB-44.rst b/Misc/NEWS.d/next/Library/2024-10-14-08-20-18.gh-issue-125435.0bB-44.rst new file mode 100644 index 00000000000000..5a8db84b6c3813 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-10-14-08-20-18.gh-issue-125435.0bB-44.rst @@ -0,0 +1 @@ +Add :meth:`datetime.time.total_seconds` method