Skip to content

[23440] Fix time utils time_t 64 bits in windows#134

Merged
rsanchez15 merged 8 commits intomainfrom
fix/time_utils_overflow
Jul 16, 2025
Merged

[23440] Fix time utils time_t 64 bits in windows#134
rsanchez15 merged 8 commits intomainfrom
fix/time_utils_overflow

Conversation

@EugenioCollado
Copy link
Copy Markdown
Contributor

This PR addresses an issue where Timestamp::max() or Timestamp::min() may exceed the representable range of std::tm, as time_t can be a 64-bit long long int. Specifically, std::tm in Windows cannot express dates before 1970 or beyond 2038.

To resolve this, the PR truncates time_t when converting it to std::tm and adjusts Timestamp::max() and Timestamp::min() to fit within the accepted range on Windows (0 to 2^32).

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.

Project coverage is 62.29%. Comparing base (89c1650) to head (b8f3f7c).

Files with missing lines Patch % Lines
cpp_utils/src/cpp/time/time_utils.cpp 78.57% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #134      +/-   ##
==========================================
- Coverage   62.96%   62.29%   -0.68%     
==========================================
  Files          65       65              
  Lines        1974     1867     -107     
  Branches      589      535      -54     
==========================================
- Hits         1243     1163      -80     
+ Misses        393      384       -9     
+ Partials      338      320      -18     

☔ 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.

Comment thread cpp_utils/include/cpp_utils/time/time_utils.hpp
Comment thread cpp_utils/test/unittest/time/time_utils_test.cpp
Comment thread cpp_utils/src/cpp/time/time_utils.cpp Outdated
Comment thread cpp_utils/src/cpp/time/time_utils.cpp Outdated
Comment thread cpp_utils/src/cpp/time/time_utils.cpp Outdated
Comment thread cpp_utils/src/cpp/time/time_utils.cpp Outdated
@rsanchez15
Copy link
Copy Markdown
Collaborator

This PR addresses some issues arising from eProsima/DDS-Record-Replay#173.

Revisit once the work on SQL support for DDS Recorder is resumed.

EugenioCollado and others added 7 commits July 2, 2025 08:10
Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com>
Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com>
Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com>
Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com>
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
@Mario-DL Mario-DL force-pushed the fix/time_utils_overflow branch from 0449f8f to ecd4908 Compare July 2, 2025 06:11
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
@Mario-DL Mario-DL changed the title Fix time utils time_t 64 bits in windows [23440] Fix time utils time_t 64 bits in windows Jul 2, 2025
@Mario-DL
Copy link
Copy Markdown
Contributor

Mario-DL commented Jul 2, 2025

In Windows, time_t will be 64 bits or 32 bits depending on the plaform, hence different versions of gmtime() are used under the hood: _gmtime32() or _gmtime64() (https://learn.microsoft.com/es-es/cpp/c-runtime-library/reference/gmtime-gmtime32-gmtime64?view=msvc-170).
The lower bound for a time_t in Windows is 0 (1970-1-1) and the upper one is 31/12/3000 23:59:59 for 64 bits and 18/01/2038 23:59:59 for a 32 bits windows.

I updated the date_to_string(), timestamp_to_string(), time_to_string() and string_to_timestamp() methods as @juanlofer-eprosima suggested.
Thanks @EugenioCollado for the detection and proposal.

@rsanchez15 rsanchez15 merged commit 757a4cd into main Jul 16, 2025
15 checks passed
@rsanchez15 rsanchez15 deleted the fix/time_utils_overflow branch July 16, 2025 13:22
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.

5 participants