@@ -184,6 +184,28 @@ def parse_tz_offset(tokens: ListOf(str)) -> int:
184
184
else :
185
185
raise ValueError ('Invalid tz offset: ' )
186
186
187
+ @Entrypoint
188
+ @staticmethod
189
+ def parse_iso_time (time_tokens : ListOf (str )):
190
+ hour , minute , second = 0 , 0 , 0.0
191
+
192
+ if len (time_tokens ) == 1 :
193
+ if len (time_tokens [0 ]) == 6 :
194
+ hour , minute , second = int (time_tokens [0 ][:2 ]), int (time_tokens [0 ][2 :4 ]), float (time_tokens [0 ][4 :6 ])
195
+ elif len (time_tokens [0 ]) == 4 :
196
+ hour , minute , second = int (time_tokens [0 ][:2 ]), int (time_tokens [0 ][2 :4 ]), 0.0
197
+ elif len (time_tokens [0 ]) == 2 :
198
+ hour , minute , second = int (time_tokens [0 ][:2 ]), 0 , 0.0
199
+ elif len (time_tokens ) == 2 :
200
+ hour , minute , second = int (time_tokens [0 ]), int (time_tokens [1 ]), 0.0
201
+ elif len (time_tokens ) == 3 :
202
+ hour , minute , second = int (time_tokens [0 ]), int (time_tokens [1 ]), float (time_tokens [2 ])
203
+
204
+ if not is_time (hour , minute , second ):
205
+ raise ValueError ('Invalid time: ' , time_tokens )
206
+
207
+ return time_to_seconds (hour , minute , second )
208
+
187
209
@Entrypoint
188
210
@staticmethod
189
211
def parse_iso (date_str : str ) -> float :
@@ -224,6 +246,11 @@ def parse_iso(date_str: str) -> float:
224
246
if not is_date (year , month , day ):
225
247
raise ValueError ('Invalid date_tokens: ' , date_tokens )
226
248
249
+ dt = date_to_seconds (year , month , day )
250
+
251
+ if cursor >= len (tokens ):
252
+ return dt
253
+
227
254
# Process time segement
228
255
time_tokens = ListOf (str )([])
229
256
while cursor < len (tokens ):
@@ -236,32 +263,15 @@ def parse_iso(date_str: str) -> float:
236
263
time_tokens .append (tokens [cursor ])
237
264
cursor += 1
238
265
239
- hour , minute , second = 0 , 0 , 0.0
240
-
241
- if len (time_tokens ) == 1 :
242
- if len (time_tokens [0 ]) == 6 :
243
- hour , minute , second = int (time_tokens [0 ][:2 ]), int (time_tokens [0 ][2 :4 ]), float (time_tokens [0 ][4 :6 ])
244
- elif len (time_tokens [0 ]) == 4 :
245
- hour , minute , second = int (time_tokens [0 ][:2 ]), int (time_tokens [0 ][2 :4 ]), 0.0
246
- elif len (time_tokens [0 ]) == 2 :
247
- hour , minute , second = int (time_tokens [0 ][:2 ]), 0 , 0.0
248
- elif len (time_tokens ) == 2 :
249
- hour , minute , second = int (time_tokens [0 ]), int (time_tokens [1 ]), 0.0
250
- elif len (time_tokens ) == 3 :
251
- hour , minute , second = int (time_tokens [0 ]), int (time_tokens [1 ]), float (time_tokens [2 ])
252
-
253
- if not is_time (hour , minute , second ):
254
- raise ValueError ('Invalid time: ' , time_tokens )
266
+ dt += DateParser .parse_iso_time (time_tokens )
267
+ if cursor >= len (tokens ):
268
+ return dt
255
269
256
270
tz_tokens = ListOf (str )([])
257
271
while cursor < len (tokens ):
258
272
tz_tokens .append (tokens [cursor ])
259
273
cursor += 1
260
274
261
- dt = date_to_seconds (year , month , day ) + time_to_seconds (hour , minute , second )
262
- if len (tz_tokens ) == 0 :
263
- return dt
264
-
265
275
if len (tz_tokens ) == 1 :
266
276
tz_offset = tz_abbr_to_utc_offset (tz_tokens [0 ], dt )
267
277
elif tz_tokens [0 ] == PLUS or tz_tokens [0 ] == DASH :
0 commit comments