From dc4e31ccc5172463acd41efb2790e92cff22d5a7 Mon Sep 17 00:00:00 2001 From: Ruben Verweij Date: Tue, 19 Sep 2017 11:26:15 +0200 Subject: [PATCH] Add additional date formats for parsing raw metadata --- nd2reader/common.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/nd2reader/common.py b/nd2reader/common.py index 070b6fc..df5ddcf 100644 --- a/nd2reader/common.py +++ b/nd2reader/common.py @@ -198,15 +198,12 @@ def parse_date(text_info): for line in text_info.values(): line = line.decode("utf8") # ND2s seem to randomly switch between 12- and 24-hour representations. - try: - absolute_start = datetime.strptime(line, "%m/%d/%Y %H:%M:%S") - except (TypeError, ValueError): + possible_formats = ["%m/%d/%Y %H:%M:%S", "%m/%d/%Y %I:%M:%S %p", "%d/%m/%Y %H:%M:%S"] + for date_format in possible_formats: try: - absolute_start = datetime.strptime(line, "%m/%d/%Y %I:%M:%S %p") + absolute_start = datetime.strptime(line, date_format) except (TypeError, ValueError): - absolute_start = None - - if absolute_start is not None: + continue return absolute_start return None