-
Notifications
You must be signed in to change notification settings - Fork 1
fix: handle time parsing overload gracefully #35
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
Merged
greghuels
merged 11 commits into
main
from
greg.huels/FFESUPPORT-348/fix-end-date-parsing-2
Dec 2, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
72c8d01
fix: use max-time as fallback when parsing fails for end date
greghuels 74350b2
chore: run CI tests on a variety of operating systems
greghuels 610de88
fix: use cmake --build for cross-platform compatibility
greghuels 1b14afa
fix: resolve MSVC compiler warnings on Windows
greghuels 88e95cc
fix: disable warnings for third-party code on Windows
greghuels 96a7bd9
fix: Windows test build and execution issues
greghuels 688fdc4
update to include re2
greghuels 7b83775
fix windows CI test
greghuels 72a7f12
fix date parsing implementation to handle both underflow and overflow
greghuels 62a765b
Update src/json_utils.hpp
greghuels be1e47d
CR changes
greghuels File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,8 @@ | |
|
|
||
| namespace eppoclient { | ||
|
|
||
| std::chrono::system_clock::time_point parseISOTimestamp(const std::string& timestamp) { | ||
| std::chrono::system_clock::time_point parseISOTimestamp(const std::string& timestamp, | ||
| std::string& error) { | ||
| std::tm tm = {}; | ||
| char dot = '\0'; | ||
| int milliseconds = 0; | ||
|
|
@@ -17,6 +18,7 @@ std::chrono::system_clock::time_point parseISOTimestamp(const std::string& times | |
| ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%S"); | ||
|
|
||
| if (ss.fail()) { | ||
| error = "Invalid timestamp: " + timestamp; | ||
| return std::chrono::system_clock::time_point(); | ||
| } | ||
|
|
||
|
|
@@ -52,7 +54,32 @@ std::chrono::system_clock::time_point parseISOTimestamp(const std::string& times | |
| #endif | ||
|
|
||
| if (time_c == -1) { | ||
| return std::chrono::system_clock::time_point(); | ||
| // Validate that we have at least 4 characters and they're all digits | ||
| if (timestamp.length() < 4) { | ||
| error = "Invalid timestamp: " + timestamp; | ||
| return std::chrono::system_clock::time_point(); | ||
| } | ||
|
|
||
| std::string yearStr = timestamp.substr(0, 4); | ||
| for (char c : yearStr) { | ||
| if (!std::isdigit(static_cast<unsigned char>(c))) { | ||
| error = "Invalid timestamp: " + timestamp; | ||
| return std::chrono::system_clock::time_point(); | ||
| } | ||
| } | ||
|
|
||
| // Validate that the 5th character is a dash (if it exists) | ||
| if (timestamp.length() > 4 && timestamp[4] != '-') { | ||
| error = "Invalid timestamp: " + timestamp; | ||
| return std::chrono::system_clock::time_point(); | ||
| } | ||
|
|
||
| int year = std::stoi(yearStr); | ||
| if (year < 1970) { | ||
| return std::chrono::system_clock::time_point::min(); | ||
| } else { | ||
| return std::chrono::system_clock::time_point::max(); | ||
| } | ||
|
Comment on lines
+57
to
+82
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: there's a lot of shenanigans in this section, so worth adding a comment explaining the rational — i.e. that |
||
| } | ||
| auto tp = std::chrono::system_clock::from_time_t(time_c); | ||
| tp += std::chrono::milliseconds(milliseconds); | ||
|
|
@@ -61,7 +88,12 @@ std::chrono::system_clock::time_point parseISOTimestamp(const std::string& times | |
|
|
||
| std::string formatISOTimestamp(const std::chrono::system_clock::time_point& tp) { | ||
| auto tt = std::chrono::system_clock::to_time_t(tp); | ||
| std::tm tm = *std::gmtime(&tt); | ||
| std::tm tm = {}; | ||
| #ifdef _WIN32 | ||
| gmtime_s(&tm, &tt); | ||
| #else | ||
| tm = *std::gmtime(&tt); | ||
| #endif | ||
|
|
||
| // Add milliseconds | ||
| auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch()) % 1000; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is implemented in #42