From c5295ff83c7c693061fc8bb1647a2950a982cfa2 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:28:28 -0400 Subject: [PATCH 1/4] fix timezone awareness for session start time checks --- src/nwbinspector/checks/nwbfile_metadata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nwbinspector/checks/nwbfile_metadata.py b/src/nwbinspector/checks/nwbfile_metadata.py index a5fbae66e..897277dba 100644 --- a/src/nwbinspector/checks/nwbfile_metadata.py +++ b/src/nwbinspector/checks/nwbfile_metadata.py @@ -29,7 +29,7 @@ def check_session_start_time_old_date(nwbfile: NWBFile): session_start_time = nwbfile.session_start_time dummy_time = datetime(1980, 1, 1) if session_start_time.tzinfo is not None: - dummy_time = dummy_time.astimezone() + dummy_time.tzinfo = session_start_time.tzinfo if session_start_time <= dummy_time: return InspectorMessage( message=(f"The session_start_time ({session_start_time}) may not be set to the true date of the recording.") From 997e22ca44a3d84464b3f3723921a3616ad8dfac Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:23:11 -0400 Subject: [PATCH 2/4] fix --- src/nwbinspector/checks/nwbfile_metadata.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nwbinspector/checks/nwbfile_metadata.py b/src/nwbinspector/checks/nwbfile_metadata.py index 897277dba..92739a47e 100644 --- a/src/nwbinspector/checks/nwbfile_metadata.py +++ b/src/nwbinspector/checks/nwbfile_metadata.py @@ -29,7 +29,7 @@ def check_session_start_time_old_date(nwbfile: NWBFile): session_start_time = nwbfile.session_start_time dummy_time = datetime(1980, 1, 1) if session_start_time.tzinfo is not None: - dummy_time.tzinfo = session_start_time.tzinfo + dummy_time.replace(tzinfo=session_start_time.tzinfo) if session_start_time <= dummy_time: return InspectorMessage( message=(f"The session_start_time ({session_start_time}) may not be set to the true date of the recording.") @@ -46,7 +46,7 @@ def check_session_start_time_future_date(nwbfile: NWBFile): session_start_time = nwbfile.session_start_time current_time = datetime.now() if session_start_time.tzinfo is not None: - current_time = current_time.astimezone() + current_time.replace(tzinfo=session_start_time.tzinfo) if session_start_time >= current_time: return InspectorMessage( message=f"The session_start_time ({session_start_time}) is set to a future date and time." From 4f70569ab42b42ee9f8ddf1661678ef30a2d5dd1 Mon Sep 17 00:00:00 2001 From: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:54:54 -0400 Subject: [PATCH 3/4] Apply suggestions from code review --- src/nwbinspector/checks/nwbfile_metadata.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nwbinspector/checks/nwbfile_metadata.py b/src/nwbinspector/checks/nwbfile_metadata.py index 92739a47e..86fbebc04 100644 --- a/src/nwbinspector/checks/nwbfile_metadata.py +++ b/src/nwbinspector/checks/nwbfile_metadata.py @@ -29,7 +29,7 @@ def check_session_start_time_old_date(nwbfile: NWBFile): session_start_time = nwbfile.session_start_time dummy_time = datetime(1980, 1, 1) if session_start_time.tzinfo is not None: - dummy_time.replace(tzinfo=session_start_time.tzinfo) + dummy_time = dummy_time.replace(tzinfo=session_start_time.tzinfo) if session_start_time <= dummy_time: return InspectorMessage( message=(f"The session_start_time ({session_start_time}) may not be set to the true date of the recording.") @@ -46,7 +46,7 @@ def check_session_start_time_future_date(nwbfile: NWBFile): session_start_time = nwbfile.session_start_time current_time = datetime.now() if session_start_time.tzinfo is not None: - current_time.replace(tzinfo=session_start_time.tzinfo) + current_time = current_time.replace(tzinfo=session_start_time.tzinfo) if session_start_time >= current_time: return InspectorMessage( message=f"The session_start_time ({session_start_time}) is set to a future date and time." From 4e900055b5669cc89e54a021409a0d0217d87470 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Tue, 4 Jun 2024 17:13:52 -0700 Subject: [PATCH 4/4] Update nwbfile_metadata.py --- src/nwbinspector/checks/nwbfile_metadata.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/nwbinspector/checks/nwbfile_metadata.py b/src/nwbinspector/checks/nwbfile_metadata.py index 86fbebc04..5802beccf 100644 --- a/src/nwbinspector/checks/nwbfile_metadata.py +++ b/src/nwbinspector/checks/nwbfile_metadata.py @@ -28,8 +28,11 @@ def check_session_start_time_old_date(nwbfile: NWBFile): """ session_start_time = nwbfile.session_start_time dummy_time = datetime(1980, 1, 1) - if session_start_time.tzinfo is not None: - dummy_time = dummy_time.replace(tzinfo=session_start_time.tzinfo) + + tzinfo = session_start_time.tzinfo + if tzinfo is not None: + dummy_time = dummy_time.astimezone(tzinfo) + if session_start_time <= dummy_time: return InspectorMessage( 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): """ session_start_time = nwbfile.session_start_time current_time = datetime.now() + tzinfo = session_start_time.tzinfo if session_start_time.tzinfo is not None: - current_time = current_time.replace(tzinfo=session_start_time.tzinfo) + current_time = current_time.astimezone(tzinfo) + if session_start_time >= current_time: return InspectorMessage( message=f"The session_start_time ({session_start_time}) is set to a future date and time."