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
Quickly work with date ranges. . Check out our [unit tests](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/blob/main/tests/Exceptionless.DateTimeExtensions.Tests/DateTimeRangeTests.cs) for more usage samples.
37
+
Quickly work with date ranges with support for Elasticsearch-style date math expressions and bracket notation. Check out our [unit tests](https://github.com/exceptionless/Exceptionless.DateTimeExtensions/blob/main/tests/Exceptionless.DateTimeExtensions.Tests/DateTimeRangeTests.cs) for more usage samples.
// Supports timezone-aware operations: Z (UTC), +05:00, -08:00
49
+
50
+
// Bracket notation support [start TO end]
51
+
varbracketRange=DateTimeRange.Parse("[2023-01-01 TO 2023-12-31]", DateTime.Now);
52
+
53
+
// Wildcard support for open-ended ranges
54
+
varwildcardRange=DateTimeRange.Parse("[2023-01-01 TO *]", DateTime.Now); // From date to infinity
44
55
```
45
56
57
+
#### Date Math Features
58
+
59
+
Supports full Elasticsearch date math syntax following [official specifications](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#date-math):
60
+
61
+
-**Anchors**: `now`, explicit dates with `||` separator
-**Timezone Support**: Preserves explicit timezones (`Z`, `+05:00`, `-08:00`) or uses system timezone as fallback
65
+
66
+
Examples:
67
+
68
+
-`now+1h` - One hour from now
69
+
-`now-1d/d` - Start of yesterday
70
+
-`2025-01-01T01:25:35Z||+3d/d` - January 4th, 2025 (start of day) in UTC
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
+
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
// Result will still have +05:00 offset, not Eastern time offset
128
+
```
129
+
130
+
The `DateMath` utility supports the same comprehensive syntax as `DateTimeRange` but provides a simpler API for direct parsing operations.
131
+
46
132
### TimeUnit
47
133
48
134
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