Skip to content

Commit cb13a30

Browse files
authored
Neuronexus datetime parsing (#1572)
* neuronexus datetime parsing * exclude some python verisons * another try * correct version check * could be * try another
1 parent 499db96 commit cb13a30

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

neo/rawio/neuronexusrawio.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
from pathlib import Path
3838
import json
3939
import datetime
40+
import sys
41+
import re
4042

4143
import numpy as np
4244

@@ -219,21 +221,15 @@ def _parse_header(self):
219221
# Add the minimum annotations
220222
self._generate_minimal_annotations()
221223

222-
# date comes out as:
223-
# year-month-daydayofweektime all as a string so we need to prep it for
224-
# entering into datetime
225-
# example: '2024-07-01T13:04:49.4972245-04:00'
226-
stringified_date_list = self.metadata['status']['start_time'].split('-')
227-
year = int(stringified_date_list[0])
228-
month = int(stringified_date_list[1])
229-
day = int(stringified_date_list[2][:2]) # day should be first two digits of the third item in list
230-
time_info = stringified_date_list[2].split(':')
231-
hour = int(time_info[0][-2:])
232-
minute = int(time_info[1])
233-
second = int(float(time_info[2]))
234-
microsecond = int(1000 * 1000 * (float(time_info[2]) - second))# second -> micro is 1000 * 1000
235-
236-
rec_datetime = datetime.datetime(year, month, day, hour, minute, second, microsecond)
224+
# date comes out as: '2024-07-01T13:04:49.4972245-04:00' so in ISO format
225+
datetime_string = self.metadata["status"]["start_time"]
226+
227+
# Python 3.10 and older expect iso format to only have 3 or 6 decimal places
228+
if sys.version_info.minor < 11:
229+
datetime_string = re.sub(r"(\.\d{6})\d+", r"\1", datetime_string)
230+
231+
rec_datetime = datetime.datetime.fromisoformat(datetime_string)
232+
237233
bl_annotations = self.raw_annotations["blocks"][0]
238234
seg_annotations = bl_annotations["segments"][0]
239235
for d in (bl_annotations, seg_annotations):

0 commit comments

Comments
 (0)