File tree 1 file changed +6
-3
lines changed
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 21
21
# really be a big deal.
22
22
reDuration = re .compile (r'^([0-9]{1,5}(h|m|s|ms)){1,4}$' )
23
23
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.
25
26
maxDuration_ms = (((99999 * 3600 ) + (59 * 60 ) + 59 ) * 1_000 ) + 999
26
27
28
+
27
29
def parse_duration (duration ) -> datetime .timedelta :
28
30
"""
29
31
Parse GEP-2257 Duration format to a datetime.timedelta object.
@@ -75,6 +77,7 @@ def parse_duration(duration) -> datetime.timedelta:
75
77
76
78
return durationpy .from_str (duration )
77
79
80
+
78
81
def format_duration (delta : datetime .timedelta ) -> str :
79
82
"""
80
83
Format a datetime.timedelta object to GEP-2257 Duration format.
@@ -130,7 +133,8 @@ def format_duration(delta: datetime.timedelta) -> str:
130
133
raise ValueError ("Cannot express negative durations in GEP-2257: {}" .format (delta ))
131
134
132
135
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 ))
134
138
135
139
# durationpy.to_str() is happy to use floating-point seconds, which
136
140
# GEP-2257 is _not_ happy with. So start by peeling off any microseconds
@@ -158,4 +162,3 @@ def format_duration(delta: datetime.timedelta) -> str:
158
162
delta_str += f"{ delta_ms } ms"
159
163
160
164
return delta_str
161
-
You can’t perform that action at this time.
0 commit comments