-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Eschew leniency when parsing time zones #77267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
980a28d
6380825
c729086
0948bb6
574f9ee
f760b6e
c0328ef
91e3007
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| setup: | ||
| - do: | ||
| indices.create: | ||
| index: test | ||
| body: | ||
| settings: | ||
| number_of_replicas: 0 | ||
| mappings: | ||
| properties: | ||
| mydate: | ||
| type: date | ||
| format: "uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSSZZZZZ" | ||
|
|
||
| - do: | ||
| cluster.health: | ||
| wait_for_status: green | ||
|
|
||
| - do: | ||
| index: | ||
| index: test | ||
| id: 1 | ||
| body: { "mydate": "2021-08-12T01:00:00.000000000+02:00" } | ||
|
|
||
| - do: | ||
| indices.refresh: {} | ||
|
|
||
| --- | ||
| "respect offsets in range bounds": | ||
| - skip: | ||
| version: " - 7.99.99" | ||
| reason: "Fixed in 7.16 (backport pending)" | ||
| - do: | ||
| search: | ||
| rest_total_hits_as_int: true | ||
| body: { | ||
| "query": { | ||
| "match_all": {} | ||
| }, | ||
| "aggregations": { | ||
| "myagg": { | ||
| "date_range": { | ||
| "field": "mydate", | ||
| "ranges": [ | ||
| { | ||
| "from": "2021-08-12T00:00:00.000000000+02:00", | ||
| "to": "2021-08-12T02:00:00.000000000+02:00" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| - match: { hits.total: 1 } | ||
| - length: { aggregations.myagg.buckets: 1 } | ||
| - match: { aggregations.myagg.buckets.0.from_as_string: "2021-08-11T22:00:00.000000000Z" } | ||
| - match: { aggregations.myagg.buckets.0.from: 1628719200000 } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we could add human readable date in a comment to help with readability? |
||
| - match: { aggregations.myagg.buckets.0.to_as_string: "2021-08-12T00:00:00.000000000Z" } | ||
| - match: { aggregations.myagg.buckets.0.to: 1628726400000 } | ||
| - match: { aggregations.myagg.buckets.0.doc_count: 1 } | ||
|
|
||
| --- | ||
| "offsets and timezones play nicely together": | ||
| - skip: | ||
| version: " - 7.99.99" | ||
| reason: "Fixed in 7.16 (backport pending)" | ||
| - do: | ||
| search: | ||
| rest_total_hits_as_int: true | ||
| body: { | ||
| "query": { | ||
| "match_all": {} | ||
| }, | ||
| "aggregations": { | ||
| "myagg": { | ||
| "date_range": { | ||
| "time_zone": "America/New_York", | ||
| "field": "mydate", | ||
| "ranges": [ | ||
| { | ||
| "from": "2021-08-12T00:00:00.000000000+02:00", | ||
| "to": "2021-08-12T02:00:00.000000000+02:00" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| - match: { hits.total: 1 } | ||
| - length: { aggregations.myagg.buckets: 1 } | ||
| - match: { aggregations.myagg.buckets.0.from_as_string: "2021-08-11T18:00:00.000000000-04:00" } | ||
| - match: { aggregations.myagg.buckets.0.from: 1628719200000 } | ||
| - match: { aggregations.myagg.buckets.0.to_as_string: "2021-08-11T20:00:00.000000000-04:00" } | ||
| - match: { aggregations.myagg.buckets.0.to: 1628726400000 } | ||
| - match: { aggregations.myagg.buckets.0.doc_count: 1 } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,7 +210,9 @@ private Instant parseDateTime(String value, ZoneId timeZone, boolean roundUpIfNo | |
| return DateFormatters.from(formatter.parse(value)).toInstant(); | ||
| } else { | ||
| TemporalAccessor accessor = formatter.parse(value); | ||
| ZoneId zoneId = TemporalQueries.zone().queryFrom(accessor); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docs describe the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while this would fix the use case where a mapping expects an offset but the problem will re-highlight itself whe na mapping is using zoneId?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually I just tested this and it would work..
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good test though, we should add it to the suite. Do you mind if I just copy it in?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't mind it at all :) it is a copy of your test with just patterns changed :D |
||
| // Use the offset if provided, otherwise fall back to the zone, or null. | ||
| ZoneOffset offset = TemporalQueries.offset().queryFrom(accessor); | ||
| ZoneId zoneId = offset == null ? TemporalQueries.zoneId().queryFrom(accessor) : ZoneId.ofOffset("", offset); | ||
| if (zoneId != null) { | ||
| timeZone = zoneId; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be in the same file as the rest of the range agg tests, but I'm refactoring that file in a different branch, and wanted to save myself a merge conflict.