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
Copy file name to clipboardExpand all lines: README.md
+42-2Lines changed: 42 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,12 +56,52 @@ var wildcardRange = DateTimeRange.Parse("[2023-01-01 TO *]", DateTime.Now); // F
56
56
57
57
#### Date Math Features
58
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):
59
+
Supports full [Elasticsearch date math syntax](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#date-math):
60
60
61
61
-**Anchors**: `now`, explicit dates with `||` separator
-**Timezone Support**: Preserves explicit timezones (`Z`, `+05:00`, `-08:00`) or uses system timezone as fallback
65
+
-**Escaped slashes**: `\/d` is treated identically to `/d` for contexts where `/` must be escaped
66
+
67
+
##### Real-World Patterns
68
+
69
+
```csharp
70
+
// Common date range queries
71
+
varthisMonth=DateTimeRange.Parse("[now/M TO now/M]", now); // Start of month through end of month
72
+
varlastMonth=DateTimeRange.Parse("[now-1M/M TO now/M}", now); // Start of last month through start of this month
73
+
varyearToDate=DateTimeRange.Parse("[now/y TO now]", now); // Start of year through now
74
+
varlast7Days=DateTimeRange.Parse("[now-7d/d TO now]", now); // Start of 7 days ago through now
75
+
varlast15Minutes=DateTimeRange.Parse("[now-15m TO now]", now); // 15 minutes ago through now
76
+
varlast24Hours=DateTimeRange.Parse("[now-24h TO now]", now); // 24 hours ago through now
77
+
vartomorrow=DateTimeRange.Parse("[now+1d/d TO now+1d/d]", now); // Start through end of tomorrow
78
+
79
+
// Short-form comparison operators
80
+
varrecentItems=DateTimeRange.Parse(">=now-1h", now); // From 1 hour ago to max
81
+
varfutureOnly=DateTimeRange.Parse(">now", now); // After now to max
82
+
varbeforeToday=DateTimeRange.Parse("<now/d", now); // Min to start of today
83
+
varthroughToday=DateTimeRange.Parse("<=now/d", now); // Min to end of today
84
+
```
85
+
86
+
##### Rounding Behavior with Boundaries
87
+
88
+
Rounding direction (`/d`, `/M`, etc.) is controlled by boundary inclusivity, following [Elasticsearch range query rounding rules](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html#date-math-rounding):
89
+
90
+
| Boundary | Bracket | Operator | Rounding direction |`now/d` resolves to |
0 commit comments