From ce3b15c3e1dfec869dcf95c8a2284614706da30d Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Mon, 23 Sep 2024 16:14:12 +0530 Subject: [PATCH 1/2] fix: update comment Signed-off-by: Akhil Narang --- frappe/utils/data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frappe/utils/data.py b/frappe/utils/data.py index b1f5e85e68..eeadfbdf24 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -2443,8 +2443,8 @@ class UnicodeWithAttrs(str): 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 + # 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 total_seconds = o.total_seconds() hours, remainder = divmod(total_seconds, 3600) minutes, seconds = divmod(remainder, 60) From 44447d27e00ba61c5cc344048a7fd4246b2229c3 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Mon, 23 Sep 2024 16:15:24 +0530 Subject: [PATCH 2/2] fix(format_timedelta): don't try to call `.total_seconds()` if a string was passed in Signed-off-by: Akhil Narang --- frappe/utils/data.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frappe/utils/data.py b/frappe/utils/data.py index eeadfbdf24..6262f00ad0 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -2442,10 +2442,13 @@ class UnicodeWithAttrs(str): self.metadata = text.metadata -def format_timedelta(o: datetime.timedelta) -> str: +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 - total_seconds = o.total_seconds() + 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)