From cec14e6d5010c758c6f9f41dbd0ffe4abe40a1c6 Mon Sep 17 00:00:00 2001 From: Chris Kerr Date: Sun, 23 May 2021 21:04:29 +0300 Subject: [PATCH] Add '%m.%d.%y' date format for .mpr file timestamps Closes #60 --- galvani/BioLogic.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/galvani/BioLogic.py b/galvani/BioLogic.py index a3786c0..c91d602 100644 --- a/galvani/BioLogic.py +++ b/galvani/BioLogic.py @@ -416,10 +416,18 @@ class MPRfile: if maybe_log_module: log_module, = maybe_log_module - try: - tm = time.strptime(log_module['date'].decode('ascii'), '%m/%d/%y') - except ValueError: - tm = time.strptime(log_module['date'].decode('ascii'), '%m-%d-%y') + date_string = log_module['date'].decode('ascii') + date_formats = ['%m/%d/%y', '%m-%d-%y', '%m.%d.%y'] + for date_format in date_formats: + try: + tm = time.strptime(date_string, date_format) + except ValueError: + continue + else: + break + else: + raise ValueError(f'Could not parse timestamp {date_string!r}' + f' with any of the formats {date_formats}') self.enddate = date(tm.tm_year, tm.tm_mon, tm.tm_mday) # There is a timestamp at either 465 or 469 bytes