Merge pull request #27868 from akhilnarang/fix-format_timedelta

fix: don't call `.total_seconds()` if the object isn't of type `datetime.timedelta`
This commit is contained in:
Akhil Narang 2024-09-23 17:44:16 +05:30 committed by GitHub
commit a04aba0408
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2442,10 +2442,13 @@ class UnicodeWithAttrs(str):
self.metadata = text.metadata
def format_timedelta(o: datetime.timedelta) -> str:
# mariadb allows a wide diff range - https://mariadb.com/kb/en/time/
# but frappe doesnt - i think via babel : only allows 0..23 range for hour
total_seconds = o.total_seconds()
def format_timedelta(o: datetime.timedelta | str) -> str:
# MariaDB allows a wide range - https://mariadb.com/kb/en/time/
# but Frappe doesn't - I think via babel : only allows 0..23 range for hour
if isinstance(o, datetime.timedelta):
total_seconds = o.total_seconds()
else:
total_seconds = cint(o)
hours, remainder = divmod(total_seconds, 3600)
minutes, seconds = divmod(remainder, 60)
rounded_seconds = round(seconds, 6)