Skip to content

Commit

Permalink
Set start of the week to Monday for root locale (elastic#43652)
Browse files Browse the repository at this point in the history
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

change skip reason

compile error

not orking spi

working unit test

cleanup

 change providers for 9+

revert changes IsoLocale

cleanup

move spi files to server

make unit test pass from gradle

expermienting with gradle tasks

uncomment jar hell check

only add settings in buildplugin

allign options for locale providers
  • Loading branch information
pgomulka committed Oct 17, 2019
1 parent 8c90164 commit 8696ec7
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
import org.elasticsearch.gradle.tool.Boilerplate
import org.elasticsearch.gradle.tool.ClasspathUtils
import org.gradle.api.DefaultTask
import org.gradle.api.JavaVersion
import org.gradle.api.Task
import org.gradle.api.file.FileCopyDetails
import org.gradle.api.tasks.Copy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
setup:
- skip:
version: " - 7.3.99"
reason: "only backported to 7.4 (7x)"

- 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" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.Calendar;
import java.util.Locale;
import java.util.spi.CalendarDataProvider;

public class IsoCalendarDataProvider extends CalendarDataProvider {

@Override
public int getFirstDayOfWeek(Locale locale) {
return Calendar.MONDAY;
}

@Override
public int getMinimalDaysInFirstWeek(Locale locale) {
return 4;
}

@Override
public Locale[] getAvailableLocales() {
return new Locale[]{Locale.ROOT};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.elasticsearch.common.time.IsoCalendarDataProvider
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.test.ESTestCase;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.ISODateTimeFormat;

import java.time.LocalDateTime;
Expand Down

0 comments on commit 8696ec7

Please sign in to comment.