本文整理汇总了Java中org.elasticsearch.common.joda.Joda类的典型用法代码示例。如果您正苦于以下问题:Java Joda类的具体用法?Java Joda怎么用?Java Joda使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Joda类属于org.elasticsearch.common.joda包,在下文中一共展示了Joda类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: RangeQueryBuilder
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
/**
* Read from a stream.
*/
public RangeQueryBuilder(StreamInput in) throws IOException {
super(in);
fieldName = in.readString();
from = in.readGenericValue();
to = in.readGenericValue();
includeLower = in.readBoolean();
includeUpper = in.readBoolean();
timeZone = in.readOptionalTimeZone();
String formatString = in.readOptionalString();
if (formatString != null) {
format = Joda.forPattern(formatString);
}
if (in.getVersion().onOrAfter(Version.V_5_2_0_UNRELEASED)) {
String relationString = in.readOptionalString();
if (relationString != null) {
relation = ShapeRelation.getRelationByName(relationString);
}
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:RangeQueryBuilder.java
示例2: testThatEpochsCanBeParsed
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
public void testThatEpochsCanBeParsed() {
boolean parseMilliSeconds = randomBoolean();
// epoch: 1433144433655 => date: Mon Jun 1 09:40:33.655 CEST 2015
FormatDateTimeFormatter formatter = Joda.forPattern(parseMilliSeconds ? "epoch_millis" : "epoch_second");
DateTime dateTime = formatter.parser().parseDateTime(parseMilliSeconds ? "1433144433655" : "1433144433");
assertThat(dateTime.getYear(), is(2015));
assertThat(dateTime.getDayOfMonth(), is(1));
assertThat(dateTime.getMonthOfYear(), is(6));
assertThat(dateTime.getHourOfDay(), is(7)); // utc timezone, +2 offset due to CEST
assertThat(dateTime.getMinuteOfHour(), is(40));
assertThat(dateTime.getSecondOfMinute(), is(33));
if (parseMilliSeconds) {
assertThat(dateTime.getMillisOfSecond(), is(655));
} else {
assertThat(dateTime.getMillisOfSecond(), is(0));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:SimpleJodaTests.java
示例3: testThatEpochTimePrinterWorks
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
public void testThatEpochTimePrinterWorks() {
StringBuffer buffer = new StringBuffer();
LocalDateTime now = LocalDateTime.now();
Joda.EpochTimePrinter epochTimePrinter = new Joda.EpochTimePrinter(false);
epochTimePrinter.printTo(buffer, now, Locale.ROOT);
assertThat(buffer.length(), is(10));
// only check the last digit, as seconds go from 0-99 in the unix timestamp and don't stop at 60
assertThat(buffer.toString(), endsWith(String.valueOf(now.getSecondOfMinute() % 10)));
buffer = new StringBuffer();
Joda.EpochTimePrinter epochMilliSecondTimePrinter = new Joda.EpochTimePrinter(true);
epochMilliSecondTimePrinter.printTo(buffer, now, Locale.ROOT);
assertThat(buffer.length(), is(13));
assertThat(buffer.toString(), endsWith(String.valueOf(now.getMillisOfSecond())));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SimpleJodaTests.java
示例4: testThatEpochParserIsIdempotent
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
public void testThatEpochParserIsIdempotent() {
FormatDateTimeFormatter formatter = Joda.forPattern("epoch_millis");
DateTime dateTime = formatter.parser().parseDateTime("1234567890123");
assertThat(dateTime.getMillis(), is(1234567890123L));
dateTime = formatter.printer().parseDateTime("1234567890456");
assertThat(dateTime.getMillis(), is(1234567890456L));
dateTime = formatter.parser().parseDateTime("1234567890789");
assertThat(dateTime.getMillis(), is(1234567890789L));
dateTime = formatter.parser().parseDateTime("1234567890123456789");
assertThat(dateTime.getMillis(), is(1234567890123456789L));
FormatDateTimeFormatter secondsFormatter = Joda.forPattern("epoch_second");
DateTime secondsDateTime = secondsFormatter.parser().parseDateTime("1234567890");
assertThat(secondsDateTime.getMillis(), is(1234567890000L));
secondsDateTime = secondsFormatter.printer().parseDateTime("1234567890");
assertThat(secondsDateTime.getMillis(), is(1234567890000L));
secondsDateTime = secondsFormatter.parser().parseDateTime("1234567890");
assertThat(secondsDateTime.getMillis(), is(1234567890000L));
secondsDateTime = secondsFormatter.parser().parseDateTime("1234567890123456");
assertThat(secondsDateTime.getMillis(), is(1234567890123456000L));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:SimpleJodaTests.java
示例5: test_process_object
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
@Test
public void test_process_object() throws IllegalAccessException, NoSuchFieldException, IOException {
Tweet tweet = getRandomTweet();
String tweetJson = objectProcessor.toJsonString(tweet);
logger.info("Generated JSON: {}", tweetJson);
Tweet tweetFromJson = objectProcessor.fromJsonString(tweetJson, Tweet.class);
Map<String, Object> tweetMap = jsonToMap(tweetJson);
checkTweetEquals(tweetFromJson, tweet);
// test custom date serializer/deserializer
assertThat((String) tweetMap.get("tweetDate"), equalTo(Joda.forPattern("basic_date").printer().print(new DateTime(tweet.getTweetDate()))));
assertThat((String) tweetMap.get("tweetDatetime"), equalTo(Joda.forPattern("yyyy/MM/dd HH:mm:ss").printer().print(new DateTime(tweet.getTweetDate()))));
assertThat(((List<String>) tweetMap.get("specialDates")), hasSize(tweet.getSpecialDates().size()));
assertThat(((List<String>) tweetMap.get("specialDates")).get(0), equalTo(Joda.forPattern("basic_date_time_no_millis").printer().print(new DateTime(tweet.getSpecialDates().get(0)))));
}
开发者ID:kzwang,项目名称:elasticsearch-osem,代码行数:20,代码来源:ObjectProcessorTest.java
示例6: docValueFormat
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
@Override
public DocValueFormat docValueFormat(@Nullable String format, DateTimeZone timeZone) {
FormatDateTimeFormatter dateTimeFormatter = this.dateTimeFormatter;
if (format != null) {
dateTimeFormatter = Joda.forPattern(format);
}
if (timeZone == null) {
timeZone = DateTimeZone.UTC;
}
return new DocValueFormat.DateTime(dateTimeFormatter, timeZone);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:DateFieldMapper.java
示例7: valueOf
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
@Override
public java.lang.Long valueOf(String value, String fmt) {
FormatDateTimeFormatter f = formatter;
if (fmt != null) {
f = Joda.forPattern(fmt);
}
return f.parser().parseDateTime(value).getMillis();
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:FieldStats.java
示例8: unparsed
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
/**
* Convert an extended bounds in parsed for into one in unparsed form.
*/
public static ExtendedBounds unparsed(ExtendedBounds template) {
// It'd probably be better to randomize the formatter
FormatDateTimeFormatter formatter = Joda.forPattern("dateOptionalTime");
String minAsStr = template.getMin() == null ? null : formatter.printer().print(new Instant(template.getMin()));
String maxAsStr = template.getMax() == null ? null : formatter.printer().print(new Instant(template.getMax()));
return new ExtendedBounds(minAsStr, maxAsStr);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:ExtendedBoundsTests.java
示例9: testParseAndValidate
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
public void testParseAndValidate() {
long now = randomLong();
Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build();
SearchContext context = mock(SearchContext.class);
QueryShardContext qsc = new QueryShardContext(0,
new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), indexSettings), null, null, null, null,
null, xContentRegistry(), null, null, () -> now);
when(context.getQueryShardContext()).thenReturn(qsc);
FormatDateTimeFormatter formatter = Joda.forPattern("dateOptionalTime");
DocValueFormat format = new DocValueFormat.DateTime(formatter, DateTimeZone.UTC);
ExtendedBounds expected = randomParsedExtendedBounds();
ExtendedBounds parsed = unparsed(expected).parseAndValidate("test", context, format);
// parsed won't *equal* expected because equal includes the String parts
assertEquals(expected.getMin(), parsed.getMin());
assertEquals(expected.getMax(), parsed.getMax());
parsed = new ExtendedBounds("now", null).parseAndValidate("test", context, format);
assertEquals(now, (long) parsed.getMin());
assertNull(parsed.getMax());
parsed = new ExtendedBounds(null, "now").parseAndValidate("test", context, format);
assertNull(parsed.getMin());
assertEquals(now, (long) parsed.getMax());
SearchParseException e = expectThrows(SearchParseException.class,
() -> new ExtendedBounds(100L, 90L).parseAndValidate("test", context, format));
assertEquals("[extended_bounds.min][100] cannot be greater than [extended_bounds.max][90] for histogram aggregation [test]",
e.getMessage());
e = expectThrows(SearchParseException.class,
() -> unparsed(new ExtendedBounds(100L, 90L)).parseAndValidate("test", context, format));
assertEquals("[extended_bounds.min][100] cannot be greater than [extended_bounds.max][90] for histogram aggregation [test]",
e.getMessage());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:ExtendedBoundsTests.java
示例10: testIsoVsCustom
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
public void testIsoVsCustom() {
DateTimeFormatter formatter = ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC);
long millis = formatter.parseMillis("1970-01-01T00:00:00");
assertThat(millis, equalTo(0L));
formatter = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").withZone(DateTimeZone.UTC);
millis = formatter.parseMillis("1970/01/01 00:00:00");
assertThat(millis, equalTo(0L));
FormatDateTimeFormatter formatter2 = Joda.forPattern("yyyy/MM/dd HH:mm:ss");
millis = formatter2.parser().parseMillis("1970/01/01 00:00:00");
assertThat(millis, equalTo(0L));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:SimpleJodaTests.java
示例11: testSlashInFormat
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
public void testSlashInFormat() {
FormatDateTimeFormatter formatter = Joda.forPattern("MM/yyyy");
formatter.parser().parseMillis("01/2001");
formatter = Joda.forPattern("yyyy/MM/dd HH:mm:ss");
long millis = formatter.parser().parseMillis("1970/01/01 00:00:00");
formatter.printer().print(millis);
try {
millis = formatter.parser().parseMillis("1970/01/01");
fail();
} catch (IllegalArgumentException e) {
// it really can't parse this one
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:SimpleJodaTests.java
示例12: testMultipleDifferentFormats
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
public void testMultipleDifferentFormats() {
FormatDateTimeFormatter formatter = Joda.forPattern("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd");
String input = "1970/01/01 00:00:00";
long millis = formatter.parser().parseMillis(input);
assertThat(input, is(formatter.printer().print(millis)));
Joda.forPattern("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||dateOptionalTime");
Joda.forPattern("dateOptionalTime||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd");
Joda.forPattern("yyyy/MM/dd HH:mm:ss||dateOptionalTime||yyyy/MM/dd");
Joda.forPattern("date_time||date_time_no_millis");
Joda.forPattern(" date_time || date_time_no_millis");
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:SimpleJodaTests.java
示例13: expectInvalidPattern
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
private void expectInvalidPattern(String pattern, String errorMessage) {
try {
Joda.forPattern(pattern);
fail("Pattern " + pattern + " should have thrown an exception but did not");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString(errorMessage));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:SimpleJodaTests.java
示例14: testThatNegativeEpochsCanBeParsed
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
public void testThatNegativeEpochsCanBeParsed() {
// problem: negative epochs can be arbitrary in size...
boolean parseMilliSeconds = randomBoolean();
FormatDateTimeFormatter formatter = Joda.forPattern(parseMilliSeconds ? "epoch_millis" : "epoch_second");
DateTime dateTime = formatter.parser().parseDateTime("-10000");
assertThat(dateTime.getYear(), is(1969));
assertThat(dateTime.getMonthOfYear(), is(12));
assertThat(dateTime.getDayOfMonth(), is(31));
if (parseMilliSeconds) {
assertThat(dateTime.getHourOfDay(), is(23)); // utc timezone, +2 offset due to CEST
assertThat(dateTime.getMinuteOfHour(), is(59));
assertThat(dateTime.getSecondOfMinute(), is(50));
} else {
assertThat(dateTime.getHourOfDay(), is(21)); // utc timezone, +2 offset due to CEST
assertThat(dateTime.getMinuteOfHour(), is(13));
assertThat(dateTime.getSecondOfMinute(), is(20));
}
// every negative epoch must be parsed, no matter if exact the size or bigger
if (parseMilliSeconds) {
formatter.parser().parseDateTime("-100000000");
formatter.parser().parseDateTime("-999999999999");
formatter.parser().parseDateTime("-1234567890123");
formatter.parser().parseDateTime("-1234567890123456789");
} else {
formatter.parser().parseDateTime("-100000000");
formatter.parser().parseDateTime("-1234567890");
formatter.parser().parseDateTime("-1234567890123456");
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:SimpleJodaTests.java
示例15: testForInvalidDatesInEpochSecond
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
public void testForInvalidDatesInEpochSecond() {
FormatDateTimeFormatter formatter = Joda.forPattern("epoch_second");
try {
formatter.parser().parseDateTime(randomFrom("invalid date", "12345678901234567", "12345678901234567890"));
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Invalid format"));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:SimpleJodaTests.java
示例16: testForInvalidDatesInEpochMillis
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
public void testForInvalidDatesInEpochMillis() {
FormatDateTimeFormatter formatter = Joda.forPattern("epoch_millis");
try {
formatter.parser().parseDateTime(randomFrom("invalid date", "12345678901234567890"));
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Invalid format"));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:SimpleJodaTests.java
示例17: testThatEpochParserIsPrinter
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
public void testThatEpochParserIsPrinter() {
FormatDateTimeFormatter formatter = Joda.forPattern("epoch_millis");
assertThat(formatter.parser().isPrinter(), is(true));
assertThat(formatter.printer().isPrinter(), is(true));
FormatDateTimeFormatter epochSecondFormatter = Joda.forPattern("epoch_second");
assertThat(epochSecondFormatter.parser().isPrinter(), is(true));
assertThat(epochSecondFormatter.printer().isPrinter(), is(true));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:SimpleJodaTests.java
示例18: assertDateFormatParsingThrowingException
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
private void assertDateFormatParsingThrowingException(String pattern, String invalidDate) {
try {
FormatDateTimeFormatter formatter = Joda.forPattern(pattern);
DateTimeFormatter parser = formatter.parser();
parser.parseMillis(invalidDate);
fail(String.format(Locale.ROOT, "Expected parsing exception for pattern [%s] with date [%s], but did not happen", pattern, invalidDate));
} catch (IllegalArgumentException e) {
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:SimpleJodaTests.java
示例19: Timestamp
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
public Timestamp(boolean enabled, String path, String format, String defaultTimestamp, Boolean ignoreMissing) {
this.enabled = enabled;
this.path = path;
if (path == null) {
pathElements = Strings.EMPTY_ARRAY;
} else {
pathElements = Strings.delimitedListToStringArray(path, ".");
}
this.format = format;
this.dateTimeFormatter = Joda.forPattern(format);
this.defaultTimestamp = defaultTimestamp;
this.ignoreMissing = ignoreMissing;
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:MappingMetaData.java
示例20: valueOf
import org.elasticsearch.common.joda.Joda; //导入依赖的package包/类
@Override
protected java.lang.Long valueOf(String value, String optionalFormat) {
FormatDateTimeFormatter dateFormatter = this.dateFormatter;
if (optionalFormat != null) {
dateFormatter = Joda.forPattern(optionalFormat);
}
return dateFormatter.parser().parseMillis(value);
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:9,代码来源:FieldStats.java
注:本文中的org.elasticsearch.common.joda.Joda类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论