File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 2121# really be a big deal.
2222reDuration = re .compile (r'^([0-9]{1,5}(h|m|s|ms)){1,4}$' )
2323
24- # maxDuration_ms is the maximum duration that GEP-2257 can support, in milliseconds.
24+ # maxDuration_ms is the maximum duration that GEP-2257 can support, in
25+ # milliseconds.
2526maxDuration_ms = (((99999 * 3600 ) + (59 * 60 ) + 59 ) * 1_000 ) + 999
2627
28+
2729def parse_duration (duration ) -> datetime .timedelta :
2830 """
2931 Parse GEP-2257 Duration format to a datetime.timedelta object.
@@ -75,6 +77,7 @@ def parse_duration(duration) -> datetime.timedelta:
7577
7678 return durationpy .from_str (duration )
7779
80+
7881def format_duration (delta : datetime .timedelta ) -> str :
7982 """
8083 Format a datetime.timedelta object to GEP-2257 Duration format.
@@ -130,7 +133,8 @@ def format_duration(delta: datetime.timedelta) -> str:
130133 raise ValueError ("Cannot express negative durations in GEP-2257: {}" .format (delta ))
131134
132135 if delta > datetime .timedelta (milliseconds = maxDuration_ms ):
133- raise ValueError ("Cannot express durations longer than 99999h59m59s999ms in GEP-2257: {}" .format (delta ))
136+ raise ValueError (
137+ "Cannot express durations longer than 99999h59m59s999ms in GEP-2257: {}" .format (delta ))
134138
135139 # durationpy.to_str() is happy to use floating-point seconds, which
136140 # GEP-2257 is _not_ happy with. So start by peeling off any microseconds
@@ -158,4 +162,3 @@ def format_duration(delta: datetime.timedelta) -> str:
158162 delta_str += f"{ delta_ms } ms"
159163
160164 return delta_str
161-
You can’t perform that action at this time.
0 commit comments