Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Timezone awareness for session start time checks #471

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/nwbinspector/checks/nwbfile_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.astimezone()

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.")
Expand All @@ -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.astimezone()
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."
Expand Down
Loading