You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a `DateMath` utility class for parsing Elasticsearch date math expressions, offering standalone date math functionality without range capabilities.
This utility supports parsing expressions with `now`, explicit dates, operations, and time units, providing a simpler API for direct parsing operations.
Includes comprehensive unit tests for various parsing scenarios, edge cases, and timezone handling.
Copy file name to clipboardExpand all lines: README.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,37 @@ Examples:
70
70
-`2025-01-01T01:25:35Z||+3d/d` - January 4th, 2025 (start of day) in UTC
71
71
-`2023-06-15T14:30:00+05:00||+1M-2d` - One month minus 2 days from the specified date/time in +05:00 timezone
72
72
73
+
### DateMath Utility
74
+
75
+
For applications that need standalone date math parsing without the range functionality, the `DateMath` utility class provides direct access to Elasticsearch date math expression parsing. Check out our [unit tests](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/blob/main/tests/Exceptionless.DateTimeExtensions.Tests/DateMathTests.cs) for more usage samples.
76
+
77
+
```csharp
78
+
usingExceptionless.DateTimeExtensions;
79
+
80
+
// Parse date math expressions with standard .NET conventions
81
+
varbaseTime=DateTimeOffset.Now;
82
+
83
+
// Parse method - throws ArgumentException on invalid input
84
+
varresult=DateMath.Parse("now+1h", baseTime);
85
+
varrounded=DateMath.Parse("now-1d/d", baseTime, isUpperLimit: false); // Start of yesterday
86
+
87
+
// TryParse method - returns bool for success/failure
88
+
if (DateMath.TryParse("2023.06.15||+1M/d", baseTime, false, outvarparsed)) {
89
+
// Successfully parsed: June 15, 2023 + 1 month, rounded to start of day
The `DateMath` utility supports the same comprehensive syntax as `DateTimeRange` but provides a simpler API for direct parsing operations.
103
+
73
104
### TimeUnit
74
105
75
106
Quickly work with time units. . Check out our [unit tests](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/blob/main/tests/Exceptionless.DateTimeExtensions.Tests/TimeUnitTests.cs) for more usage samples.
0 commit comments