Skip to content

294 fix utc dst#295

Merged
oruebel merged 10 commits intoNeurodataWithoutBorders:mainfrom
cboulay:294-fix-utc-dst
May 1, 2026
Merged

294 fix utc dst#295
oruebel merged 10 commits intoNeurodataWithoutBorders:mainfrom
cboulay:294-fix-utc-dst

Conversation

@cboulay
Copy link
Copy Markdown
Contributor

@cboulay cboulay commented Apr 6, 2026

Fixes #294

  • Adds unit test to show get_utc_offset_seconds matches the OS-reported value (which includes DST)
  • Adds integration test to show that the session_start_time written to the file is not in the future
  • modifies get_utc_offset_seconds to pass tests with platform-specific code for DST correction

Comment thread tests/testNWBFile.cpp Fixed
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.52%. Comparing base (fa10b17) to head (ad686e0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #295      +/-   ##
==========================================
- Coverage   84.55%   84.52%   -0.03%     
==========================================
  Files          57       57              
  Lines        2596     2591       -5     
  Branches      332      332              
==========================================
- Hits         2195     2190       -5     
  Misses        401      401              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@oruebel
Copy link
Copy Markdown
Contributor

oruebel commented Apr 6, 2026

Thanks for the PR. I'll take a look on Wednesday when I'm back at work

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect UTC offset calculation during DST so timestamps (notably session_start_time) are written with the correct timezone offset and don’t appear to be in the future (per nwbinspector’s check_session_start_time_future_date).

Changes:

  • Update get_utc_offset_seconds to use platform-specific, DST-aware mechanisms (tm_gmtoff on Unix/macOS; _get_timezone + _get_dstbias on Windows; adjusted fallback).
  • Add a unit test ensuring get_utc_offset_seconds matches the OS-reported offset (including DST).
  • Add an integration-style test ensuring the written session_start_time is not in the future once converted to UTC.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Utils.hpp Reworks UTC offset computation to be DST-correct using platform-specific approaches and an improved fallback.
tests/testUtilsFunctions.cpp Adds a unit test asserting the computed UTC offset matches OS-provided offset values (DST-inclusive).
tests/testNWBFile.cpp Adds a test that parses session_start_time, converts it to UTC, and asserts it is not in the future.

Comment thread tests/testNWBFile.cpp Outdated
Comment on lines +516 to +522
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4996) // sscanf deprecation
#endif
std::sscanf(readSessionStartTime.c_str(),
"%4d-%2d-%2dT%2d:%2d:%2d.%*d%c%2d:%2d",
&parsed.tm_year,
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::sscanf is used here, but this file doesn’t include <cstdio>, which can cause build failures on some toolchains (e.g., std::sscanf not declared / not in std). Add the proper header (or avoid the std::-qualified overload and include the right C header) to make this compilation unit self-contained.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Comment thread tests/testNWBFile.cpp Outdated
Comment on lines +520 to +530
std::sscanf(readSessionStartTime.c_str(),
"%4d-%2d-%2dT%2d:%2d:%2d.%*d%c%2d:%2d",
&parsed.tm_year,
&parsed.tm_mon,
&parsed.tm_mday,
&parsed.tm_hour,
&parsed.tm_min,
&parsed.tm_sec,
&offset_sign,
&offset_h,
&offset_m);
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value of std::sscanf is ignored. If parsing fails (unexpected format, locale differences, etc.), parsed/offset fields may remain default/partial and the computed epoch becomes meaningless (potentially making the test flaky). Capture the conversion count and REQUIRE it matches the expected number of assignments before using the parsed values.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

@oruebel
Copy link
Copy Markdown
Contributor

oruebel commented Apr 9, 2026

@copilot add an entry to CHANGLOG.md following the existing style

Copy link
Copy Markdown
Contributor

@oruebel oruebel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cboulay could please address the two issues identified by copilot related to the use of std::sscanf (i.e., add the missing include for <cstdio> and a REQUIRE statement to check the return value of std::sscanf. Also, could you please add an entry in CHANGELOG.md to describe the fix from this PR.

cboulay added 2 commits April 30, 2026 11:28
* added #include <cstdio> for std::sscanf
* captured sscanf return into parsed_fields and added REQUIRE(parsed_fields == 9) to fail the test if the timestamp string isn't fully parsed
* In CHANGELOG.md, added a Fixed entry under "Upcoming (~June 2026)" describing the DST fix and crediting @cboulay / PR NeurodataWithoutBorders#295.
@cboulay
Copy link
Copy Markdown
Contributor Author

cboulay commented Apr 30, 2026

@oruebel , sorry it took a while for me to circle back to this but I've made the requested changes.

@cboulay cboulay requested a review from oruebel May 1, 2026 05:42
Copy link
Copy Markdown
Contributor

@oruebel oruebel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for finding and fixing this bug!

@oruebel oruebel merged commit 6571d66 into NeurodataWithoutBorders:main May 1, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getCurrentTime() produces wrong UTC offset when DST is active

5 participants