forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set start of the week to Monday for root locale (elastic#43652)
Introducing a IsoLocal.ROOT constant which should be used instead of java.util.Locale.ROOT in ES when dealing with dates. IsoLocal.ROOT customises start of the week to be Monday instead of Sunday. closes elastic#42588 an issue with investigation details relates elastic#41670 bug raised (this won't fix it on its own. joda.parseInto has to be reimplemented closes elastic#43275 an issue raised by community member
- Loading branch information
Showing
10 changed files
with
343 additions
and
207 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
libs/core/src/main/java/org/elasticsearch/common/time/IsoLocale.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.common.time; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Locale constants to be used across elasticsearch code base. | ||
* java.util.Locale.ROOT should not be used as it defaults start of the week incorrectly to Sunday. | ||
*/ | ||
public final class IsoLocale { | ||
private IsoLocale() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
/** | ||
* We want to use Locale.ROOT but with a start of the week as defined in ISO8601 to be compatible with the behaviour in joda-time | ||
* https://github.com/elastic/elasticsearch/issues/42588 | ||
* @see java.time.temporal.WeekFields#of(Locale) | ||
*/ | ||
public static final Locale ROOT = new Locale.Builder() | ||
.setLocale(Locale.ROOT) | ||
.setUnicodeLocaleKeyword("fw", "mon").build(); | ||
} |
47 changes: 47 additions & 0 deletions
47
...src/main/resources/rest-api-spec/test/search.aggregation/310_date_agg_per_day_of_week.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
setup: | ||
- skip: | ||
version: " - 7.99.99" #TODO change this after backport | ||
reason: "not backported yet" | ||
|
||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
mappings: | ||
properties: | ||
date: | ||
type: date | ||
|
||
- do: | ||
index: | ||
index: test | ||
id: 1 | ||
body: { "date": "2009-11-15T14:12:12" } | ||
|
||
- do: | ||
indices.refresh: | ||
index: [test] | ||
|
||
--- | ||
# The inserted document has a field date=2009-11-15T14:12:12 which is Sunday. | ||
# When aggregating per day of the week this should be considered as last day of the week (7) | ||
# and this value should be used in 'key_as_string' | ||
"Date aggregartion per day of week": | ||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test | ||
body: | ||
aggregations: | ||
test: | ||
"date_histogram": { | ||
"field": "date", | ||
"calendar_interval": "day", | ||
"format": "e", | ||
"offset": 0 | ||
} | ||
|
||
- match: {hits.total: 1} | ||
- length: { aggregations.test.buckets: 1 } | ||
- match: { aggregations.test.buckets.0.key_as_string: "7" } |
409 changes: 216 additions & 193 deletions
409
server/src/main/java/org/elasticsearch/common/time/DateFormatters.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters