List of usage examples for org.joda.time DateTimeZone forTimeZone
public static DateTimeZone forTimeZone(TimeZone zone)
From source file:io.druid.jackson.DruidDefaultSerializersModule.java
License:Apache License
public DruidDefaultSerializersModule() { super("Druid default serializers"); JodaStuff.register(this); addDeserializer(Granularity.class, new JsonDeserializer<Granularity>() { @Override// w w w .java2s. c o m public Granularity deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { return Granularity.valueOf(jp.getText().toUpperCase()); } }); addDeserializer(DateTimeZone.class, new JsonDeserializer<DateTimeZone>() { @Override public DateTimeZone deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { String tzId = jp.getText(); try { return DateTimeZone.forID(tzId); } catch (IllegalArgumentException e) { // also support Java timezone strings return DateTimeZone.forTimeZone(TimeZone.getTimeZone(tzId)); } } }); addSerializer(DateTimeZone.class, new JsonSerializer<DateTimeZone>() { @Override public void serialize(DateTimeZone dateTimeZone, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeString(dateTimeZone.getID()); } }); addSerializer(Sequence.class, new JsonSerializer<Sequence>() { @Override public void serialize(Sequence value, final JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartArray(); value.accumulate(null, new Accumulator<Object, Object>() { @Override public Object accumulate(Object o, Object o1) { try { jgen.writeObject(o1); } catch (IOException e) { throw Throwables.propagate(e); } return null; } }); jgen.writeEndArray(); } }); addSerializer(Yielder.class, new JsonSerializer<Yielder>() { @Override public void serialize(Yielder yielder, final JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { try { jgen.writeStartArray(); while (!yielder.isDone()) { final Object o = yielder.get(); jgen.writeObject(o); yielder = yielder.next(null); } jgen.writeEndArray(); } finally { yielder.close(); } } }); addSerializer(ByteOrder.class, ToStringSerializer.instance); addDeserializer(ByteOrder.class, new JsonDeserializer<ByteOrder>() { @Override public ByteOrder deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (ByteOrder.BIG_ENDIAN.toString().equals(jp.getText())) { return ByteOrder.BIG_ENDIAN; } return ByteOrder.LITTLE_ENDIAN; } }); }
From source file:io.druid.java.util.common.DateTimes.java
License:Apache License
public static DateTimeZone inferTzfromString(String tzId) { try {// w ww . j av a 2 s.c om return DateTimeZone.forID(tzId); } catch (IllegalArgumentException e) { // also support Java timezone strings return DateTimeZone.forTimeZone(TimeZone.getTimeZone(tzId)); } }
From source file:io.kahu.hawaii.util.xml.bind.DateTimeConverter.java
License:Apache License
public static DateTime getDateTime(Calendar calendar) { // @formatter:off return new DateTime(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DATE), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), calendar.get(Calendar.MILLISECOND), DateTimeZone.forTimeZone(calendar.getTimeZone())); // @formatter:on }
From source file:io.prestosql.plugin.hive.AbstractTestHiveClient.java
License:Apache License
protected void setupHive(String connectorId, String databaseName, String timeZoneId) { clientId = connectorId;/*www.j ava 2s. c o m*/ database = databaseName; tablePartitionFormat = new SchemaTableName(database, "presto_test_partition_format"); tableUnpartitioned = new SchemaTableName(database, "presto_test_unpartitioned"); tableOffline = new SchemaTableName(database, "presto_test_offline"); tableOfflinePartition = new SchemaTableName(database, "presto_test_offline_partition"); tableNotReadable = new SchemaTableName(database, "presto_test_not_readable"); view = new SchemaTableName(database, "presto_test_view"); invalidTable = new SchemaTableName(database, INVALID_TABLE); tableBucketedStringInt = new SchemaTableName(database, "presto_test_bucketed_by_string_int"); tableBucketedBigintBoolean = new SchemaTableName(database, "presto_test_bucketed_by_bigint_boolean"); tableBucketedDoubleFloat = new SchemaTableName(database, "presto_test_bucketed_by_double_float"); tablePartitionSchemaChange = new SchemaTableName(database, "presto_test_partition_schema_change"); tablePartitionSchemaChangeNonCanonical = new SchemaTableName(database, "presto_test_partition_schema_change_non_canonical"); tableBucketEvolution = new SchemaTableName(database, "presto_test_bucket_evolution"); invalidClientId = "hive"; invalidTableHandle = new HiveTableHandle(database, INVALID_TABLE); invalidTableLayoutHandle = new HiveTableLayoutHandle(invalidTable, ImmutableList.of(), ImmutableList.of(new HivePartition(invalidTable, "unknown", ImmutableMap.of())), TupleDomain.all(), TupleDomain.all(), Optional.empty(), Optional.empty()); dsColumn = new HiveColumnHandle("ds", HIVE_STRING, parseTypeSignature(StandardTypes.VARCHAR), -1, PARTITION_KEY, Optional.empty()); fileFormatColumn = new HiveColumnHandle("file_format", HIVE_STRING, parseTypeSignature(StandardTypes.VARCHAR), -1, PARTITION_KEY, Optional.empty()); dummyColumn = new HiveColumnHandle("dummy", HIVE_INT, parseTypeSignature(StandardTypes.INTEGER), -1, PARTITION_KEY, Optional.empty()); intColumn = new HiveColumnHandle("t_int", HIVE_INT, parseTypeSignature(StandardTypes.INTEGER), -1, PARTITION_KEY, Optional.empty()); invalidColumnHandle = new HiveColumnHandle(INVALID_COLUMN, HIVE_STRING, parseTypeSignature(StandardTypes.VARCHAR), 0, REGULAR, Optional.empty()); List<ColumnHandle> partitionColumns = ImmutableList.of(dsColumn, fileFormatColumn, dummyColumn); List<HivePartition> partitions = ImmutableList.<HivePartition>builder().add(new HivePartition( tablePartitionFormat, "ds=2012-12-29/file_format=textfile/dummy=1", ImmutableMap.<ColumnHandle, NullableValue>builder() .put(dsColumn, NullableValue.of(createUnboundedVarcharType(), utf8Slice("2012-12-29"))) .put(fileFormatColumn, NullableValue.of(createUnboundedVarcharType(), utf8Slice("textfile"))) .put(dummyColumn, NullableValue.of(INTEGER, 1L)).build())) .add(new HivePartition(tablePartitionFormat, "ds=2012-12-29/file_format=sequencefile/dummy=2", ImmutableMap.<ColumnHandle, NullableValue>builder() .put(dsColumn, NullableValue.of(createUnboundedVarcharType(), utf8Slice("2012-12-29"))) .put(fileFormatColumn, NullableValue.of(createUnboundedVarcharType(), utf8Slice("sequencefile"))) .put(dummyColumn, NullableValue.of(INTEGER, 2L)).build())) .add(new HivePartition(tablePartitionFormat, "ds=2012-12-29/file_format=rctext/dummy=3", ImmutableMap.<ColumnHandle, NullableValue>builder() .put(dsColumn, NullableValue.of(createUnboundedVarcharType(), utf8Slice("2012-12-29"))) .put(fileFormatColumn, NullableValue.of(createUnboundedVarcharType(), utf8Slice("rctext"))) .put(dummyColumn, NullableValue.of(INTEGER, 3L)).build())) .add(new HivePartition(tablePartitionFormat, "ds=2012-12-29/file_format=rcbinary/dummy=4", ImmutableMap.<ColumnHandle, NullableValue>builder() .put(dsColumn, NullableValue.of(createUnboundedVarcharType(), utf8Slice("2012-12-29"))) .put(fileFormatColumn, NullableValue.of(createUnboundedVarcharType(), utf8Slice("rcbinary"))) .put(dummyColumn, NullableValue.of(INTEGER, 4L)).build())) .build(); partitionCount = partitions.size(); tupleDomain = TupleDomain.fromFixedValues( ImmutableMap.of(dsColumn, NullableValue.of(createUnboundedVarcharType(), utf8Slice("2012-12-29")))); tableLayout = new ConnectorTableLayout( new HiveTableLayoutHandle(tablePartitionFormat, partitionColumns, partitions, tupleDomain, tupleDomain, Optional.empty(), Optional.empty()), Optional.empty(), TupleDomain.withColumnDomains(ImmutableMap.of(dsColumn, Domain.create(ValueSet.ofRanges( Range.equal(createUnboundedVarcharType(), utf8Slice("2012-12-29"))), false), fileFormatColumn, Domain.create( ValueSet.ofRanges(Range.equal(createUnboundedVarcharType(), utf8Slice("textfile")), Range.equal(createUnboundedVarcharType(), utf8Slice("sequencefile")), Range.equal(createUnboundedVarcharType(), utf8Slice("rctext")), Range.equal(createUnboundedVarcharType(), utf8Slice("rcbinary"))), false), dummyColumn, Domain.create(ValueSet.ofRanges(Range.equal(INTEGER, 1L), Range.equal(INTEGER, 2L), Range.equal(INTEGER, 3L), Range.equal(INTEGER, 4L)), false))), Optional.empty(), Optional.empty(), Optional.of(new DiscretePredicates(partitionColumns, ImmutableList.of( TupleDomain.withColumnDomains(ImmutableMap.of(dsColumn, Domain.create( ValueSet.ofRanges( Range.equal(createUnboundedVarcharType(), utf8Slice("2012-12-29"))), false), fileFormatColumn, Domain.create( ValueSet.ofRanges( Range.equal(createUnboundedVarcharType(), utf8Slice("textfile"))), false), dummyColumn, Domain.create(ValueSet.ofRanges(Range.equal(INTEGER, 1L)), false))), TupleDomain.withColumnDomains(ImmutableMap.of(dsColumn, Domain.create(ValueSet.ofRanges( Range.equal(createUnboundedVarcharType(), utf8Slice("2012-12-29"))), false), fileFormatColumn, Domain.create(ValueSet.ofRanges( Range.equal(createUnboundedVarcharType(), utf8Slice("sequencefile"))), false), dummyColumn, Domain.create(ValueSet.ofRanges(Range.equal(INTEGER, 2L)), false))), TupleDomain.withColumnDomains(ImmutableMap.of(dsColumn, Domain.create( ValueSet.ofRanges( Range.equal(createUnboundedVarcharType(), utf8Slice("2012-12-29"))), false), fileFormatColumn, Domain.create( ValueSet.ofRanges( Range.equal(createUnboundedVarcharType(), utf8Slice("rctext"))), false), dummyColumn, Domain.create(ValueSet.ofRanges(Range.equal(INTEGER, 3L)), false))), TupleDomain.withColumnDomains(ImmutableMap.of(dsColumn, Domain.create( ValueSet.ofRanges( Range.equal(createUnboundedVarcharType(), utf8Slice("2012-12-29"))), false), fileFormatColumn, Domain.create( ValueSet.ofRanges( Range.equal(createUnboundedVarcharType(), utf8Slice("rcbinary"))), false), dummyColumn, Domain.create(ValueSet.ofRanges(Range.equal(INTEGER, 4L)), false)))))), ImmutableList.of()); List<HivePartition> unpartitionedPartitions = ImmutableList.of(new HivePartition(tableUnpartitioned)); unpartitionedTableLayout = new ConnectorTableLayout( new HiveTableLayoutHandle(tableUnpartitioned, ImmutableList.of(), unpartitionedPartitions, TupleDomain.all(), TupleDomain.all(), Optional.empty(), Optional.empty())); timeZone = DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZoneId)); }
From source file:jp.furplag.util.Localizer.java
License:Apache License
private static DateTimeZone getDateTimeZone(final String zone) { if (zone == null) return DateTimeZone.getDefault(); if (StringUtils.isSimilarToBlank(zone)) return DateTimeZone.UTC; if (DateTimeZone.getAvailableIDs().contains(zone)) return DateTimeZone.forID(zone.toString()); if (LazyInitializer.ZONE_DUPRECATED.containsKey(zone)) return DateTimeZone.forTimeZone(TimeZone.getTimeZone(LazyInitializer.ZONE_DUPRECATED.get(zone))); if (LazyInitializer.AVAILABLE_ZONE_IDS.contains(zone)) return DateTimeZone.forTimeZone(TimeZone.getTimeZone(zone)); Matcher base = OFFSET.matcher(StringUtils.normalize(zone, true)); if (base.find()) { String offsetString = base.group(); int[] offsetTime = JSONifier.parseLazy( JSONifier.stringifyLazy(StringUtils.truncateFirst(offsetString, "[\\+\\-]").split("[:\\.]")), int[].class); if (offsetTime.length < 1) return DateTimeZone.UTC; LocalTime offset = new LocalTime(offsetTime.length > 0 ? offsetTime[0] : 0, offsetTime.length > 1 ? offsetTime[1] : 0, offsetTime.length > 2 ? offsetTime[2] : 0, offsetTime.length > 3 ? offsetTime[3] : 0); return DateTimeZone.forID((offsetString.startsWith("-") ? "-" : "+") + offset.toString(OFFSET_FORMAT)); }//www . j a va 2s. co m return DateTimeZone.UTC; }
From source file:jp.furplag.util.Localizer.java
License:Apache License
private static DateTimeZone getDateTimeZone(final TimeZone zone) { if (zone == null) return DateTimeZone.getDefault(); String zoneID = ((TimeZone) zone).getID(); if (DateTimeZone.getAvailableIDs().contains(zoneID)) return DateTimeZone.forID(zoneID); if (LazyInitializer.ZONE_DUPRECATED.containsKey(zoneID)) return DateTimeZone.forTimeZone(TimeZone.getTimeZone(LazyInitializer.ZONE_DUPRECATED.get(zoneID))); return DateTimeZone.forTimeZone((TimeZone) zone); }
From source file:lucee.commons.date.JodaDateTimeUtil.java
License:Open Source License
private DateTimeZone getDateTimeZone(TimeZone tz) { DateTimeZone dtz = (DateTimeZone) zones.get(tz); if (dtz == null) { dtz = DateTimeZone.forTimeZone(tz); zones.put(tz, dtz);/*from w w w. ja v a 2 s. co m*/ } return dtz; }
From source file:name.gano.astro.time.Time.java
License:Open Source License
/** Constructor from Joda DateTime **/ public Time(DateTime time) { time.withZone(DateTimeZone.forTimeZone(tz)); currentTime = time.toGregorianCalendar(); updateTimeMeasures(); }
From source file:name.gano.astro.time.Time.java
License:Open Source License
public static GregorianCalendar convertJD2Calendar(double jd) { return MJD_EPOCH.plus(new Duration((long) (mjdOfJd(jd) * 24 * 60 * 60000))) .toDateTime(DateTimeZone.forTimeZone(tz)).toGregorianCalendar(); }
From source file:net.sf.jasperreports.functions.standard.DateTimeFunctions.java
License:Open Source License
/** *Creates a date object using the specified information on day, month and year. *///from ww w.j av a 2 s .c o m @Function("DATE") @FunctionParameters({ @FunctionParameter("year"), @FunctionParameter("month"), @FunctionParameter("dayOfMonth") }) public Date DATE(Integer year, Integer month, Integer dayOfMonth) { if (year == null || month == null || dayOfMonth == null) { if (log.isDebugEnabled()) { log.debug("None of the arguments can be null."); } return null; } return new DateTime(year, month, dayOfMonth, 0, 0, 0, DateTimeZone.forTimeZone(getReportTimeZone())) .toDate(); }