Skip to content

Commit 46c7cd9

Browse files
authored
Deduplicate two similar TimeUtils classes.
* Deduplicate org.elasticsearch.xpack.core.dataframe.utils.TimeUtils and org.elasticsearch.xpack.core.ml.utils.time.TimeUtils into a common class: org.elasticsearch.xpack.core.common.time.TimeUtils. * Add unit tests for parseTimeField and parseTimeFieldToInstant methods
1 parent 392245b commit 46c7cd9

File tree

25 files changed

+71
-159
lines changed

25 files changed

+71
-159
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/utils/TimeUtils.java renamed to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/time/TimeUtils.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.core.dataframe.utils;
6+
package org.elasticsearch.xpack.core.common.time;
77

88
import org.elasticsearch.ElasticsearchParseException;
99
import org.elasticsearch.common.ParseField;
@@ -26,7 +26,7 @@ public static Date parseTimeField(XContentParser parser, String fieldName) throw
2626
if (parser.currentToken() == XContentParser.Token.VALUE_NUMBER) {
2727
return new Date(parser.longValue());
2828
} else if (parser.currentToken() == XContentParser.Token.VALUE_STRING) {
29-
return new Date(TimeUtils.dateStringToEpoch(parser.text()));
29+
return new Date(dateStringToEpoch(parser.text()));
3030
}
3131
throw new IllegalArgumentException(
3232
"unexpected token [" + parser.currentToken() + "] for [" + fieldName + "]");
@@ -36,7 +36,7 @@ public static Instant parseTimeFieldToInstant(XContentParser parser, String fiel
3636
if (parser.currentToken() == XContentParser.Token.VALUE_NUMBER) {
3737
return Instant.ofEpochMilli(parser.longValue());
3838
} else if (parser.currentToken() == XContentParser.Token.VALUE_STRING) {
39-
return Instant.ofEpochMilli(TimeUtils.dateStringToEpoch(parser.text()));
39+
return Instant.ofEpochMilli(dateStringToEpoch(parser.text()));
4040
}
4141
throw new IllegalArgumentException(
4242
"unexpected token [" + parser.currentToken() + "] for [" + fieldName + "]");
@@ -123,8 +123,6 @@ private static void checkNonNegative(TimeValue timeValue, ParseField field) {
123123
}
124124
}
125125

126-
127-
128126
/**
129127
* Check the given {@code timeValue} is a multiple of the {@code baseUnit}
130128
*/

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/notifications/DataFrameAuditMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import org.elasticsearch.common.xcontent.XContentParser;
1212
import org.elasticsearch.xpack.core.common.notifications.AbstractAuditMessage;
1313
import org.elasticsearch.xpack.core.common.notifications.Level;
14+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
1415
import org.elasticsearch.xpack.core.dataframe.DataFrameField;
15-
import org.elasticsearch.xpack.core.dataframe.utils.TimeUtils;
1616

1717
import java.util.Date;
1818

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/dataframe/transforms/DataFrameTransformConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
import org.elasticsearch.common.xcontent.XContentBuilder;
2121
import org.elasticsearch.common.xcontent.XContentParser;
2222
import org.elasticsearch.common.xcontent.XContentParserUtils;
23+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
2324
import org.elasticsearch.xpack.core.dataframe.DataFrameField;
2425
import org.elasticsearch.xpack.core.dataframe.DataFrameMessages;
2526
import org.elasticsearch.xpack.core.dataframe.transforms.pivot.PivotConfig;
2627
import org.elasticsearch.xpack.core.dataframe.utils.ExceptionsHelper;
27-
import org.elasticsearch.xpack.core.dataframe.utils.TimeUtils;
2828

2929
import java.io.IOException;
3030
import java.time.Instant;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/annotations/Annotation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.elasticsearch.common.xcontent.ToXContentObject;
1414
import org.elasticsearch.common.xcontent.XContentBuilder;
1515
import org.elasticsearch.xpack.core.ml.job.config.Job;
16-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
16+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
1717

1818
import java.io.IOException;
1919
import java.util.Date;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/calendars/ScheduledEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
2424
import org.elasticsearch.xpack.core.ml.utils.Intervals;
2525
import org.elasticsearch.xpack.core.ml.utils.ToXContentParams;
26-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
26+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
2727

2828
import java.io.IOException;
2929
import java.time.Instant;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DatafeedConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.elasticsearch.xpack.core.ml.utils.QueryProvider;
3434
import org.elasticsearch.xpack.core.ml.utils.ToXContentParams;
3535
import org.elasticsearch.xpack.core.ml.utils.XContentObjectTransformer;
36-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
36+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
3737

3838
import java.io.IOException;
3939
import java.util.ArrayList;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/datafeed/DelayedDataCheckConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.elasticsearch.common.xcontent.ToXContentObject;
1818
import org.elasticsearch.common.xcontent.XContentBuilder;
1919
import org.elasticsearch.common.xcontent.XContentParser;
20-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
20+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
2121

2222
import java.io.IOException;
2323
import java.util.Objects;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/AnalysisConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.elasticsearch.common.xcontent.XContentBuilder;
1818
import org.elasticsearch.xpack.core.ml.job.messages.Messages;
1919
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
20-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
20+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
2121

2222
import java.io.IOException;
2323
import java.util.ArrayList;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/config/Job.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts;
2727
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
2828
import org.elasticsearch.xpack.core.ml.utils.MlStrings;
29-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
29+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
3030

3131
import java.io.IOException;
3232
import java.util.ArrayList;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/output/FlushAcknowledgement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.elasticsearch.common.xcontent.ObjectParser;
1414
import org.elasticsearch.common.xcontent.ToXContentObject;
1515
import org.elasticsearch.common.xcontent.XContentBuilder;
16-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
16+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
1717

1818
import java.io.IOException;
1919
import java.util.Date;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/DataCounts.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.elasticsearch.common.xcontent.ToXContentObject;
1515
import org.elasticsearch.common.xcontent.XContentBuilder;
1616
import org.elasticsearch.xpack.core.ml.job.config.Job;
17-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
17+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
1818

1919
import java.io.IOException;
2020
import java.util.Date;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSizeStats.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import org.elasticsearch.common.xcontent.XContentBuilder;
1717
import org.elasticsearch.xpack.core.ml.job.config.Job;
1818
import org.elasticsearch.xpack.core.ml.job.results.Result;
19-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
19+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
2020

2121
import java.io.IOException;
2222
import java.util.Date;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/process/autodetect/state/ModelSnapshot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.elasticsearch.common.xcontent.XContentParser;
2323
import org.elasticsearch.common.xcontent.XContentType;
2424
import org.elasticsearch.xpack.core.ml.job.config.Job;
25-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
25+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
2626

2727
import java.io.IOException;
2828
import java.io.InputStream;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/AnomalyRecord.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.elasticsearch.xpack.core.ml.job.config.Detector;
1818
import org.elasticsearch.xpack.core.ml.job.config.Job;
1919
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
20-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
20+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
2121

2222
import java.io.IOException;
2323
import java.util.ArrayList;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/Bucket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.elasticsearch.common.xcontent.XContentBuilder;
1616
import org.elasticsearch.xpack.core.ml.job.config.Job;
1717
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
18-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
18+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
1919

2020
import java.io.IOException;
2121
import java.util.ArrayList;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/BucketInfluencer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.elasticsearch.common.xcontent.XContentBuilder;
1616
import org.elasticsearch.xpack.core.ml.job.config.Job;
1717
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
18-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
18+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
1919

2020
import java.io.IOException;
2121
import java.util.Date;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/Forecast.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.elasticsearch.common.xcontent.ToXContentObject;
1515
import org.elasticsearch.common.xcontent.XContentBuilder;
1616
import org.elasticsearch.xpack.core.ml.job.config.Job;
17-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
17+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
1818

1919
import java.io.IOException;
2020
import java.util.Date;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/Influencer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.elasticsearch.common.xcontent.XContentBuilder;
1616
import org.elasticsearch.xpack.core.ml.job.config.Job;
1717
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
18-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
18+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
1919

2020
import java.io.IOException;
2121
import java.util.Date;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/results/ModelPlot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.elasticsearch.common.xcontent.ToXContentObject;
1515
import org.elasticsearch.common.xcontent.XContentBuilder;
1616
import org.elasticsearch.xpack.core.ml.job.config.Job;
17-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
17+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
1818

1919
import java.io.IOException;
2020
import java.util.Date;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/notifications/AuditMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.elasticsearch.xpack.core.common.notifications.AbstractAuditMessage;
1212
import org.elasticsearch.xpack.core.common.notifications.Level;
1313
import org.elasticsearch.xpack.core.ml.job.config.Job;
14-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
14+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
1515

1616
import java.util.Date;
1717

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/time/TimeUtils.java

Lines changed: 0 additions & 129 deletions
This file was deleted.

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditMessageTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.elasticsearch.common.xcontent.ObjectParser;
1111
import org.elasticsearch.common.xcontent.XContentParser;
1212
import org.elasticsearch.test.AbstractXContentTestCase;
13-
import org.elasticsearch.xpack.core.ml.utils.time.TimeUtils;
13+
import org.elasticsearch.xpack.core.common.time.TimeUtils;
1414
import org.junit.Before;
1515

1616
import java.util.Date;

0 commit comments

Comments
 (0)