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


Java DateTimeZone类代码示例

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


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

示例1: testRoundingWithTimeZone

import org.joda.time.DateTimeZone; //导入依赖的package包/类
public void testRoundingWithTimeZone() {
    MutableDateTime time = new MutableDateTime(DateTimeZone.UTC);
    time.setZone(DateTimeZone.forOffsetHours(-2));
    time.setRounding(time.getChronology().dayOfMonth(), MutableDateTime.ROUND_FLOOR);

    MutableDateTime utcTime = new MutableDateTime(DateTimeZone.UTC);
    utcTime.setRounding(utcTime.getChronology().dayOfMonth(), MutableDateTime.ROUND_FLOOR);

    time.setMillis(utcTimeInMillis("2009-02-03T01:01:01"));
    utcTime.setMillis(utcTimeInMillis("2009-02-03T01:01:01"));

    assertThat(time.toString(), equalTo("2009-02-02T00:00:00.000-02:00"));
    assertThat(utcTime.toString(), equalTo("2009-02-03T00:00:00.000Z"));
    // the time is on the 2nd, and utcTime is on the 3rd, but, because time already encapsulates
    // time zone, the millis diff is not 24, but 22 hours
    assertThat(time.getMillis(), equalTo(utcTime.getMillis() - TimeValue.timeValueHours(22).millis()));

    time.setMillis(utcTimeInMillis("2009-02-04T01:01:01"));
    utcTime.setMillis(utcTimeInMillis("2009-02-04T01:01:01"));
    assertThat(time.toString(), equalTo("2009-02-03T00:00:00.000-02:00"));
    assertThat(utcTime.toString(), equalTo("2009-02-04T00:00:00.000Z"));
    assertThat(time.getMillis(), equalTo(utcTime.getMillis() - TimeValue.timeValueHours(22).millis()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:SimpleJodaTests.java

示例2: calculateDailyInstanceCounts

import org.joda.time.DateTimeZone; //导入依赖的package包/类
private Boolean calculateDailyInstanceCounts() {

    try {

      DateTime utcNow = DateTime.now(DateTimeZone.UTC);

      List<Instance> instances = cloudInstanceStore.getInstances(region);
      List<ReservedInstances> reservedInstances = cloudInstanceStore.getReservedInstances(region);

      // Generate instance counts per type per Availability zone
      List<EsInstanceCountRecord> instanceCountRecords =
          getInstanceCountRecords(instances, reservedInstances, utcNow);
      logger.info("Number of instance count records {}", instanceCountRecords.size());

      // Insert records into soundwave store.
      instanceCounterStore.bulkInsert(instanceCountRecords);
      logger.info("Bulk insert succeeded for instance count records");

      return true;

    } catch (Exception e) {

      logger.error(ExceptionUtils.getRootCauseMessage(e));
      return false;
    }
  }
 
开发者ID:pinterest,项目名称:soundwave,代码行数:27,代码来源:DailyInstanceCountPerTypeJob.java

示例3: fromKubernetesPod

import org.joda.time.DateTimeZone; //导入依赖的package包/类
public KubernetesInstance fromKubernetesPod(Pod elasticAgentPod) {
    KubernetesInstance kubernetesInstance;
    try {
        ObjectMeta metadata = elasticAgentPod.getMetadata();
        DateTime createdAt = DateTime.now().withZone(DateTimeZone.UTC);
        if (StringUtils.isNotBlank(metadata.getCreationTimestamp())) {
            createdAt = new DateTime(getSimpleDateFormat().parse(metadata.getCreationTimestamp())).withZone(DateTimeZone.UTC);
        }
        String environment = metadata.getLabels().get(Constants.ENVIRONMENT_LABEL_KEY);
        Long jobId = Long.valueOf(metadata.getLabels().get(Constants.JOB_ID_LABEL_KEY));
        kubernetesInstance = new KubernetesInstance(createdAt, environment, metadata.getName(), metadata.getAnnotations(), jobId, PodState.fromPod(elasticAgentPod));
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
    return kubernetesInstance;
}
 
开发者ID:gocd,项目名称:kubernetes-elastic-agents,代码行数:17,代码来源:KubernetesInstanceFactory.java

示例4: parse

import org.joda.time.DateTimeZone; //导入依赖的package包/类
public long parse(String text, LongSupplier now, boolean roundUp, DateTimeZone timeZone) {
    long time;
    String mathString;
    if (text.startsWith("now")) {
        try {
            time = now.getAsLong();
        } catch (Exception e) {
            throw new ElasticsearchParseException("could not read the current timestamp", e);
        }
        mathString = text.substring("now".length());
    } else {
        int index = text.indexOf("||");
        if (index == -1) {
            return parseDateTime(text, timeZone, roundUp);
        }
        time = parseDateTime(text.substring(0, index), timeZone, false);
        mathString = text.substring(index + 2);
    }

    return parseMath(mathString, time, roundUp, timeZone);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DateMathParser.java

示例5: assertInterval

import org.joda.time.DateTimeZone; //导入依赖的package包/类
/**
 * perform a number on assertions and checks on {@link TimeUnitRounding} intervals
 * @param rounded the expected low end of the rounding interval
 * @param unrounded a date in the interval to be checked for rounding
 * @param nextRoundingValue the expected upper end of the rounding interval
 * @param rounding the rounding instance
 */
private static void assertInterval(long rounded, long unrounded, long nextRoundingValue, Rounding rounding,
        DateTimeZone tz) {
    assert rounded <= unrounded && unrounded <= nextRoundingValue;
    assertThat("rounding should be idempotent ", rounding.round(rounded), isDate(rounded, tz));
    assertThat("rounded value smaller or equal than unrounded" + rounding, rounded, lessThanOrEqualTo(unrounded));
    assertThat("values less than rounded should round further down" + rounding, rounding.round(rounded - 1), lessThan(rounded));
    assertThat("nextRounding value should be greater than date" + rounding, nextRoundingValue, greaterThan(unrounded));
    assertThat("nextRounding value should be a rounded date", rounding.round(nextRoundingValue), isDate(nextRoundingValue, tz));
    assertThat("values above nextRounding should round down there", rounding.round(nextRoundingValue + 1),
            isDate(nextRoundingValue, tz));

    long dateBetween = dateBetween(rounded, nextRoundingValue);
    assertThat("dateBetween should round down to roundedDate", rounding.round(dateBetween), isDate(rounded, tz));
    assertThat("dateBetween should round up to nextRoundingValue", rounding.nextRoundingValue(dateBetween),
            isDate(nextRoundingValue, tz));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:TimeZoneRoundingTests.java

示例6: testDateRangeInQueryStringWithTimeZone_7880

import org.joda.time.DateTimeZone; //导入依赖的package包/类
public void testDateRangeInQueryStringWithTimeZone_7880() {
    //the mapping needs to be provided upfront otherwise we are not sure how many failures we get back
    //as with dynamic mappings some shards might be lacking behind and parse a different query
    assertAcked(prepareCreate("test").addMapping(
            "type", "past", "type=date"
    ));

    DateTimeZone timeZone = randomDateTimeZone();
    String now = ISODateTimeFormat.dateTime().print(new DateTime(timeZone));
    logger.info(" --> Using time_zone [{}], now is [{}]", timeZone.getID(), now);
    client().prepareIndex("test", "type", "1").setSource("past", now).get();
    refresh();

    SearchResponse searchResponse = client().prepareSearch().setQuery(queryStringQuery("past:[now-1m/m TO now+1m/m]")
            .timeZone(timeZone.getID())).get();
    assertHitCount(searchResponse, 1L);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:SearchQueryIT.java

示例7: testAutoCreateIndexWithDateMathExpression

import org.joda.time.DateTimeZone; //导入依赖的package包/类
public void testAutoCreateIndexWithDateMathExpression() throws Exception {
    DateTime now = new DateTime(DateTimeZone.UTC);
    String index1 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now);
    String index2 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.minusDays(1));
    String index3 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.minusDays(2));

    String dateMathExp1 = "<.marvel-{now/d}>";
    String dateMathExp2 = "<.marvel-{now/d-1d}>";
    String dateMathExp3 = "<.marvel-{now/d-2d}>";
    client().prepareIndex(dateMathExp1, "type", "1").setSource("{}", XContentType.JSON).get();
    client().prepareIndex(dateMathExp2, "type", "2").setSource("{}", XContentType.JSON).get();
    client().prepareIndex(dateMathExp3, "type", "3").setSource("{}", XContentType.JSON).get();
    refresh();

    SearchResponse searchResponse = client().prepareSearch(dateMathExp1, dateMathExp2, dateMathExp3).get();
    assertHitCount(searchResponse, 3);
    assertSearchHits(searchResponse, "1", "2", "3");

    IndicesStatsResponse indicesStatsResponse = client().admin().indices().prepareStats(dateMathExp1, dateMathExp2, dateMathExp3).get();
    assertThat(indicesStatsResponse.getIndex(index1), notNullValue());
    assertThat(indicesStatsResponse.getIndex(index2), notNullValue());
    assertThat(indicesStatsResponse.getIndex(index3), notNullValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:DateMathIndexExpressionsIntegrationIT.java

示例8: setTexts

import org.joda.time.DateTimeZone; //导入依赖的package包/类
private void setTexts() {
    dateTime.setText(
            DateTimeFormat.forPattern("MMM dd  hh:mm aa").print(new DateTime(game.getGameDateTime(), Constants.DATE.VEGAS_TIME_ZONE).toDateTime(DateTimeZone.getDefault())));
    if (game.getFirstTeam().getName().equals(DefaultFactory.Team.NAME)) {
        firstTeamTitle.setText(game.getFirstTeam().getCity());
        firstTeamSubtitle.setText("-");
    } else {
        firstTeamTitle.setText(game.getFirstTeam().getName() + " " + String.valueOf(game.getFirstTeamScore()));
        firstTeamSubtitle.setText(game.getFirstTeam().getCity());
    }
    if (game.getSecondTeam().getName().equals(DefaultFactory.Team.NAME)) {
        secondTeamTitle.setText(game.getSecondTeam().getCity());
        secondTeamSubtitle.setText("-");
    } else {
        secondTeamTitle.setText(game.getSecondTeam().getName() + " " + String.valueOf(game.getSecondTeamScore()));
        secondTeamSubtitle.setText(game.getSecondTeam().getCity());
    }
    bidAmount.setText(getContext().getString(R.string.bid_amount,
            game.getLeagueType() instanceof Soccer_Spread ? "(" + (int) game.getVIBid().getVigAmount() + ") " : game.getVIBid().getCondition().getValue().replace("spread", ""),
            String.valueOf(game.getVIBid().getBidAmount())));
}
 
开发者ID:riteshakya037,项目名称:Android-Scrapper,代码行数:22,代码来源:GridDialogItemFragment.java

示例9: RuleServiceModel

import org.joda.time.DateTimeZone; //导入依赖的package包/类
public RuleServiceModel(
    final String eTag,
    final String id,
    final String name,
    final String dateCreated,
    final Boolean enabled,
    final String description,
    final String groupId,
    final String severity,
    final ArrayList<ConditionServiceModel> conditions) {

    this.eTag = eTag;
    this.id = id;
    this.name = name;
    this.dateCreated = dateCreated;
    this.dateModified = DateTime.now(DateTimeZone.UTC).toString(DATE_FORMAT);
    this.enabled = enabled;
    this.description = description;
    this.groupId = groupId;
    this.severity = severity;

    this.conditions = conditions;
}
 
开发者ID:Azure,项目名称:device-telemetry-java,代码行数:24,代码来源:RuleServiceModel.java

示例10: testSingleValuedFieldOrderedBySubAggregationAsc

import org.joda.time.DateTimeZone; //导入依赖的package包/类
public void testSingleValuedFieldOrderedBySubAggregationAsc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateHistogram("histo")
                    .field("date")
                    .dateHistogramInterval(DateHistogramInterval.MONTH)
                    .order(Histogram.Order.aggregation("sum", true))
                    .subAggregation(max("sum").field("value")))
            .execute().actionGet();

    assertSearchResponse(response);

    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    assertThat(histo.getBuckets().size(), equalTo(3));

    int i = 0;
    for (Histogram.Bucket bucket : histo.getBuckets()) {
        assertThat(((DateTime) bucket.getKey()), equalTo(new DateTime(2012, i + 1, 1, 0, 0, DateTimeZone.UTC)));
        i++;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:DateHistogramIT.java

示例11: TikaPoweredMetadataExtracter

import org.joda.time.DateTimeZone; //导入依赖的package包/类
public TikaPoweredMetadataExtracter(String extractorContext, HashSet<String> supportedMimeTypes, HashSet<String> supportedEmbedMimeTypes)
{
    super(supportedMimeTypes, supportedEmbedMimeTypes);

    this.extractorContext = extractorContext;

    // TODO Once TIKA-451 is fixed this list will get nicer
    DateTimeParser[] parsersUTC = {
        DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").getParser(),
        DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").getParser()
    };
    DateTimeParser[] parsers = {
        DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").getParser(),
        DateTimeFormat.forPattern("yyyy-MM-dd").getParser(),
        DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").getParser(),
        DateTimeFormat.forPattern("yyyy/MM/dd").getParser(),
            DateTimeFormat.forPattern("EEE MMM dd hh:mm:ss zzz yyyy").getParser()
    };

    this.tikaUTCDateFormater = new DateTimeFormatterBuilder().append(null, parsersUTC).toFormatter().withZone(DateTimeZone.UTC);
    this.tikaDateFormater = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:TikaPoweredMetadataExtracter.java

示例12: testSingleValuedFieldOrderedByMultiValuedSubAggregationDesc

import org.joda.time.DateTimeZone; //导入依赖的package包/类
public void testSingleValuedFieldOrderedByMultiValuedSubAggregationDesc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateHistogram("histo")
                    .field("date")
                    .dateHistogramInterval(DateHistogramInterval.MONTH)
                    .order(Histogram.Order.aggregation("stats", "sum", false))
                    .subAggregation(stats("stats").field("value")))
            .execute().actionGet();

    assertSearchResponse(response);

    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    assertThat(histo.getBuckets().size(), equalTo(3));

    int i = 2;
    for (Histogram.Bucket bucket : histo.getBuckets()) {
        assertThat(((DateTime) bucket.getKey()), equalTo(new DateTime(2012, i + 1, 1, 0, 0, DateTimeZone.UTC)));
        i--;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:DateHistogramIT.java

示例13: configure

import org.joda.time.DateTimeZone; //导入依赖的package包/类
@Override
public void configure(Map<String, Object> config) {
  String localeString = (String) config.get(HdfsSinkConnectorConfig.LOCALE_CONFIG);
  if (localeString.equals("")) {
    throw new ConfigException(HdfsSinkConnectorConfig.LOCALE_CONFIG,
                              localeString, "Locale cannot be empty.");
  }
  String timeZoneString = (String) config.get(HdfsSinkConnectorConfig.TIMEZONE_CONFIG);
  if (timeZoneString.equals("")) {
    throw new ConfigException(HdfsSinkConnectorConfig.TIMEZONE_CONFIG,
                              timeZoneString, "Timezone cannot be empty.");
  }
  String hiveIntString = (String) config.get(HdfsSinkConnectorConfig.HIVE_INTEGRATION_CONFIG);
  boolean hiveIntegration = hiveIntString != null && hiveIntString.toLowerCase().equals("true");
  Locale locale = new Locale(localeString);
  DateTimeZone timeZone = DateTimeZone.forID(timeZoneString);
  init(partitionDurationMs, pathFormat, locale, timeZone, hiveIntegration);
}
 
开发者ID:jiangxiluning,项目名称:kafka-connect-hdfs,代码行数:19,代码来源:HourlyPartitioner.java

示例14: onSetUpInTransaction

import org.joda.time.DateTimeZone; //导入依赖的package包/类
@Override
protected void onSetUpInTransaction() throws Exception
{
    nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
    importerService = (ImporterService)applicationContext.getBean(ServiceRegistry.IMPORTER_SERVICE.getLocalName());
    
    importerBootstrap = (ImporterBootstrap)applicationContext.getBean("spacesBootstrap");
    
    this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
    
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    this.versionService = (VersionService)this.applicationContext.getBean("VersionService");
    
    // Create the store
    this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    
    TimeZone tz = TimeZone.getTimeZone("GMT");
    TimeZone.setDefault(tz);
    // Joda time has already grabbed the JVM zone so re-set it here
    DateTimeZone.setDefault(DateTimeZone.forTimeZone(tz));
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:ImporterComponentTest.java

示例15: testRoundingRandom

import org.joda.time.DateTimeZone; //导入依赖的package包/类
/**
 * Randomized test on TimeUnitRounding. Test uses random
 * {@link DateTimeUnit} and {@link DateTimeZone} and often (50% of the time)
 * chooses test dates that are exactly on or close to offset changes (e.g.
 * DST) in the chosen time zone.
 *
 * It rounds the test date down and up and performs various checks on the
 * rounding unit interval that is defined by this. Assumptions tested are
 * described in
 * {@link #assertInterval(long, long, long, Rounding, DateTimeZone)}
 */
public void testRoundingRandom() {
    for (int i = 0; i < 1000; ++i) {
        DateTimeUnit timeUnit = randomTimeUnit();
        DateTimeZone tz = randomDateTimeZone();
        Rounding rounding = new Rounding.TimeUnitRounding(timeUnit, tz);
        long date = Math.abs(randomLong() % (2 * (long) 10e11)); // 1970-01-01T00:00:00Z - 2033-05-18T05:33:20.000+02:00
        long unitMillis = timeUnit.field(tz).getDurationField().getUnitMillis();
        if (randomBoolean()) {
            nastyDate(date, tz, unitMillis);
        }
        final long roundedDate = rounding.round(date);
        final long nextRoundingValue = rounding.nextRoundingValue(roundedDate);

        assertInterval(roundedDate, date, nextRoundingValue, rounding, tz);

        // check correct unit interval width for units smaller than a day, they should be fixed size except for transitions
        if (unitMillis <= DateTimeConstants.MILLIS_PER_DAY) {
            // if the interval defined didn't cross timezone offset transition, it should cover unitMillis width
            if (tz.getOffset(roundedDate - 1) == tz.getOffset(nextRoundingValue + 1)) {
                assertThat("unit interval width not as expected for [" + timeUnit + "], [" + tz + "] at "
                        + new DateTime(roundedDate), nextRoundingValue - roundedDate, equalTo(unitMillis));
            }
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:TimeZoneRoundingTests.java


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