Skip to content

294 fix utc dst#295

Open
cboulay wants to merge 8 commits intoNeurodataWithoutBorders:mainfrom
cboulay:294-fix-utc-dst
Open

294 fix utc dst#295
cboulay wants to merge 8 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

@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.50%. Comparing base (c881be2) to head (7997903).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #295      +/-   ##
==========================================
- Coverage   84.53%   84.50%   -0.03%     
==========================================
  Files          57       57              
  Lines        2593     2588       -5     
  Branches      331      331              
==========================================
- Hits         2192     2187       -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 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 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.

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