Skip to content
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

Core: Switch mapping/aggregations over to java time #36363

Merged
merged 202 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from 189 commits
Commits
Show all changes
202 commits
Select commit Hold shift + click to select a range
19e3035
Core: Move aggs/mapping code over to java time
spinscale Sep 20, 2018
baf7acd
run test on java9 only
spinscale Sep 20, 2018
efe5661
fix compilation error
spinscale Sep 20, 2018
b856795
fix randomized test to use java time
spinscale Sep 20, 2018
443bdea
silence another test for now on java8 due to BWC issues without syste…
spinscale Sep 20, 2018
995855d
Merge branch 'master' into java-time
spinscale Sep 21, 2018
739ca1f
Merge branch 'master' into java-time
spinscale Sep 24, 2018
af7abc8
Merge branch 'master' into java-time
spinscale Sep 25, 2018
e6d61d2
Merge branch 'master' into java-time
spinscale Sep 26, 2018
a464a05
Merge branch 'master' into java-time
spinscale Sep 27, 2018
79f2ebb
Merge branch 'master' into java-time
spinscale Sep 27, 2018
a9de009
fix wrong casting
spinscale Sep 27, 2018
c9b7e22
Merge branch 'master' into java-time
spinscale Sep 28, 2018
5d34a06
fix import
spinscale Sep 28, 2018
121b208
Merge branch 'master' into java-time
spinscale Sep 28, 2018
4ab9cc2
fix compilation errors
spinscale Sep 28, 2018
13301c1
Merge branch 'master' into java-time
spinscale Sep 28, 2018
8f4564e
fix unit test
spinscale Sep 28, 2018
720caf8
Merge branch 'master' into java-time
spinscale Oct 1, 2018
26905c9
Merge branch 'master' into java-time
spinscale Oct 1, 2018
7b88806
Merge branch 'master' into java-time
spinscale Oct 2, 2018
d9b241c
Merge branch 'master' into java-time
spinscale Oct 2, 2018
3f8e10a
fix compilation errors
spinscale Oct 2, 2018
3df911f
fix tests
spinscale Oct 2, 2018
a1987ef
remove unused imports
spinscale Oct 2, 2018
8cd9cfa
Merge branch 'master' into java-time
spinscale Oct 3, 2018
d8af35d
Merge branch 'master' into java-time
spinscale Oct 4, 2018
5e50374
Merge branch 'master' into java-time
spinscale Oct 5, 2018
50e86b5
Merge branch 'master' into java-time
spinscale Oct 6, 2018
c58040f
Merge branch 'master' into java-time
spinscale Oct 8, 2018
80f7e69
fix test by not using root locale
spinscale Oct 8, 2018
3f74ffb
Merge branch 'master' into java-time
spinscale Oct 9, 2018
a8fd14c
Merge branch 'master' into java-time
spinscale Oct 10, 2018
ae50fcc
Merge branch 'master' into java-time
spinscale Oct 11, 2018
0d8c7e3
Add floating point parsing of epoch millis
spinscale Oct 11, 2018
fc99549
Merge branch 'master' into java-time
spinscale Oct 15, 2018
dee1b8e
catch both exceptions, fixes tests properly
spinscale Oct 15, 2018
113eb93
add another test for epoch millis date formatter
spinscale Oct 16, 2018
2861b7c
Merge branch 'master' into java-time
spinscale Oct 16, 2018
390ca93
Merge branch 'master' into java-time
spinscale Oct 16, 2018
dab811d
remove some TODOs
spinscale Oct 16, 2018
982c418
Merge branch 'master' into java-time
spinscale Oct 17, 2018
f56a596
Merge branch 'master' into java-time
spinscale Oct 17, 2018
7bdc090
Merge branch 'master' into java-time
spinscale Oct 18, 2018
418444f
Merge branch 'master' into java-time
spinscale Oct 23, 2018
87c49d1
remove more TODOs
spinscale Oct 23, 2018
5735433
fix HLRC compilation error
spinscale Oct 23, 2018
64cae08
Merge branch 'master' into java-time
spinscale Oct 24, 2018
01d7bdf
Merge branch 'master' into java-time
spinscale Oct 24, 2018
603be5d
Merge branch 'master' into java-time
spinscale Oct 25, 2018
8fbf1f1
remove import
spinscale Oct 25, 2018
e5b0cd0
Merge branch 'master' into java-time
spinscale Oct 25, 2018
50dd0ff
Merge branch 'master' into java-time
spinscale Oct 26, 2018
f49b2dd
Merge branch 'master' into java-time
spinscale Oct 26, 2018
2ce818d
Merge branch 'master' into java-time
spinscale Oct 29, 2018
a0c24af
fix checkstyle
spinscale Oct 29, 2018
b087623
Merge branch 'master' into java-time
spinscale Oct 31, 2018
e76d474
Merge branch 'master' into java-time
spinscale Nov 2, 2018
594dcc9
Merge branch 'master' into java-time
spinscale Nov 2, 2018
2a4ef79
fix range query test
spinscale Nov 2, 2018
436af3d
Merge branch 'master' into java-time
spinscale Nov 2, 2018
1e83827
Merge branch 'master' into java-time
spinscale Nov 5, 2018
1a96c92
Merge branch 'master' into java-time
spinscale Nov 6, 2018
ca0344b
Merge branch 'master' into java-time
spinscale Nov 7, 2018
1d7f1f2
Merge branch 'master' into java-time
spinscale Nov 7, 2018
cc80caf
fix compilation errors
spinscale Nov 7, 2018
7e44ddf
Merge branch 'master' into java-time
spinscale Nov 8, 2018
a2b5ef5
Merge branch 'master' into java-time
spinscale Nov 9, 2018
fb2810b
fix compilation
spinscale Nov 9, 2018
89e5fd1
fix tests
spinscale Nov 9, 2018
9421ce6
Merge branch 'master' into java-time
spinscale Nov 26, 2018
4cf8463
removed import
spinscale Nov 26, 2018
568c1b5
Merge branch 'master' into java-time
spinscale Nov 26, 2018
101eeae
Merge branch 'master' into java-time
spinscale Nov 26, 2018
1245bbe
Merge branch 'master' into java-time
spinscale Nov 27, 2018
cb250c4
fix casting to java-time in ML
spinscale Nov 27, 2018
14403c3
Merge branch 'master' into java-time
spinscale Nov 27, 2018
501d02d
remove unused import
spinscale Nov 27, 2018
5e32ce0
Merge branch 'master' into java-time
spinscale Nov 28, 2018
3a27760
Core: Migrating from joda to java.time. ML package (#35949)
pgomulka Nov 28, 2018
bf3a942
Merge branch 'master' into java-time
spinscale Nov 29, 2018
8b32091
Merge branch 'master' into java-time
spinscale Nov 30, 2018
3a76b95
Merge branch 'master' into java-time
spinscale Nov 30, 2018
972e5a4
Merge branch 'master' into java-time
spinscale Dec 3, 2018
3d91e31
Merge branch 'master' into java-time
spinscale Dec 3, 2018
f486f63
Fix java date parsing to be compatible with joda (#36155)
pgomulka Dec 3, 2018
34fc485
Deprecate /_xpack/monitoring/* in favor of /_monitoring/* (#36130)
jakelandis Dec 3, 2018
94832de
Improve painless docs for score, similarity, weight and sort (#35629)
romseygeek Dec 3, 2018
5926e4b
Remove the deprecated _termvector endpoint. (#36131)
jtibshirani Dec 3, 2018
c15c3bb
Fix broken links in painless docs (#36170)
romseygeek Dec 3, 2018
a188931
[ILM] fix ilm.remove_policy rest-spec (#36165)
talevy Dec 3, 2018
3d35bdb
Added soft limit to open scroll contexts #25244 (#36009)
joaofcmb Dec 3, 2018
7c51625
[DOCS] Fixes peer link
lcawl Dec 3, 2018
83a2054
[DOCs] More broken painless links
lcawl Dec 3, 2018
41cb9df
[test] generate unique user names (#36179)
andyb-elastic Dec 3, 2018
0686a13
[test] mute RemoveCorruptedShardDataCommandIT
andyb-elastic Dec 4, 2018
2ecd87d
[HLRC] Added support for CCR Get Auto Follow Pattern apis (#36049)
martijnvg Dec 4, 2018
277cfaf
Testclusters: implement starting, waiting for and stopping single clu…
alpar-t Dec 4, 2018
3aec7eb
(Minor) Fix some typos (#36180)
glenacota Dec 4, 2018
11f6448
Merge branch 'master' into java-time
spinscale Dec 5, 2018
ee6c1a6
Merge branch 'master' into java-time
spinscale Dec 6, 2018
97ed0d5
Merge branch 'master' into java-time
spinscale Dec 6, 2018
f0a719c
Merge branch 'master' into java-time
spinscale Dec 7, 2018
9520605
fix compilation errors
spinscale Dec 7, 2018
f907699
cleanups
spinscale Dec 7, 2018
ea2281c
Merge branch 'master' into java-time
spinscale Dec 7, 2018
971e5d0
fix checkstyle
spinscale Dec 7, 2018
03c67ee
Merge branch 'master' into java-time
spinscale Dec 10, 2018
ba6b1f1
Merge branch 'master' into java-time
spinscale Dec 10, 2018
fbc79c9
fix tests
spinscale Dec 10, 2018
275a33e
Merge branch 'master' into java-time
spinscale Dec 10, 2018
62995e3
fix rest tests
spinscale Dec 10, 2018
1f36baf
Merge branch 'master' into java-time
spinscale Dec 11, 2018
9d6c33e
fix test
spinscale Dec 11, 2018
a177c3a
Merge branch 'master' into java-time
spinscale Dec 11, 2018
3fa2a1b
fix another test
spinscale Dec 11, 2018
62dff53
simplify serialization code
spinscale Dec 11, 2018
c036c40
restore accidentally removed ccr snippet
spinscale Dec 11, 2018
17b3aa2
Fix failing licence test (#36482)
pgomulka Dec 11, 2018
ce8411a
normalize date to prevent UTC/Z to string issues in tests
spinscale Dec 11, 2018
8b8970c
Merge branch 'master' into java-time
spinscale Dec 11, 2018
4634a93
Merge branch 'master' into java-time
spinscale Dec 11, 2018
9273268
catch correct date parse exception
spinscale Dec 12, 2018
b5a92db
Merge branch 'master' into java-time
spinscale Dec 12, 2018
b225148
fix tests
spinscale Dec 12, 2018
2ee4510
review comments
spinscale Dec 12, 2018
a25e91e
Merge branch 'master' into java-time
spinscale Dec 12, 2018
409c12b
add exception handling
spinscale Dec 12, 2018
1d4d9c4
Merge branch 'master' into java-time
spinscale Dec 13, 2018
d678d71
fix rollupindexertests
spinscale Dec 13, 2018
acf17e0
fix compilation of new field mappers
spinscale Dec 13, 2018
79a6079
Merge branch 'master' into java-time
spinscale Dec 13, 2018
88d7da9
Merge branch 'master' into java-time
spinscale Dec 14, 2018
8064c85
Merge branch 'master' into java-time
spinscale Dec 14, 2018
c9df2f9
Merge branch 'master' into java-time
spinscale Dec 17, 2018
5307643
Merge branch 'master' into java-time
spinscale Dec 18, 2018
f7471f0
Merge branch 'master' into java-time
spinscale Dec 18, 2018
7ab754c
Merge branch 'master' into java-time
spinscale Dec 19, 2018
03b4a3c
Merge branch 'master' into java-time
spinscale Dec 19, 2018
bf2528b
Merge branch 'master' into java-time
spinscale Dec 21, 2018
e2acbc8
Merge branch 'master' into java-time
spinscale Dec 30, 2018
5f336c9
fix tests using week based year
spinscale Dec 30, 2018
acc4c71
Merge branch 'master' into java-time
spinscale Jan 7, 2019
ad08cdd
Merge branch 'master' into java-time
spinscale Jan 7, 2019
2d23dd9
Add super simple benchmark to check joda/java time conversion differe…
spinscale Jan 7, 2019
71c4f2d
add missing license
spinscale Jan 7, 2019
aea63a8
Merge branch 'master' into java-time
spinscale Jan 8, 2019
2aca1f9
Merge branch 'master' into java-time
spinscale Jan 8, 2019
ed71785
Merge branch 'master' into java-time
spinscale Jan 9, 2019
cbbd3c0
Merge branch 'master' into java-time
spinscale Jan 9, 2019
fdb1d9d
fix tests by checking for java 8
spinscale Jan 9, 2019
1040e2c
Merge branch 'master' into java-time
spinscale Jan 9, 2019
a191118
fix a few more tests for java 8
spinscale Jan 9, 2019
cc1ed73
Merge branch 'master' into java-time
spinscale Jan 10, 2019
9ccabad
fix formatter
spinscale Jan 10, 2019
d33f5ba
Merge branch 'master' into java-time
spinscale Jan 10, 2019
8d2ad6c
allow to parse nanoseconds by default in date field mapper
spinscale Jan 10, 2019
de6ac15
add clarifying comment
spinscale Jan 10, 2019
ce22809
Merge branch 'master' into java-time
spinscale Jan 10, 2019
fbe4d46
fix failing test
spinscale Jan 11, 2019
3180107
Merge branch 'master' into java-time
spinscale Jan 11, 2019
d15ad93
Merge branch 'master' into java-time
spinscale Jan 11, 2019
451b724
Merge branch 'master' into java-time
spinscale Jan 11, 2019
af8dd13
Merge branch 'master' into java-time
spinscale Jan 12, 2019
197e215
fix some ML tests by providing useful date ranges
spinscale Jan 12, 2019
32e81c4
work around java 8 time formatting issues
spinscale Jan 12, 2019
383d5e7
fix checkstyle and fix some tests due to moving formatter
spinscale Jan 13, 2019
e65470d
fix unused import
spinscale Jan 13, 2019
c49c2df
fix tests on java 8
spinscale Jan 13, 2019
c6f6167
removed unused import
spinscale Jan 13, 2019
0d879f7
Merge branch 'master' into java-time
spinscale Jan 14, 2019
070af0d
Merge branch 'master' into java-time
spinscale Jan 14, 2019
fcd8ac7
Merge branch 'master' into java-time
spinscale Jan 14, 2019
e4250bc
Merge branch 'master' into java-time
spinscale Jan 15, 2019
a529dc9
Merge branch 'master' into java-time
spinscale Jan 15, 2019
cc14c00
incorporate first round of review comments
spinscale Jan 15, 2019
1b23509
more review comments
spinscale Jan 15, 2019
f185cbf
remoe unused import
spinscale Jan 15, 2019
a99871b
review comment: ensure previous transition exists
spinscale Jan 15, 2019
6a68f98
remove another unused import
spinscale Jan 15, 2019
fb44168
Merge branch 'master' into java-time
spinscale Jan 16, 2019
5263ee2
more review comments
spinscale Jan 16, 2019
c9c717f
change wrong boolean check
spinscale Jan 16, 2019
f66f177
Merge branch 'master' into java-time
spinscale Jan 16, 2019
c9cbe51
Merge branch 'master' into java-time
spinscale Jan 17, 2019
5fbba3e
review comments: change rangequerybuilder equals/hashcode
spinscale Jan 17, 2019
0ac86fd
Merge branch 'master' into java-time
spinscale Jan 17, 2019
b1237d7
Merge branch 'master' into java-time
spinscale Jan 18, 2019
595a99a
incorporate review comments from zach
spinscale Jan 18, 2019
06008ea
Merge branch 'master' into java-time
spinscale Jan 20, 2019
30d0d91
Merge branch 'master' into java-time
spinscale Jan 21, 2019
6eb1fca
Merge branch 'master' into java-time
spinscale Jan 21, 2019
c9d655f
Merge branch 'master' into java-time
spinscale Jan 21, 2019
7f6b4a3
Merge branch 'master' into java-time
spinscale Jan 21, 2019
252812d
Merge branch 'master' into java-time
spinscale Jan 22, 2019
c8ee0b3
fix tests
spinscale Jan 22, 2019
8af2f03
remove unused import
spinscale Jan 22, 2019
84958df
Merge branch 'master' into java-time
spinscale Jan 22, 2019
fa885ca
Merge branch 'master' into java-time
spinscale Jan 22, 2019
575c53d
Merge branch 'master' into java-time
spinscale Jan 22, 2019
db8c562
Merge branch 'master' into java-time
spinscale Jan 22, 2019
623f253
fix test
spinscale Jan 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,3 @@ public TemporalAccessor parseJodaDate() {
return jodaFormatter.parse("1234567890");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.joda.time.DateTimeZone;

import java.io.IOException;
import java.time.ZoneId;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -107,7 +107,7 @@ public String typeName() {
}

@Override
public DocValueFormat docValueFormat(String format, DateTimeZone timeZone) {
public DocValueFormat docValueFormat(String format, ZoneId timeZone) {
throw new UnsupportedOperationException(
"Field [" + name() + "] of type [" + typeName() + "] doesn't support docvalue_fields or aggregations");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.MultiValueMode;
import org.joda.time.DateTimeZone;

import java.io.IOException;
import java.math.BigDecimal;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -301,7 +301,7 @@ public Object valueForDisplay(Object value) {
}

@Override
public DocValueFormat docValueFormat(String format, DateTimeZone timeZone) {
public DocValueFormat docValueFormat(String format, ZoneId timeZone) {
if (timeZone != null) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName()
+ "] does not support custom time zones");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.joda.time.DateTimeZone;

import java.io.IOException;
import java.time.ZoneId;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -107,7 +107,7 @@ public String typeName() {
}

@Override
public DocValueFormat docValueFormat(String format, DateTimeZone timeZone) {
public DocValueFormat docValueFormat(String format, ZoneId timeZone) {
throw new UnsupportedOperationException(
"Field [" + name() + "] of type [" + typeName() + "] doesn't support docvalue_fields or aggregations");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;
import org.elasticsearch.search.DocValueFormat;
import org.joda.time.DateTimeZone;

import java.io.IOException;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -208,7 +208,7 @@ public BytesRef parseBytesRef(String value) {
};

@Override
public DocValueFormat docValueFormat(final String format, final DateTimeZone timeZone) {
public DocValueFormat docValueFormat(final String format, final ZoneId timeZone) {
return COLLATE_FORMAT;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
index: timetest
body:
mappings:
test: { "properties": { "my_time": {"type": "date"}}}
test: { "properties": { "my_time": {"type": "date", "format": "strict_date_optional_time_nanos"}}}

- do:
ingest.put_pipeline:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.common.time.DateFormatters;
import org.elasticsearch.common.xcontent.ContextParser;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
Expand Down Expand Up @@ -368,7 +367,7 @@ public static final class Tombstone implements ToXContentObject, Writeable {
TOMBSTONE_PARSER.declareString((b, s) -> {}, new ParseField(DELETE_DATE_KEY));
}

static final DateFormatter FORMATTER = DateFormatters.forPattern("strict_date_optional_time").withZone(ZoneOffset.UTC);
static final DateFormatter FORMATTER = DateFormatter.forPattern("strict_date_optional_time").withZone(ZoneOffset.UTC);

static ContextParser<Void, Tombstone> getParser() {
return (parser, context) -> TOMBSTONE_PARSER.apply(parser, null).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.common.time.DateFormatters;
import org.elasticsearch.common.time.DateMathParser;
import org.elasticsearch.common.time.DateUtils;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNotFoundException;
Expand Down Expand Up @@ -819,7 +819,7 @@ private static List<String> resolveEmptyOrTrivialWildcard(IndicesOptions options

static final class DateMathExpressionResolver implements ExpressionResolver {

private static final DateFormatter DEFAULT_DATE_FORMATTER = DateFormatters.forPattern("uuuu.MM.dd");
private static final DateFormatter DEFAULT_DATE_FORMATTER = DateFormatter.forPattern("uuuu.MM.dd");
private static final String EXPRESSION_LEFT_BOUND = "<";
private static final String EXPRESSION_RIGHT_BOUND = ">";
private static final char LEFT_BOUND = '{';
Expand Down Expand Up @@ -912,18 +912,19 @@ String resolveExpression(String expression, final Context context) {
int formatPatternTimeZoneSeparatorIndex = patternAndTZid.indexOf(TIME_ZONE_BOUND);
if (formatPatternTimeZoneSeparatorIndex != -1) {
dateFormatterPattern = patternAndTZid.substring(0, formatPatternTimeZoneSeparatorIndex);
timeZone = ZoneId.of(patternAndTZid.substring(formatPatternTimeZoneSeparatorIndex + 1));
timeZone = DateUtils.of(patternAndTZid.substring(formatPatternTimeZoneSeparatorIndex + 1));
} else {
dateFormatterPattern = patternAndTZid;
timeZone = ZoneOffset.UTC;
}
dateFormatter = DateFormatters.forPattern(dateFormatterPattern);
dateFormatter = DateFormatter.forPattern(dateFormatterPattern);
}

DateFormatter formatter = dateFormatter.withZone(timeZone);
DateMathParser dateMathParser = formatter.toDateMathParser();
long millis = dateMathParser.parse(mathExpression, context::getStartTime, false, timeZone);
Instant instant = dateMathParser.parse(mathExpression, context::getStartTime, false, timeZone);

String time = formatter.format(Instant.ofEpochMilli(millis));
String time = formatter.format(instant);
beforePlaceHolderSb.append(time);
inPlaceHolderSb = new StringBuilder();
inPlaceHolder = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.common.time.DateFormatters;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand All @@ -48,7 +47,7 @@
*/
public final class UnassignedInfo implements ToXContentFragment, Writeable {

public static final DateFormatter DATE_TIME_FORMATTER = DateFormatters.forPattern("dateOptionalTime").withZone(ZoneOffset.UTC);
public static final DateFormatter DATE_TIME_FORMATTER = DateFormatter.forPattern("dateOptionalTime").withZone(ZoneOffset.UTC);

public static final Setting<TimeValue> INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING =
Setting.positiveTimeSetting("index.unassigned.node_left.delayed_timeout", TimeValue.timeValueMinutes(1), Property.Dynamic,
Expand Down
20 changes: 14 additions & 6 deletions server/src/main/java/org/elasticsearch/common/Rounding.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
package org.elasticsearch.common;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.time.DateUtils;
import org.elasticsearch.common.unit.TimeValue;

import java.io.IOException;
Expand Down Expand Up @@ -188,7 +190,7 @@ static class TimeUnitRounding extends Rounding {

TimeUnitRounding(StreamInput in) throws IOException {
unit = DateTimeUnit.resolve(in.readByte());
timeZone = ZoneId.of(in.readString());
timeZone = DateUtils.of(in.readString());
unitRoundsToMidnight = unit.getField().getBaseUnit().getDuration().toMillis() > 60L * 60L * 1000L;
}

Expand Down Expand Up @@ -367,8 +369,11 @@ public long nextRoundingValue(long utcMillis) {
@Override
public void innerWriteTo(StreamOutput out) throws IOException {
out.writeByte(unit.getId());
String tz = ZoneOffset.UTC.equals(timeZone) ? "UTC" : timeZone.getId(); // stay joda compatible
out.writeString(tz);
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
out.writeString(timeZone.getId());
} else {
out.writeString(DateUtils.zoneIdToDateTimeZone(timeZone).getID());
}
}

@Override
Expand Down Expand Up @@ -417,7 +422,7 @@ public String toString() {

TimeIntervalRounding(StreamInput in) throws IOException {
interval = in.readVLong();
timeZone = ZoneId.of(in.readString());
timeZone = DateUtils.of(in.readString());
}

@Override
Expand Down Expand Up @@ -490,8 +495,11 @@ public long nextRoundingValue(long time) {
@Override
public void innerWriteTo(StreamOutput out) throws IOException {
out.writeVLong(interval);
String tz = ZoneOffset.UTC.equals(timeZone) ? "UTC" : timeZone.getId(); // stay joda compatible
out.writeString(tz);
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
out.writeString(timeZone.getId());
} else {
out.writeString(DateUtils.zoneIdToDateTimeZone(timeZone).getID());
}
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions server/src/main/java/org/elasticsearch/common/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.elasticsearch.common;

import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.common.time.DateFormatters;

import java.time.Instant;
import java.time.ZoneOffset;
Expand Down Expand Up @@ -85,7 +84,7 @@ public Table endHeaders() {
return this;
}

private static final DateFormatter FORMATTER = DateFormatters.forPattern("HH:mm:ss").withZone(ZoneOffset.UTC);
private static final DateFormatter FORMATTER = DateFormatter.forPattern("HH:mm:ss").withZone(ZoneOffset.UTC);

public Table startRow() {
if (headers.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,23 @@ public DateTimeZone readOptionalTimeZone() throws IOException {
return null;
}

/**
* Read a {@linkplain DateTimeZone}.
*/
public ZoneId readZoneId() throws IOException {
return ZoneId.of(readString());
}

/**
* Read an optional {@linkplain ZoneId}.
*/
public ZoneId readOptionalZoneId() throws IOException {
if (readBoolean()) {
return ZoneId.of(readString());
}
return null;
}

public int[] readIntArray() throws IOException {
int length = readArraySize();
int[] values = new int[length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.nio.file.FileSystemLoopException;
import java.nio.file.NoSuchFileException;
import java.nio.file.NotDirectoryException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -677,7 +678,6 @@ public final <K, V> void writeMap(final Map<K, V> map, final Writer<K> keyWriter
writers.put(ZonedDateTime.class, (o, v) -> {
o.writeByte((byte) 23);
final ZonedDateTime zonedDateTime = (ZonedDateTime) v;
zonedDateTime.getZone().getId();
o.writeString(zonedDateTime.getZone().getId());
o.writeLong(zonedDateTime.toInstant().toEpochMilli());
});
Expand Down Expand Up @@ -988,6 +988,13 @@ public void writeTimeZone(DateTimeZone timeZone) throws IOException {
writeString(timeZone.getID());
}

/**
* Write a {@linkplain ZoneId} to the stream.
*/
public void writeZoneId(ZoneId timeZone) throws IOException {
writeString(timeZone.getId());
}

/**
* Write an optional {@linkplain DateTimeZone} to the stream.
*/
Expand All @@ -1000,6 +1007,18 @@ public void writeOptionalTimeZone(@Nullable DateTimeZone timeZone) throws IOExce
}
}

/**
* Write an optional {@linkplain ZoneId} to the stream.
*/
public void writeOptionalZoneId(@Nullable ZoneId timeZone) throws IOException {
if (timeZone == null) {
writeBoolean(false);
} else {
writeBoolean(true);
writeZoneId(timeZone);
}
}

/**
* Writes a list of {@link Streamable} objects
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
import java.time.ZonedDateTime;
import java.time.temporal.TemporalAccessor;
import java.util.Locale;
import java.util.Objects;

public class JodaDateFormatter implements DateFormatter {
final String pattern;

final String pattern;
final DateTimeFormatter parser;

final DateTimeFormatter printer;

public JodaDateFormatter(String pattern, DateTimeFormatter parser, DateTimeFormatter printer) {
Expand Down Expand Up @@ -108,4 +108,21 @@ public ZoneId zone() {
public DateMathParser toDateMathParser() {
return new JodaDateMathParser(this);
}

@Override
public int hashCode() {
return Objects.hash(locale(), zone(), pattern());
}

@Override
public boolean equals(Object obj) {
if (obj.getClass().equals(this.getClass()) == false) {
return false;
}
JodaDateFormatter other = (JodaDateFormatter) obj;

return Objects.equals(pattern(), other.pattern()) &&
Objects.equals(locale(), other.locale()) &&
Objects.equals(zone(), other.zone());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.joda.time.MutableDateTime;
import org.joda.time.format.DateTimeFormatter;

import java.time.Instant;
import java.time.ZoneId;
import java.util.Objects;
import java.util.function.LongSupplier;
Expand All @@ -50,7 +51,7 @@ public JodaDateMathParser(JodaDateFormatter dateTimeFormatter) {
// if it has been used. For instance, the request cache does not cache requests that make
// use of `now`.
@Override
public long parse(String text, LongSupplier now, boolean roundUp, ZoneId tz) {
public Instant parse(String text, LongSupplier now, boolean roundUp, ZoneId tz) {
final DateTimeZone timeZone = tz == null ? null : DateUtils.zoneIdToDateTimeZone(tz);
long time;
String mathString;
Expand All @@ -64,13 +65,13 @@ public long parse(String text, LongSupplier now, boolean roundUp, ZoneId tz) {
} else {
int index = text.indexOf("||");
if (index == -1) {
return parseDateTime(text, timeZone, roundUp);
return Instant.ofEpochMilli(parseDateTime(text, timeZone, roundUp));
}
time = parseDateTime(text.substring(0, index), timeZone, false);
mathString = text.substring(index + 2);
}

return parseMath(mathString, time, roundUp, timeZone);
return Instant.ofEpochMilli(parseMath(mathString, time, roundUp, timeZone));
}

private long parseMath(String mathString, long time, boolean roundUp, DateTimeZone timeZone) throws ElasticsearchParseException {
Expand Down
Loading