Formatting.
Signed-off-by: Flynn <emissary@flynn.kodachi.com>
This commit is contained in:
parent
40aaae5e53
commit
8e3d9c4d89
@ -21,9 +21,11 @@ import durationpy
|
||||
# really be a big deal.
|
||||
reDuration = re.compile(r'^([0-9]{1,5}(h|m|s|ms)){1,4}$')
|
||||
|
||||
# maxDuration_ms is the maximum duration that GEP-2257 can support, in milliseconds.
|
||||
# maxDuration_ms is the maximum duration that GEP-2257 can support, in
|
||||
# milliseconds.
|
||||
maxDuration_ms = (((99999 * 3600) + (59 * 60) + 59) * 1_000) + 999
|
||||
|
||||
|
||||
def parse_duration(duration) -> datetime.timedelta:
|
||||
"""
|
||||
Parse GEP-2257 Duration format to a datetime.timedelta object.
|
||||
@ -75,6 +77,7 @@ def parse_duration(duration) -> datetime.timedelta:
|
||||
|
||||
return durationpy.from_str(duration)
|
||||
|
||||
|
||||
def format_duration(delta: datetime.timedelta) -> str:
|
||||
"""
|
||||
Format a datetime.timedelta object to GEP-2257 Duration format.
|
||||
@ -130,7 +133,8 @@ def format_duration(delta: datetime.timedelta) -> str:
|
||||
raise ValueError("Cannot express negative durations in GEP-2257: {}".format(delta))
|
||||
|
||||
if delta > datetime.timedelta(milliseconds=maxDuration_ms):
|
||||
raise ValueError("Cannot express durations longer than 99999h59m59s999ms in GEP-2257: {}".format(delta))
|
||||
raise ValueError(
|
||||
"Cannot express durations longer than 99999h59m59s999ms in GEP-2257: {}".format(delta))
|
||||
|
||||
# durationpy.to_str() is happy to use floating-point seconds, which
|
||||
# GEP-2257 is _not_ happy with. So start by peeling off any microseconds
|
||||
@ -158,4 +162,3 @@ def format_duration(delta: datetime.timedelta) -> str:
|
||||
delta_str += f"{delta_ms}ms"
|
||||
|
||||
return delta_str
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user