Skip to content

Conversation

ejsmith
Copy link
Member

@ejsmith ejsmith commented Sep 28, 2025

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:

  • Added fallback logic to DateMath.TryParse and IsValidExpression to attempt parsing as an explicit date when date math parsing fails, supporting both DateTimeOffset and TimeZoneInfo contexts. This ensures that plain date strings (with or without time zone info) are now accepted and parsed correctly. [1] [2] [3]

Test coverage improvements:

  • Updated and expanded tests in DateMathTests.cs to:
    • Remove invalidation of plain date strings as test cases, reflecting new acceptance of such inputs. [1] [2]
    • Add tests for fallback parsing, including correct offset application, end-of-day adjustment for upper limits, and preservation of explicit time zone offsets.
    • Update time zone-related tests to use plain date expressions instead of requiring the || anchor, verifying correct offset handling for both explicit and implicit time zones. [1] [2]
    • Add plain date strings to the list of valid expressions in theory-driven tests.

These changes make date parsing more robust, user-friendly, and consistent across different usage scenarios.

@ejsmith ejsmith requested a review from Copilot September 28, 2025 02:46
@CLAassistant
Copy link

CLAassistant commented Sep 28, 2025

CLA assistant check
All committers have signed the CLA.

@ejsmith ejsmith requested a review from niemyjski September 28, 2025 02:47
Copy link

@Copilot 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

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 TryParse and IsValidExpression methods to handle explicit dates when regex matching fails
  • Implemented comprehensive timezone offset handling for both DateTimeOffset and TimeZoneInfo contexts
  • 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
niemyjski previously approved these changes Sep 28, 2025
niemyjski
niemyjski previously approved these changes Sep 28, 2025
@ejsmith ejsmith merged commit cabdd34 into main Sep 28, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants