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


Java DateTimeZone.forID方法代码示例

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


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

示例1: 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

示例2: testTimeIntervalCET_DST_End

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
/**
 * test DST end with interval rounding
 * CET: 25 October 2015, 03:00:00 clocks were turned backward 1 hour to 25 October 2015, 02:00:00 local standard time
 */
public void testTimeIntervalCET_DST_End() {
    long interval = TimeUnit.MINUTES.toMillis(20);
    DateTimeZone tz = DateTimeZone.forID("CET");
    Rounding rounding = new TimeIntervalRounding(interval, tz);

    assertThat(rounding.round(time("2015-10-25T01:55:00+02:00")), isDate(time("2015-10-25T01:40:00+02:00"), tz));
    assertThat(rounding.round(time("2015-10-25T02:15:00+02:00")), isDate(time("2015-10-25T02:00:00+02:00"), tz));
    assertThat(rounding.round(time("2015-10-25T02:35:00+02:00")), isDate(time("2015-10-25T02:20:00+02:00"), tz));
    assertThat(rounding.round(time("2015-10-25T02:55:00+02:00")), isDate(time("2015-10-25T02:40:00+02:00"), tz));
    // after DST shift
    assertThat(rounding.round(time("2015-10-25T02:15:00+01:00")), isDate(time("2015-10-25T02:00:00+01:00"), tz));
    assertThat(rounding.round(time("2015-10-25T02:35:00+01:00")), isDate(time("2015-10-25T02:20:00+01:00"), tz));
    assertThat(rounding.round(time("2015-10-25T02:55:00+01:00")), isDate(time("2015-10-25T02:40:00+01:00"), tz));
    assertThat(rounding.round(time("2015-10-25T03:15:00+01:00")), isDate(time("2015-10-25T03:00:00+01:00"), tz));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:TimeZoneRoundingTests.java

示例3: testAmbiguousHoursAfterDSTSwitch

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
/**
 * special test for DST switch from #9491
 */
public void testAmbiguousHoursAfterDSTSwitch() {
    Rounding tzRounding;
    final DateTimeZone tz = DateTimeZone.forID("Asia/Jerusalem");
    tzRounding = Rounding.builder(DateTimeUnit.HOUR_OF_DAY).timeZone(tz).build();
    assertThat(tzRounding.round(time("2014-10-26T00:30:00+03:00")), isDate(time("2014-10-26T00:00:00+03:00"), tz));
    assertThat(tzRounding.round(time("2014-10-26T01:30:00+03:00")), isDate(time("2014-10-26T01:00:00+03:00"), tz));
    // the utc date for "2014-10-25T03:00:00+03:00" and "2014-10-25T03:00:00+02:00" is the same, local time turns back 1h here
    assertThat(time("2014-10-26T03:00:00+03:00"), isDate(time("2014-10-26T02:00:00+02:00"), tz));
    assertThat(tzRounding.round(time("2014-10-26T01:30:00+02:00")), isDate(time("2014-10-26T01:00:00+02:00"), tz));
    assertThat(tzRounding.round(time("2014-10-26T02:30:00+02:00")), isDate(time("2014-10-26T02:00:00+02:00"), tz));

    // Day interval
    tzRounding = Rounding.builder(DateTimeUnit.DAY_OF_MONTH).timeZone(tz).build();
    assertThat(tzRounding.round(time("2014-11-11T17:00:00", tz)), isDate(time("2014-11-11T00:00:00", tz), tz));
    // DST on
    assertThat(tzRounding.round(time("2014-08-11T17:00:00", tz)), isDate(time("2014-08-11T00:00:00", tz), tz));
    // Day of switching DST on -> off
    assertThat(tzRounding.round(time("2014-10-26T17:00:00", tz)), isDate(time("2014-10-26T00:00:00", tz), tz));
    // Day of switching DST off -> on
    assertThat(tzRounding.round(time("2015-03-27T17:00:00", tz)), isDate(time("2015-03-27T00:00:00", tz), tz));

    // Month interval
    tzRounding = Rounding.builder(DateTimeUnit.MONTH_OF_YEAR).timeZone(tz).build();
    assertThat(tzRounding.round(time("2014-11-11T17:00:00", tz)), isDate(time("2014-11-01T00:00:00", tz), tz));
    // DST on
    assertThat(tzRounding.round(time("2014-10-10T17:00:00", tz)), isDate(time("2014-10-01T00:00:00", tz), tz));

    // Year interval
    tzRounding = Rounding.builder(DateTimeUnit.YEAR_OF_CENTURY).timeZone(tz).build();
    assertThat(tzRounding.round(time("2014-11-11T17:00:00", tz)), isDate(time("2014-01-01T00:00:00", tz), tz));

    // Two timestamps in same year and different timezone offset ("Double buckets" issue - #9491)
    tzRounding = Rounding.builder(DateTimeUnit.YEAR_OF_CENTURY).timeZone(tz).build();
    assertThat(tzRounding.round(time("2014-11-11T17:00:00", tz)),
            isDate(tzRounding.round(time("2014-08-11T17:00:00", tz)), tz));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:TimeZoneRoundingTests.java

示例4: testJodaPatternMultipleFormats

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
public void testJodaPatternMultipleFormats() {
    List<String> matchFormats = new ArrayList<>();
    matchFormats.add("yyyy dd MM");
    matchFormats.add("dd/MM/yyyy");
    matchFormats.add("dd-MM-yyyy");
    DateProcessor dateProcessor = new DateProcessor(randomAsciiOfLength(10), DateTimeZone.forID("Europe/Amsterdam"), Locale.ENGLISH,
            "date_as_string", matchFormats, "date_as_date");

    Map<String, Object> document = new HashMap<>();
    document.put("date_as_string", "2010 12 06");
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
    dateProcessor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));

    document = new HashMap<>();
    document.put("date_as_string", "12/06/2010");
    ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
    dateProcessor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));

    document = new HashMap<>();
    document.put("date_as_string", "12-06-2010");
    ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
    dateProcessor.execute(ingestDocument);
    assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));

    document = new HashMap<>();
    document.put("date_as_string", "2010");
    ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
    try {
        dateProcessor.execute(ingestDocument);
        fail("processor should have failed due to not supported date format");
    } catch(IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("unable to parse date [2010]"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:DateProcessorTests.java

示例5: openSession

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
private void openSession() throws SQLException {
TSOpenSessionReq openReq = new TSOpenSessionReq(TSProtocolVersion.TSFILE_SERVICE_PROTOCOL_V1);

openReq.setUsername(params.getUsername());
openReq.setPassword(params.getPassword());

try {
    TSOpenSessionResp openResp = client.openSession(openReq);

    // validate connection
    Utils.verifySuccess(openResp.getStatus());
    if (!supportedProtocols.contains(openResp.getServerProtocolVersion())) {
	throw new TException("Unsupported TsFile protocol");
    }
    setProtocol(openResp.getServerProtocolVersion());
    sessionHandle = openResp.getSessionHandle();
    
    if(timeZone != null){
    		setTimeZone(timeZone.getID());
    } else {
    		timeZone = DateTimeZone.forID(getTimeZone());
    }
    
} catch (TException e) {
    throw new SQLException(
	    String.format("Can not establish connection with %s. because %s", params.getJdbcUriString(), e.getMessage()));
}
isClosed = false;
   }
 
开发者ID:thulab,项目名称:iotdb-jdbc,代码行数:30,代码来源:TsfileConnection.java

示例6: execute

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
@Override
public void execute(MessageReceivedEvent event, String[] args) {
    DateTime current = new DateTime(DateTimeZone.forID("America/Montreal"));
    while (current.getDayOfWeek() != DateTimeConstants.TUESDAY) {
        current = current.minusDays(1);
    }
    int weeks = Weeks.weeksBetween(Utils.startDateMythicPlus, current).getWeeks();
    String[] weekAffixes = Utils.mythicPlusAffixes[weeks % 12];

    event.getChannel().sendMessage(Utils.createMythicEmbed(bot, event.getGuild(), weekAffixes).build()).queue();
}
 
开发者ID:greatman,项目名称:legendarybot,代码行数:12,代码来源:AffixCommand.java

示例7: testIntervalRounding_NotDivisibleInteval

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
/**
 * Special test for intervals that don't fit evenly into rounding interval.
 * In this case, when interval crosses DST transition point, rounding in local
 * time can land in a DST gap which results in wrong UTC rounding values.
 */
public void testIntervalRounding_NotDivisibleInteval() {
    DateTimeZone tz = DateTimeZone.forID("CET");
    long interval = TimeUnit.MINUTES.toMillis(14);
    Rounding rounding = new Rounding.TimeIntervalRounding(interval, tz);

    assertThat(rounding.round(time("2016-03-27T01:41:00+01:00")), isDate(time("2016-03-27T01:30:00+01:00"), tz));
    assertThat(rounding.round(time("2016-03-27T01:51:00+01:00")), isDate(time("2016-03-27T01:44:00+01:00"), tz));
    assertThat(rounding.round(time("2016-03-27T01:59:00+01:00")), isDate(time("2016-03-27T01:58:00+01:00"), tz));
    assertThat(rounding.round(time("2016-03-27T03:05:00+02:00")), isDate(time("2016-03-27T03:00:00+02:00"), tz));
    assertThat(rounding.round(time("2016-03-27T03:12:00+02:00")), isDate(time("2016-03-27T03:08:00+02:00"), tz));
    assertThat(rounding.round(time("2016-03-27T03:25:00+02:00")), isDate(time("2016-03-27T03:22:00+02:00"), tz));
    assertThat(rounding.round(time("2016-03-27T03:39:00+02:00")), isDate(time("2016-03-27T03:36:00+02:00"), tz));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:TimeZoneRoundingTests.java

示例8: setTimeZone

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
public void setTimeZone(String tz) throws TException, TsfileSQLException{
	TSSetTimeZoneReq req = new TSSetTimeZoneReq(tz);
	TSSetTimeZoneResp resp = client.setTimeZone(req);
	Utils.verifySuccess(resp.getStatus());
	
	timeZone = DateTimeZone.forID(tz);
}
 
开发者ID:thulab,项目名称:iotdb-jdbc,代码行数:8,代码来源:TsfileConnection.java

示例9: configure

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
@Override
public void configure(Map<String, Object> config) {
  long partitionDurationMs = (long) config.get(HdfsSinkConnectorConfig.PARTITION_DURATION_MS_CONFIG);
  if (partitionDurationMs < 0) {
    throw new ConfigException(HdfsSinkConnectorConfig.PARTITION_DURATION_MS_CONFIG,
                              partitionDurationMs, "Partition duration needs to be a positive.");
  }

  String pathFormat = (String) config.get(HdfsSinkConnectorConfig.PATH_FORMAT_CONFIG);
  if (pathFormat.equals("")) {
    throw new ConfigException(HdfsSinkConnectorConfig.PATH_FORMAT_CONFIG,
                              pathFormat, "Path format cannot be empty.");
  }

  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,代码行数:33,代码来源:TimeBasedPartitioner.java

示例10: doAdjustDST

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
private static DateTime doAdjustDST(DateTime dateTime, ExamRoom room) {
    DateTimeZone dtz;
    DateTime result = dateTime;
    if (room == null) {
        dtz = getDefaultTimeZone();
    } else {
        dtz = DateTimeZone.forID(room.getLocalTimezone());
    }
    if (!dtz.isStandardOffset(System.currentTimeMillis())) {
        result = dateTime.plusHours(1);
    }
    return result;
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:14,代码来源:AppUtil.java

示例11: testTimeIntervalCET_DST_Start

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
/**
 * test DST start with interval rounding
 * CET: 27 March 2016, 02:00:00 clocks were turned forward 1 hour to 27 March 2016, 03:00:00 local daylight time
 */
public void testTimeIntervalCET_DST_Start() {
    long interval = TimeUnit.MINUTES.toMillis(20);
    DateTimeZone tz = DateTimeZone.forID("CET");
    Rounding rounding = new TimeIntervalRounding(interval, tz);
    // test DST start
    assertThat(rounding.round(time("2016-03-27T01:55:00+01:00")), isDate(time("2016-03-27T01:40:00+01:00"), tz));
    assertThat(rounding.round(time("2016-03-27T02:00:00+01:00")), isDate(time("2016-03-27T03:00:00+02:00"), tz));
    assertThat(rounding.round(time("2016-03-27T03:15:00+02:00")), isDate(time("2016-03-27T03:00:00+02:00"), tz));
    assertThat(rounding.round(time("2016-03-27T03:35:00+02:00")), isDate(time("2016-03-27T03:20:00+02:00"), tz));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:TimeZoneRoundingTests.java

示例12: testSingleValuedFieldNormalised_timeZone_CET_DstStart

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
/**
 * Do a derivative on a date histogram with time zone CET at DST start
 */
public void testSingleValuedFieldNormalised_timeZone_CET_DstStart() throws Exception {
    createIndex(IDX_DST_START);
    List<IndexRequestBuilder> builders = new ArrayList<>();

    DateTimeZone timezone = DateTimeZone.forID("CET");
    addNTimes(1, IDX_DST_START, new DateTime("2012-03-24T01:00:00", timezone), builders);
    addNTimes(2, IDX_DST_START, new DateTime("2012-03-25T01:00:00", timezone), builders); // day with dst shift, only 23h long
    addNTimes(3, IDX_DST_START, new DateTime("2012-03-26T01:00:00", timezone), builders);
    addNTimes(4, IDX_DST_START, new DateTime("2012-03-27T01:00:00", timezone), builders);
    indexRandom(true, builders);
    ensureSearchable();

    SearchResponse response = client()
            .prepareSearch(IDX_DST_START)
            .addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY)
                    .timeZone(timezone).minDocCount(0)
                    .subAggregation(derivative("deriv", "_count").unit(DateHistogramInterval.HOUR)))
            .execute()
            .actionGet();

    assertSearchResponse(response);

    Histogram deriv = response.getAggregations().get("histo");
    assertThat(deriv, notNullValue());
    assertThat(deriv.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = deriv.getBuckets();
    assertThat(buckets.size(), equalTo(4));

    assertBucket(buckets.get(0), new DateTime("2012-03-24", timezone).toDateTime(DateTimeZone.UTC), 1L, nullValue(), null, null);
    assertBucket(buckets.get(1), new DateTime("2012-03-25", timezone).toDateTime(DateTimeZone.UTC), 2L, notNullValue(), 1d, 1d / 24d);
    // the following is normalized using a 23h bucket width
    assertBucket(buckets.get(2), new DateTime("2012-03-26", timezone).toDateTime(DateTimeZone.UTC), 3L, notNullValue(), 1d, 1d / 23d);
    assertBucket(buckets.get(3), new DateTime("2012-03-27", timezone).toDateTime(DateTimeZone.UTC), 4L, notNullValue(), 1d, 1d / 24d);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:DateDerivativeIT.java

示例13: parseTimeZone

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
public static DateTimeZone parseTimeZone(BytesRef timezone) throws IllegalArgumentException {
    if (timezone == null) {
        throw new IllegalArgumentException("invalid time zone value NULL");
    }
    if (timezone.equals(DEFAULT_TZ_BYTES_REF)) {
        return DEFAULT_TZ;
    }

    DateTimeZone tz = TIME_ZONE_MAP.get(timezone);
    if (tz == null) {
        try {
            String text = timezone.utf8ToString();
            int index = text.indexOf(':');
            if (index != -1) {
                int beginIndex = text.charAt(0) == '+' ? 1 : 0;
                // format like -02:30
                tz = DateTimeZone.forOffsetHoursMinutes(
                        Integer.parseInt(text.substring(beginIndex, index)),
                        Integer.parseInt(text.substring(index + 1))
                );
            } else {
                // id, listed here: http://joda-time.sourceforge.net/timezones.html
                // or here: http://www.joda.org/joda-time/timezones.html
                tz = DateTimeZone.forID(text);
            }
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                    "invalid time zone value '%s'", timezone.utf8ToString()));
        }
        TIME_ZONE_MAP.putIfAbsent(timezone, tz);
    }
    return tz;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:34,代码来源:TimeZoneParser.java

示例14: testSingleValuedFieldNormalised_timeZone_AsiaKathmandu

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
/**
 * also check for time zone shifts that are not one hour, e.g.
 * "Asia/Kathmandu, 1 Jan 1986 - Time Zone Change (IST → NPT), at 00:00:00 clocks were turned forward 00:15 minutes
 */
public void testSingleValuedFieldNormalised_timeZone_AsiaKathmandu() throws Exception {
    createIndex(IDX_DST_KATHMANDU);
    DateTimeZone timezone = DateTimeZone.forID("Asia/Kathmandu");
    List<IndexRequestBuilder> builders = new ArrayList<>();

    addNTimes(1, IDX_DST_KATHMANDU, new DateTime("1985-12-31T22:30:00", timezone), builders);
    // the shift happens during the next bucket, which includes the 45min that do not start on the full hour
    addNTimes(2, IDX_DST_KATHMANDU, new DateTime("1985-12-31T23:30:00", timezone), builders);
    addNTimes(3, IDX_DST_KATHMANDU, new DateTime("1986-01-01T01:30:00", timezone), builders);
    addNTimes(4, IDX_DST_KATHMANDU, new DateTime("1986-01-01T02:30:00", timezone), builders);
    indexRandom(true, builders);
    ensureSearchable();

    SearchResponse response = client()
            .prepareSearch(IDX_DST_KATHMANDU)
            .addAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.HOUR)
                    .timeZone(timezone).minDocCount(0)
                    .subAggregation(derivative("deriv", "_count").unit(DateHistogramInterval.MINUTE)))
            .execute()
            .actionGet();

    assertSearchResponse(response);

    Histogram deriv = response.getAggregations().get("histo");
    assertThat(deriv, notNullValue());
    assertThat(deriv.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = deriv.getBuckets();
    assertThat(buckets.size(), equalTo(4));

    assertBucket(buckets.get(0), new DateTime("1985-12-31T22:00:00", timezone).toDateTime(DateTimeZone.UTC), 1L, nullValue(), null,
            null);
    assertBucket(buckets.get(1), new DateTime("1985-12-31T23:00:00", timezone).toDateTime(DateTimeZone.UTC), 2L, notNullValue(), 1d,
            1d / 60d);
    // the following is normalized using a 105min bucket width
    assertBucket(buckets.get(2), new DateTime("1986-01-01T01:00:00", timezone).toDateTime(DateTimeZone.UTC), 3L, notNullValue(), 1d,
            1d / 105d);
    assertBucket(buckets.get(3), new DateTime("1986-01-01T02:00:00", timezone).toDateTime(DateTimeZone.UTC), 4L, notNullValue(), 1d,
            1d / 60d);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:44,代码来源:DateDerivativeIT.java

示例15: testTimeZoneParsing

import org.joda.time.DateTimeZone; //导入方法依赖的package包/类
/**
 * Test that time zones are correctly parsed by the {@link DateFieldMapper}.
 * There is a known bug with Joda 2.9.4 reported in https://github.com/JodaOrg/joda-time/issues/373.
 */
public void testTimeZoneParsing() throws Exception {
    final String timeZonePattern = "yyyy-MM-dd" + randomFrom("ZZZ", "[ZZZ]", "'['ZZZ']'");

    String mapping = XContentFactory.jsonBuilder().startObject()
            .startObject("type")
                .startObject("properties")
                    .startObject("field")
                        .field("type", "date")
                        .field("format", timeZonePattern)
                    .endObject()
                .endObject()
            .endObject().endObject().string();

    DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
    assertEquals(mapping, mapper.mappingSource().toString());

    final DateTimeZone randomTimeZone = randomBoolean() ? DateTimeZone.forID(randomFrom("UTC", "CET")) : randomDateTimeZone();
    final DateTime randomDate = new DateTime(2016, 03, 11, 0, 0, 0, randomTimeZone);

    ParsedDocument doc = mapper.parse("test", "type", "1", XContentFactory.jsonBuilder()
            .startObject()
                .field("field", DateTimeFormat.forPattern(timeZonePattern).print(randomDate))
            .endObject()
            .bytes());

    IndexableField[] fields = doc.rootDoc().getFields("field");
    assertEquals(2, fields.length);

    assertEquals(randomDate.withZone(DateTimeZone.UTC).getMillis(), fields[0].numericValue().longValue());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:DateFieldMapperTests.java


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