parent
751182df52
commit
24f4459318
|
@ -6,7 +6,7 @@ RUN npm install && \
|
||||||
|
|
||||||
FROM python:3.10.9-alpine
|
FROM python:3.10.9-alpine
|
||||||
|
|
||||||
ENV VERSION_NUMBER 0.1.2-5-g33e136a
|
ENV VERSION_NUMBER 0.1.2-6-g751182d
|
||||||
ENV PROD 1
|
ENV PROD 1
|
||||||
|
|
||||||
RUN apk add \
|
RUN apk add \
|
||||||
|
|
|
@ -9,7 +9,7 @@ def now() -> datetime:
|
||||||
|
|
||||||
|
|
||||||
def format_duration(
|
def format_duration(
|
||||||
duration: timedelta, format_string: str = "%H hours %m minutes"
|
duration: timedelta | None, format_string: str = "%H hours %m minutes"
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Format timedelta into the specified format_string.
|
Format timedelta into the specified format_string.
|
||||||
|
@ -23,6 +23,9 @@ def format_duration(
|
||||||
hour_seconds = 60 * minute_seconds
|
hour_seconds = 60 * minute_seconds
|
||||||
day_seconds = 24 * hour_seconds
|
day_seconds = 24 * hour_seconds
|
||||||
if not isinstance(duration, timedelta):
|
if not isinstance(duration, timedelta):
|
||||||
|
if duration == None:
|
||||||
|
duration = timedelta(seconds=0)
|
||||||
|
else:
|
||||||
duration = timedelta(seconds=duration)
|
duration = timedelta(seconds=duration)
|
||||||
seconds_total = int(duration.total_seconds())
|
seconds_total = int(duration.total_seconds())
|
||||||
# timestamps where end is before start
|
# timestamps where end is before start
|
||||||
|
|
|
@ -56,3 +56,9 @@ class FormatDurationTest(unittest.TestCase):
|
||||||
delta = timedelta(hours=-2)
|
delta = timedelta(hours=-2)
|
||||||
result = format_duration(delta, "%H hours")
|
result = format_duration(delta, "%H hours")
|
||||||
self.assertEqual(result, "0 hours")
|
self.assertEqual(result, "0 hours")
|
||||||
|
|
||||||
|
def test_none(self):
|
||||||
|
try:
|
||||||
|
format_duration(None)
|
||||||
|
except TypeError as exc:
|
||||||
|
assert False, f"format_duration(None) raised an exception {exc}"
|
||||||
|
|
Loading…
Reference in New Issue