Skip to content

Commit 095451c

Browse files
[Bug] Timezone awareness for session start time checks (#471)
* fix timezone awareness for session start time checks * fix * Apply suggestions from code review * Update nwbfile_metadata.py --------- Co-authored-by: Garrett Michael Flynn <[email protected]>
1 parent 8009527 commit 095451c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/nwbinspector/checks/nwbfile_metadata.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ def check_session_start_time_old_date(nwbfile: NWBFile):
2828
"""
2929
session_start_time = nwbfile.session_start_time
3030
dummy_time = datetime(1980, 1, 1)
31-
if session_start_time.tzinfo is not None:
32-
dummy_time = dummy_time.astimezone()
31+
32+
tzinfo = session_start_time.tzinfo
33+
if tzinfo is not None:
34+
dummy_time = dummy_time.astimezone(tzinfo)
35+
3336
if session_start_time <= dummy_time:
3437
return InspectorMessage(
3538
message=(f"The session_start_time ({session_start_time}) may not be set to the true date of the recording.")
@@ -45,8 +48,10 @@ def check_session_start_time_future_date(nwbfile: NWBFile):
4548
"""
4649
session_start_time = nwbfile.session_start_time
4750
current_time = datetime.now()
51+
tzinfo = session_start_time.tzinfo
4852
if session_start_time.tzinfo is not None:
49-
current_time = current_time.astimezone()
53+
current_time = current_time.astimezone(tzinfo)
54+
5055
if session_start_time >= current_time:
5156
return InspectorMessage(
5257
message=f"The session_start_time ({session_start_time}) is set to a future date and time."

0 commit comments

Comments
 (0)