@@ -374,7 +374,7 @@ def values(self):
374374 return self .as_dict ().values ()
375375
376376
377- def parse_time (value ):
377+ def parse_time (time_str : str ):
378378 """Convert a time string to "HH:MM:SS.S"
379379
380380 - leading zeros are added where necessary
@@ -387,29 +387,29 @@ def parse_time(value):
387387 - "6:15:22.00 AM" -> "06:15:22"
388388 - "6:02:22.010 AM" -> "06:02:22.01"
389389 """
390+ # remove escape characters.
391+ # See https://github.com/AFM-analysis/afmformats/issues/43
392+ time_str = time_str .replace ("\\ " , "" )
393+
390394 # fix AM/PM
391- if value .count (" " ):
392- time , ap = value .split ()
395+ if time_str .count (" " ):
396+ time_str , ap = time_str .split ()
393397 if ap == "PM" : # convert to 24h
394- timetup = time .split (":" )
398+ timetup = time_str .split (":" )
395399 timetup [0 ] = str (int (timetup [0 ]) + 12 )
396- time = ":" .join (timetup )
400+ time_str = ":" .join (timetup )
397401 else :
398- time = value
402+ time_str = time_str
403+
399404 # convert to time with leading zeros and stripped subseconds
400- hh , mm , ss = time .split (":" )
405+ hh , mm , ss = time_str .split (":" )
401406 if ss .count ("." ):
402407 ss0 , ss1 = ss .split ("." )
403408 ss1 = ("." + ss1 ).rstrip (".0" )
404409 else :
405410 ss0 = ss
406411 ss1 = ""
407412
408- # strip escape characters.
409- # See https://github.com/AFM-analysis/afmformats/issues/43
410- hh = hh .strip ("\\ " )
411- mm = mm .strip ("\\ " )
412-
413413 newvalue = ":" .join (["{:02d}" .format (int (hh )),
414414 "{:02d}" .format (int (mm )),
415415 "{:02d}" .format (int (ss0 )) + ss1
0 commit comments