@@ -190,27 +190,6 @@ def _get_column_repeat(self, cell) -> int:
190
190
191
191
return int (cell .attributes .get ((TABLENS , "number-columns-repeated" ), 1 ))
192
192
193
- def _parse_odf_time (self , value : str ) -> datetime .time :
194
- """
195
- This helper function parses ODF time value
196
- """
197
- parts = ODF_ISOTIME_PATTERN .match (value )
198
- if parts is None :
199
- raise ValueError (f"Failed to parse ODF time value: { value } " )
200
- hours , minutes , seconds , _ , second_part = parts .group (* range (1 , 6 ))
201
- if second_part is None :
202
- microseconds = 0
203
- else :
204
- microseconds = int (int (second_part ) * pow (10 , 6 - len (second_part )))
205
- return datetime .time (
206
- # ignore date part from some representations
207
- # and datetime.time restrict hour values to 0..23
208
- hour = int (hours ) % 24 ,
209
- minute = int (minutes ),
210
- second = int (seconds ),
211
- microsecond = microseconds ,
212
- )
213
-
214
193
def _get_cell_value (self , cell ) -> Scalar | NaTType :
215
194
from odf .namespaces import OFFICENS
216
195
@@ -243,10 +222,9 @@ def _get_cell_value(self, cell) -> Scalar | NaTType:
243
222
cell_value = cell .attributes .get ((OFFICENS , "date-value" ))
244
223
return pd .Timestamp (cell_value )
245
224
elif cell_type == "time" :
246
- cell_value = cell .attributes .get ((OFFICENS , "time-value" ))
247
- stamp = self ._parse_odf_time (str (cell_value ))
225
+ cell_value = self ._get_cell_time_value (cell )
248
226
# cast needed here because Scalar doesn't include datetime.time
249
- return cast (Scalar , stamp )
227
+ return cast (Scalar , cell_value )
250
228
else :
251
229
self .close ()
252
230
raise ValueError (f"Unrecognized type { cell_type } " )
@@ -277,3 +255,28 @@ def _get_cell_string_value(self, cell) -> str:
277
255
else :
278
256
value .append (str (fragment ).strip ("\n " ))
279
257
return "" .join (value )
258
+
259
+ def _get_cell_time_value (self , cell ) -> datetime .time :
260
+ """
261
+ This helper function parses ODF time value
262
+ """
263
+ from odf .namespaces import OFFICENS
264
+
265
+ value = cell .attributes .get ((OFFICENS , "time-value" ))
266
+ parts = ODF_ISOTIME_PATTERN .match (value )
267
+ if parts is None :
268
+ raise ValueError (f"Failed to parse ODF time value: { value } " )
269
+ hours , minutes , seconds , _ , second_part = parts .group (* range (1 , 6 ))
270
+ if second_part is None :
271
+ microseconds = 0
272
+ else :
273
+ microseconds = int (int (second_part ) * pow (10 , 6 - len (second_part )))
274
+
275
+ return datetime .time (
276
+ # ignore date part from some representations
277
+ # and datetime.time restrict hour values to 0..23
278
+ hour = int (hours ) % 24 ,
279
+ minute = int (minutes ),
280
+ second = int (seconds ),
281
+ microsecond = microseconds ,
282
+ )
0 commit comments