当前位置: 首页>>代码示例>>Java>>正文


Java DateTime类代码示例

本文整理汇总了Java中org.elasticsearch.common.joda.time.DateTime的典型用法代码示例。如果您正苦于以下问题:Java DateTime类的具体用法?Java DateTime怎么用?Java DateTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DateTime类属于org.elasticsearch.common.joda.time包,在下文中一共展示了DateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_process_object

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的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

示例2: updateCount

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
public void updateCount() {
	
	MapIt updatedMapItRecord = mongoTemplate.findAndModify(new Query(Criteria.where("_id")
			.is(MAPIT_ID)), new Update().inc("hitcount", 1), 
			new FindAndModifyOptions().returnNew(true),
			MapIt.class,
			"mapit");
	
	DateTime now = new DateTime();
	DateTime startDate = new DateTime(updatedMapItRecord.getStartdate());
	Period period = new Period(startDate, now);
	
	String elapsed = formatter.print(period);
	
	if ( (elapsed.equals("")) && (updatedMapItRecord.getHitcount() >= LIC_ALERT)) {
			
			//we have almost reached the ceiling within this year!
			logger.warn("***Reaching max hits ceiling for this year, current count:"
			+updatedMapItRecord.getHitcount());
	}
	
}
 
开发者ID:TransformCore,项目名称:BIS-BDT-Citizen,代码行数:23,代码来源:MapItMongoService.java

示例3: handleCommonFiltersSettings_ActivityDateInterval

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
@Test
public void handleCommonFiltersSettings_ActivityDateInterval() throws IOException, JSONException,
		ReflectiveOperationException {

	ConfigService configService = mockConfigurationService();

	SearchService tested = getTested(configService);

	QuerySettings querySettings = new QuerySettings();
	Filters filters = new Filters();
	querySettings.setFilters(filters);
	filters.acknowledgeUrlFilterCandidate("activity_date_interval", PastIntervalValue.TEST.toString());
	// set date_from and date_to to some values to test this is ignored if interval is used
	filters.acknowledgeUrlFilterCandidate("activity_date_to",
			new DateTime(1359232366456L).toString(DATE_TIME_FORMATTER_UTC));
	filters.acknowledgeUrlFilterCandidate("activity_date_from",
			new DateTime(1359232356456L).toString(DATE_TIME_FORMATTER_UTC));
	tested.parsedFilterConfigService.prepareFiltersForRequest(filters);
	{
		QueryBuilder qb = QueryBuilders.matchAllQuery();
		QueryBuilder qbRes = tested.applyCommonFilters(tested.parsedFilterConfigService.getSearchFiltersForRequest(), qb);
		TestUtils.assertJsonContentFromClasspathFile("/search/query_filters_activityDateInterval.json", qbRes.toString());
	}
}
 
开发者ID:searchisko,项目名称:searchisko,代码行数:25,代码来源:SearchServiceTest.java

示例4: selectActivityDatesHistogramInterval_common

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
@Test
public void selectActivityDatesHistogramInterval_common() throws ReflectiveOperationException {

	ConfigService configService = mockConfigurationService();

	SearchService tested = getTested(configService);

	tested.parsedFilterConfigService.prepareFiltersForRequest(null);
	String fieldName = "sys_activity_dates";

	// case - no activity dates filter defined
	Assert.assertEquals("month", tested.getDateHistogramAggregationInterval(null));

	Assert.assertEquals("month", tested.getDateHistogramAggregationInterval(fieldName));

	Filters filters = new Filters();
	// case - activity date interval precedence against from/to
	filters.acknowledgeUrlFilterCandidate("activity_date_interval", PastIntervalValue.YEAR.toString());
	filters.acknowledgeUrlFilterCandidate("activity_date_from",
			new DateTime(DateTimeZone.UTC).minus(1000000).toString(DATE_TIME_FORMATTER_UTC));
	filters.acknowledgeUrlFilterCandidate("activity_date_to", new DateTime(DateTimeZone.UTC).toString(DATE_TIME_FORMATTER_UTC));
	tested.parsedFilterConfigService.prepareFiltersForRequest(filters);
	Assert.assertEquals("week", tested.getDateHistogramAggregationInterval(fieldName));
}
 
开发者ID:searchisko,项目名称:searchisko,代码行数:25,代码来源:SearchServiceTest.java

示例5: updateDocumentDatesTracking

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
private <T extends IDocument> void updateDocumentDatesTracking(T document) {
    DateTime currentTime = DateTime.now();

    // only update if necessary
    if (document.getCreatedDate() == null) {
        document.setCreatedDate(currentTime.getMillis());
    }
    document.setLastModifiedDate(currentTime.getMillis());
}
 
开发者ID:bpatters,项目名称:eservice,代码行数:10,代码来源:AbstractElasticsearchDAO.java

示例6: calculateVoteStatsForUser

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
public VoteStats calculateVoteStatsForUser(String user, ReadablePeriod period) {
    final DateTime now = DateTime.now();
    DateTime past = now.minus(period);
    final SearchResponse stats = client.prepareSearch(ES_INDEX)
            .setTypes(ES_TYPE)
            .setQuery(QueryBuilders.filteredQuery(
                    QueryBuilders.nestedQuery("user", QueryBuilders.queryString("user.nickName: " + user)),
                    FilterBuilders.boolFilter().must(FilterBuilders.rangeFilter("timestamp").from(past).to(now))))
            .addAggregation(
                    AggregationBuilders.stats("voteStats")
                            .field("voteTotal")
            ).get();
    final Stats esStats = stats.getAggregations().get("voteStats");
    return new VoteStats().setCount(esStats.getCount()).setMax(esStats.getMax()).setMin(esStats.getMin()).setSum(esStats.getSum());
}
 
开发者ID:jalieven,项目名称:sarcasmotron,代码行数:16,代码来源:VoteCalculator.java

示例7: setValidity

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
public Stats setValidity(ReadablePeriod validPeriod) {
    DateTime end = DateTime.now();
    final DateTime start = end.minus(validPeriod);
    setEnd(end.toDate());
    setStart(start.toDate());
    return this;
}
 
开发者ID:jalieven,项目名称:sarcasmotron,代码行数:8,代码来源:Stats.java

示例8: serialize

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
@Override
public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException {
    if (value == null) {
        jgen.writeNull();
        return;
    }
    if (formatString != null && !formatString.isEmpty()) {
        DateTime dateTime = new DateTime(value);
        jgen.writeString(Joda.forPattern(formatString).printer().print(dateTime));
    } else {
        provider.defaultSerializeDateValue(value, jgen);
    }
}
 
开发者ID:kzwang,项目名称:elasticsearch-osem,代码行数:14,代码来源:DateSerializer.java

示例9: save

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
@Override
@Timed
public void save(String table, Document document) throws FoxtrotException {
    table = ElasticsearchUtils.getValidTableName(table);
    try {
        if (!tableMetadataManager.exists(table)) {
            throw FoxtrotExceptions.createTableMissingException(table);
        }
        if (new DateTime().plusDays(1).minus(document.getTimestamp()).getMillis() < 0) {
            return;
        }
        final Table tableMeta = tableMetadataManager.get(table);
        final Document translatedDocument = dataStore.save(tableMeta, document);
        long timestamp = translatedDocument.getTimestamp();
        connection.getClient()
                .prepareIndex()
                .setIndex(ElasticsearchUtils.getCurrentIndex(table, timestamp))
                .setType(ElasticsearchUtils.DOCUMENT_TYPE_NAME)
                .setId(translatedDocument.getId())
                .setTimestamp(Long.toString(timestamp))
                .setSource(convert(translatedDocument))
                .setConsistencyLevel(WriteConsistencyLevel.QUORUM)
                .execute()
                .get(2, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        throw FoxtrotExceptions.createExecutionException(table, e);
    }
}
 
开发者ID:Flipkart,项目名称:foxtrot,代码行数:29,代码来源:ElasticsearchQueryStore.java

示例10: testTimeWindow

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
@Test
public void testTimeWindow() throws IOException {
    SimpleRiverMouth mouth = new SimpleRiverMouth();
    // daily index format
    String index = "'test-'YYYY.MM.dd";
    mouth.setTimeWindowed(true).setIndex(index);
    mouth.index(new PlainIndexableObject(), false);
    String dayIndex = DateTimeFormat.forPattern(index).print(new DateTime());
    assertEquals(mouth.getIndex(), dayIndex);
}
 
开发者ID:szwork2013,项目名称:elasticsearch-sentiment,代码行数:11,代码来源:TimeWindowedTests.java

示例11: createReading

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
private StructuredObject createReading(String hostname, String catalogue, String objectName) {
	StructuredObject reading = new StructuredObject();
	reading.source(TIMESTAMP, new DateTime().toDateTimeISO().toString());
	reading.source(HOST, getHostPart(hostname));
	reading.source(FULL_HOST, hostname);
	reading.source(DOMAIN, getDomainPart(hostname));
	reading.source(REQUEST_URL, getUrl(hostname + catalogue));
	reading.source(RESPONSE, HttpStatus.SC_OK);
	reading.source(OBJECT_NAME, objectName);
	reading.source(TYPE, setting.getLogType());
	for (Entry<String, Object> entry : setting.getConstants().get(hostname + catalogue).entrySet()) {
		reading.source(entry.getKey(), entry.getValue());
	}
	return reading;
}
 
开发者ID:cwikman,项目名称:elasticsearch-river-jolokia,代码行数:16,代码来源:SimpleRiverSource.java

示例12: generateSampleData

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
@Override
public List<Product> generateSampleData()
{
    Set<Category> hierarchicalCategories = generateHierarchicalCategoryData();
    Set<ProductProperty> productProperties = getProductProperties();
    
    List<Product> products = new ArrayList<Product>();
    for (int i = 0; i < 50; i++)
    {
        Product product = new Product();
        product.setId(Long.valueOf(i));
        product.setTitle("Title " + i);
        product.setDescription("Description" + i);
        product.setAvailableOn(new DateTime().plusDays(i).toDate());
        product.addKeyword("Keyword " + i);
        product.setPrice(BigDecimal.valueOf(i));
        product.setSoldOut(i % 2 == 0 ? true : false);
        product.setBoostFactor(i/10000f);
        
        if(i <5)
        {
            product.addCategory(findCategory(hierarchicalCategories, MACBOOK_AIR));
            product.addCategory(findCategory(hierarchicalCategories, APPLE));
            product.addCategory(findCategory(hierarchicalCategories, RED));
            product.addCategory(findCategory(hierarchicalCategories, AGE_18_PLUS_YEARS));
            product.addProductProperty(findProductProperty(productProperties, PRODUCTPROPERTY_SIZE_21_INCH, PRODUCTPROPERTY_COLOR_BROWN));
            product.addProductProperty(findProductProperty(productProperties, PRODUCTPROPERTY_SIZE_17_INCH, PRODUCTPROPERTY_COLOR_PURPLE));
            
            product.addSpecification(new Specification(RESOLUTON_3200_1800, MEMORY_8_GB));
            product.addSpecification(new Specification(RESOLUTON_1920_1200, MEMORY_6_GB));
        }
        else if(i >=5 && i<10)
        {
            product.addCategory(findCategory(hierarchicalCategories, MACBOOK_PRO));
            product.addCategory(findCategory(hierarchicalCategories, APPLE));
            product.addCategory(findCategory(hierarchicalCategories, BLUE));
            product.addProductProperty(findProductProperty(productProperties, PRODUCTPROPERTY_SIZE_15_INCH, PRODUCTPROPERTY_COLOR_YELLOW));
            product.addProductProperty(findProductProperty(productProperties, PRODUCTPROPERTY_SIZE_17_INCH, PRODUCTPROPERTY_COLOR_PURPLE));
            
            product.addSpecification(new Specification(RESOLUTON_1920_1080, MEMORY_6_GB));
            product.addSpecification(new Specification(RESOLUTON_1920_1200, MEMORY_6_GB));
        }
        else if(i >=10 && i<20)
        {
            product.addCategory(findCategory(hierarchicalCategories, HP));
            product.addCategory(findCategory(hierarchicalCategories, AGE_12_18_YEARS));
            product.addProductProperty(findProductProperty(productProperties, PRODUCTPROPERTY_SIZE_12_INCH, PRODUCTPROPERTY_COLOR_BLACK));
            
            product.addSpecification(new Specification(RESOLUTON_1920_1080, MEMORY_4_GB));
            product.addSpecification(new Specification(RESOLUTON_1920_1080, MEMORY_2_GB));
        }
        else
        {
            product.addCategory(findCategory(hierarchicalCategories, DELL));
            product.addCategory(findCategory(hierarchicalCategories, GREEN));
            product.addCategory(findCategory(hierarchicalCategories, AGE_0_12_YEARS));
            product.addProductProperty(findProductProperty(productProperties, PRODUCTPROPERTY_SIZE_13_INCH, PRODUCTPROPERTY_COLOR_GREY));
            
            product.addSpecification(new Specification(RESOLUTON_1024_758, MEMORY_2_GB));
            product.addSpecification(new Specification(RESOLUTON_1024_600, MEMORY_6144_MB));
        }
        products.add(product);
    }
    
    return products;
}
 
开发者ID:jaibeermalik,项目名称:elasticsearch-tutorial,代码行数:67,代码来源:SampleDataGeneratorImpl.java

示例13: formatDate

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
public static String formatDate(Date date)
{
    return searchDateFormat.print(new DateTime(date).getMillis());
}
 
开发者ID:jaibeermalik,项目名称:elasticsearch-tutorial,代码行数:5,代码来源:SearchDateUtils.java

示例14: generateSampleData

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
private static List<Product> generateSampleData()
{
    final List<Product> products = new ArrayList<Product>();
    for (int i = 1; i <= 50; i++)
    {
        final Product product = new Product();
        product.setId(Long.valueOf(i));
        product.setTitle("Title " + i);
        product.setDescription("Description" + i);
        product.setAvailableOn(new DateTime().plusDays(i).toDate());
        product.addKeyword("Keyword " + i);
        product.setPrice(BigDecimal.valueOf(i));
        product.setSoldOut(i % 2 == 0 ? true : false);
        product.setBoostFactor(i / 10000f);
        if (i < 5)
        {
            product.addCategory(findCategory(hierarchicalCategories, MACBOOK_AIR));
            product.addCategory(findCategory(hierarchicalCategories, APPLE));
            product.addCategory(findCategory(hierarchicalCategories, RED));
            product.addCategory(findCategory(hierarchicalCategories, AGE_18_PLUS_YEARS));
            product.addProductProperty(findProductProperty(productProperties, PRODUCTPROPERTY_SIZE_21_INCH, PRODUCTPROPERTY_COLOR_BROWN));
            product.addProductProperty(findProductProperty(productProperties, PRODUCTPROPERTY_SIZE_17_INCH,
                    PRODUCTPROPERTY_COLOR_PURPLE));
            product.addSpecification(new Specification(RESOLUTON_3200_1800, MEMORY_8_GB));
            product.addSpecification(new Specification(RESOLUTON_1920_1200, MEMORY_6_GB));
        }
        else if (i >= 5 && i <= 10)
        {
            product.addCategory(findCategory(hierarchicalCategories, MACBOOK_PRO));
            product.addCategory(findCategory(hierarchicalCategories, APPLE));
            product.addCategory(findCategory(hierarchicalCategories, BLUE));
            product.addProductProperty(findProductProperty(productProperties, PRODUCTPROPERTY_SIZE_15_INCH,
                    PRODUCTPROPERTY_COLOR_YELLOW));
            product.addProductProperty(findProductProperty(productProperties, PRODUCTPROPERTY_SIZE_17_INCH,
                    PRODUCTPROPERTY_COLOR_PURPLE));
            product.addSpecification(new Specification(RESOLUTON_1920_1080, MEMORY_6_GB));
            product.addSpecification(new Specification(RESOLUTON_1920_1200, MEMORY_6_GB));
        }
        else if (i > 10 && i <= 20)
        {
            product.addCategory(findCategory(hierarchicalCategories, HP));
            product.addCategory(findCategory(hierarchicalCategories, AGE_12_18_YEARS));
            product.addProductProperty(findProductProperty(productProperties, PRODUCTPROPERTY_SIZE_12_INCH, PRODUCTPROPERTY_COLOR_BLACK));
            product.addSpecification(new Specification(RESOLUTON_1920_1080, MEMORY_4_GB));
            product.addSpecification(new Specification(RESOLUTON_1920_1080, MEMORY_2_GB));
        }
        else
        {
            product.addCategory(findCategory(hierarchicalCategories, DELL));
            product.addCategory(findCategory(hierarchicalCategories, GREEN));
            product.addCategory(findCategory(hierarchicalCategories, AGE_0_12_YEARS));
            product.addProductProperty(findProductProperty(productProperties, PRODUCTPROPERTY_SIZE_13_INCH, PRODUCTPROPERTY_COLOR_GREY));
            product.addSpecification(new Specification(RESOLUTON_1024_758, MEMORY_2_GB));
            product.addSpecification(new Specification(RESOLUTON_1024_600, MEMORY_6144_MB));
        }
        products.add(product);
    }
    return products;
}
 
开发者ID:jaibeermalik,项目名称:elasticsearch-akka,代码行数:60,代码来源:SampleDataGeneratorServiceImpl.java

示例15: formatDate

import org.elasticsearch.common.joda.time.DateTime; //导入依赖的package包/类
public static String formatDate(final Date date)
{
    return searchDateFormat.print(new DateTime(date).getMillis());
}
 
开发者ID:jaibeermalik,项目名称:elasticsearch-akka,代码行数:5,代码来源:SearchDateUtils.java


注:本文中的org.elasticsearch.common.joda.time.DateTime类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。