benvdh commented on a change in pull request #8276: More intuitive display of negative time
deltas (#8274)
URL: https://github.com/apache/incubator-superset/pull/8276#discussion_r326866012
##########
File path: superset/utils/core.py
##########
@@ -349,6 +349,23 @@ def datetime_f(dttm):
return "<nobr>{}</nobr>".format(dttm)
+def timedelta_f(td):
+ """
+ Ensures negative time deltas are easily interpreted by humans
+
+ >>> td = timedelta(0) - timedelta(days=1, hours=5,minutes=6)
+ >>> str(td)
+ '-2 days, 18:54:00'
+ >>> timedelta_f(td)
+ '-1 day, 5:06:00'
+ """
+ if td < timedelta(0):
+ return "-" + timedelta_f(-td)
Review comment:
That's indeed simpler, I thought the recursion did more than it actually did. Simplified
now!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
|