Fallback to using DateTimeOffset.TryParse if normal parsing doesn't work#118
Merged
Fallback to using DateTimeOffset.TryParse if normal parsing doesn't work#118
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request enhances the DateMath class to support fallback parsing of explicit date expressions when standard date math parsing fails. The implementation adds robust support for parsing plain date strings like "2023-01-01" or "2023-06-15T14:30:00" with appropriate timezone handling and end-of-day adjustments for upper limits.
- Added fallback logic to
TryParseandIsValidExpressionmethods to handle explicit dates when regex matching fails - Implemented comprehensive timezone offset handling for both
DateTimeOffsetandTimeZoneInfocontexts - Expanded test coverage with new test cases for fallback parsing scenarios and updated existing tests to reflect the new acceptance of plain date strings
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Exceptionless.DateTimeExtensions/DateMath.cs |
Added fallback parsing methods and updated main parsing logic to support explicit date expressions |
tests/Exceptionless.DateTimeExtensions.Tests/DateMathTests.cs |
Updated test cases to remove plain date strings from invalid tests and added comprehensive fallback parsing tests |
niemyjski
previously approved these changes
Sep 28, 2025
niemyjski
previously approved these changes
Sep 28, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request enhances the date math parsing logic to support explicit date expressions as a fallback when standard date math parsing fails. Now, expressions like
"2023-01-01"or"2023-06-15T14:30:00"are accepted and parsed correctly, with appropriate handling of time zones and end-of-day adjustments for upper limits. The update also significantly expands and improves the test coverage for these scenarios.Date parsing enhancements:
DateMath.TryParseandIsValidExpressionto attempt parsing as an explicit date when date math parsing fails, supporting bothDateTimeOffsetandTimeZoneInfocontexts. This ensures that plain date strings (with or without time zone info) are now accepted and parsed correctly. [1] [2] [3]Test coverage improvements:
DateMathTests.csto:||anchor, verifying correct offset handling for both explicit and implicit time zones. [1] [2]These changes make date parsing more robust, user-friendly, and consistent across different usage scenarios.