Example usage for org.joda.time DateTimeZone getID

List of usage examples for org.joda.time DateTimeZone getID

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone getID.

Prototype

@ToString
public final String getID() 

Source Link

Document

Gets the ID of this datetime zone.

Usage

From source file:io.druid.sql.calcite.expression.TimeExtractOperatorConversion.java

License:Apache License

public static DruidExpression applyTimeExtract(final DruidExpression timeExpression,
        final TimestampExtractExprMacro.Unit unit, final DateTimeZone timeZone) {
    return timeExpression.map(simpleExtraction -> {
        final String formatString = EXTRACT_FORMAT_MAP.get(unit);
        if (formatString == null) {
            return null;
        } else {//from www  .j a  va  2s.c  om
            return TimeFormatOperatorConversion.applyTimestampFormat(simpleExtraction, formatString, timeZone);
        }
    }, expression -> String.format("timestamp_extract(%s,%s,%s)", expression,
            DruidExpression.stringLiteral(unit.name()), DruidExpression.stringLiteral(timeZone.getID())));
}

From source file:io.druid.sql.calcite.expression.TimeFormatOperatorConversion.java

License:Apache License

@Override
public DruidExpression toDruidExpression(final PlannerContext plannerContext, final RowSignature rowSignature,
        final RexNode rexNode) {
    final RexCall call = (RexCall) rexNode;
    final RexNode timeArg = call.getOperands().get(0);
    final DruidExpression timeExpression = Expressions.toDruidExpression(plannerContext, rowSignature, timeArg);
    if (timeExpression == null) {
        return null;
    }/* w ww. j av a 2  s.  c  om*/

    final String pattern = call.getOperands().size() > 1 && !RexLiteral.isNullLiteral(call.getOperands().get(1))
            ? RexLiteral.stringValue(call.getOperands().get(1))
            : "yyyy-MM-dd'T'HH:mm:ss.SSSZZ";
    final DateTimeZone timeZone = call.getOperands().size() > 2
            && !RexLiteral.isNullLiteral(call.getOperands().get(2))
                    ? DateTimeZone.forID(RexLiteral.stringValue(call.getOperands().get(2)))
                    : plannerContext.getTimeZone();

    return timeExpression.map(simpleExtraction -> applyTimestampFormat(simpleExtraction, pattern, timeZone),
            expression -> DruidExpression.functionCall("timestamp_format",
                    ImmutableList
                            .of(expression, DruidExpression.stringLiteral(pattern),
                                    DruidExpression.stringLiteral(timeZone.getID()))
                            .stream().map(DruidExpression::fromExpression).collect(Collectors.toList())));
}

From source file:io.prestosql.plugin.hive.HiveMetadataFactory.java

License:Apache License

public HiveMetadataFactory(ExtendedHiveMetastore metastore, HdfsEnvironment hdfsEnvironment,
        HivePartitionManager partitionManager, DateTimeZone timeZone, int maxConcurrentFileRenames,
        boolean allowCorruptWritesForTesting, boolean skipDeletionForAlter, boolean skipTargetCleanupOnRollback,
        boolean writesToNonManagedTablesEnabled, boolean createsOfNonManagedTablesEnabled,
        long perTransactionCacheMaximumSize, int maxPartitions, TypeManager typeManager,
        LocationService locationService, TableParameterCodec tableParameterCodec,
        JsonCodec<PartitionUpdate> partitionUpdateCodec, ExecutorService executorService,
        TypeTranslator typeTranslator, String prestoVersion) {
    this.allowCorruptWritesForTesting = allowCorruptWritesForTesting;
    this.skipDeletionForAlter = skipDeletionForAlter;
    this.skipTargetCleanupOnRollback = skipTargetCleanupOnRollback;
    this.writesToNonManagedTablesEnabled = writesToNonManagedTablesEnabled;
    this.createsOfNonManagedTablesEnabled = createsOfNonManagedTablesEnabled;
    this.perTransactionCacheMaximumSize = perTransactionCacheMaximumSize;

    this.metastore = requireNonNull(metastore, "metastore is null");
    this.hdfsEnvironment = requireNonNull(hdfsEnvironment, "hdfsEnvironment is null");
    this.partitionManager = requireNonNull(partitionManager, "partitionManager is null");
    this.timeZone = requireNonNull(timeZone, "timeZone is null");
    this.typeManager = requireNonNull(typeManager, "typeManager is null");
    this.locationService = requireNonNull(locationService, "locationService is null");
    this.tableParameterCodec = requireNonNull(tableParameterCodec, "tableParameterCodec is null");
    this.partitionUpdateCodec = requireNonNull(partitionUpdateCodec, "partitionUpdateCodec is null");
    this.typeTranslator = requireNonNull(typeTranslator, "typeTranslator is null");
    this.prestoVersion = requireNonNull(prestoVersion, "prestoVersion is null");
    this.maxPartitions = maxPartitions;

    if (!allowCorruptWritesForTesting && !timeZone.equals(DateTimeZone.getDefault())) {
        log.warn("Hive writes are disabled. "
                + "To write data to Hive, your JVM timezone must match the Hive storage timezone. "
                + "Add -Duser.timezone=%s to your JVM arguments", timeZone.getID());
    }//from   w  w w . ja va 2  s.c o m

    renameExecution = new BoundedExecutor(executorService, maxConcurrentFileRenames);
}

From source file:net.danlew.android.joda.ZoneInfoCompiler.java

License:Apache License

/**
 * @return false if error.//from   w w  w  .  ja  v  a2s . c o m
 */
static boolean test(String id, DateTimeZone tz) {
    if (!id.equals(tz.getID())) {
        return true;
    }

    // Test to ensure that reported transitions are not duplicated.

    long millis = ISOChronology.getInstanceUTC().year().set(0, 1850);
    long end = ISOChronology.getInstanceUTC().year().set(0, 2050);

    int offset = tz.getOffset(millis);
    String key = tz.getNameKey(millis);

    List<Long> transitions = new ArrayList<Long>();

    while (true) {
        long next = tz.nextTransition(millis);
        if (next == millis || next > end) {
            break;
        }

        millis = next;

        int nextOffset = tz.getOffset(millis);
        String nextKey = tz.getNameKey(millis);

        if (offset == nextOffset && key.equals(nextKey)) {
            System.out.println(
                    "*d* Error in " + tz.getID() + " " + new DateTime(millis, ISOChronology.getInstanceUTC()));
            return false;
        }

        if (nextKey == null || (nextKey.length() < 3 && !"??".equals(nextKey))) {
            System.out.println("*s* Error in " + tz.getID() + " "
                    + new DateTime(millis, ISOChronology.getInstanceUTC()) + ", nameKey=" + nextKey);
            return false;
        }

        transitions.add(Long.valueOf(millis));

        offset = nextOffset;
        key = nextKey;
    }

    // Now verify that reverse transitions match up.

    millis = ISOChronology.getInstanceUTC().year().set(0, 2050);
    end = ISOChronology.getInstanceUTC().year().set(0, 1850);

    for (int i = transitions.size(); --i >= 0;) {
        long prev = tz.previousTransition(millis);
        if (prev == millis || prev < end) {
            break;
        }

        millis = prev;

        long trans = transitions.get(i).longValue();

        if (trans - 1 != millis) {
            System.out.println(
                    "*r* Error in " + tz.getID() + " " + new DateTime(millis, ISOChronology.getInstanceUTC())
                            + " != " + new DateTime(trans - 1, ISOChronology.getInstanceUTC()));

            return false;
        }
    }

    return true;
}

From source file:net.danlew.android.joda.ZoneInfoCompiler.java

License:Apache License

/**
 * Returns a map of ids to DateTimeZones.
 *
 * @param outputDir optional directory to write compiled data files to
 * @param sources optional list of source files to parse
 *///from w ww . j a  v  a 2 s.c o  m
public Map<String, DateTimeZone> compile(File outputDir, File[] sources) throws IOException {
    if (sources != null) {
        for (int i = 0; i < sources.length; i++) {
            BufferedReader in = new BufferedReader(new FileReader(sources[i]));
            parseDataFile(in);
            in.close();
        }
    }

    if (outputDir != null) {
        if (!outputDir.exists()) {
            if (!outputDir.mkdirs()) {
                throw new IOException(
                        "Destination directory doesn't exist and cannot be created: " + outputDir);
            }
        }
        if (!outputDir.isDirectory()) {
            throw new IOException("Destination is not a directory: " + outputDir);
        }
    }

    Map<String, DateTimeZone> map = new TreeMap<String, DateTimeZone>();

    System.out.println("Writing zoneinfo files");
    for (int i = 0; i < iZones.size(); i++) {
        Zone zone = iZones.get(i);
        DateTimeZoneBuilder builder = new DateTimeZoneBuilder();
        zone.addToBuilder(builder, iRuleSets);
        final DateTimeZone original = builder.toDateTimeZone(zone.iName, true);
        DateTimeZone tz = original;
        if (test(tz.getID(), tz)) {
            map.put(tz.getID(), tz);
            if (outputDir != null) {
                String fileName = ResUtils.getTzResource(tz.getID());
                if (ZoneInfoCompiler.verbose()) {
                    System.out.println("Writing " + fileName);
                }
                File file = new File(outputDir, fileName);
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                OutputStream out = new FileOutputStream(file);
                try {
                    builder.writeTo(zone.iName, out);
                } finally {
                    out.close();
                }

                // Test if it can be read back.
                InputStream in = new FileInputStream(file);
                DateTimeZone tz2 = DateTimeZoneBuilder.readFrom(in, tz.getID());
                in.close();

                if (!original.equals(tz2)) {
                    System.out.println("*e* Error in " + tz.getID() + ": Didn't read properly from file");
                }
            }
        }
    }

    for (int pass = 0; pass < 2; pass++) {
        for (int i = 0; i < iLinks.size(); i += 2) {
            String id = iLinks.get(i);
            String alias = iLinks.get(i + 1);
            DateTimeZone tz = map.get(id);
            if (tz == null) {
                if (pass > 0) {
                    System.out.println("Cannot find time zone '" + id + "' to link alias '" + alias + "' to");
                }
            } else {
                map.put(alias, tz);
            }
        }
    }

    if (outputDir != null) {
        System.out.println("Writing " + ResUtils.getZoneInfoMapResource());
        File file = new File(outputDir, ResUtils.getZoneInfoMapResource());
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }

        OutputStream out = new FileOutputStream(file);
        DataOutputStream dout = new DataOutputStream(out);
        try {
            // Sort and filter out any duplicates that match case.
            Map<String, DateTimeZone> zimap = new TreeMap<String, DateTimeZone>(String.CASE_INSENSITIVE_ORDER);
            zimap.putAll(map);
            writeZoneInfoMap(dout, zimap);
        } finally {
            dout.close();
        }
    }

    return map;
}

From source file:net.sourceforge.fenixedu.domain.time.chronologies.AcademicChronology.java

License:Open Source License

@Override
public String toString() {
    String str = "AcademicChronology";
    DateTimeZone zone = getZone();
    if (zone != null) {
        str = str + '[' + zone.getID() + ']';
    }//from  w  ww .ja  v  a2  s  .  c  o  m
    return str;
}

From source file:openmarker.tea.runtime.DefaultContext.java

License:Apache License

public String getDateFormatTimeZone() {
    if (mDateTimeFormatter == null) {
        // Force formatter and time zone to be set.
        dateFormat(null);//w ww  .ja v a 2 s  .  com
    }
    DateTimeZone zone = mDateTimeZone;
    return zone == null ? null : zone.getID();
}

From source file:org.apache.druid.jackson.DruidDefaultSerializersModule.java

License:Apache License

public DruidDefaultSerializersModule() {
    super("Druid default serializers");

    JodaStuff.register(this);

    addDeserializer(DateTimeZone.class, new JsonDeserializer<DateTimeZone>() {
        @Override//  w  w w.  j av a2  s  . c  o  m
        public DateTimeZone deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
            String tzId = jp.getText();
            return DateTimes.inferTzFromString(tzId);
        }
    });
    addSerializer(DateTimeZone.class, new JsonSerializer<DateTimeZone>() {
        @Override
        public void serialize(DateTimeZone dateTimeZone, JsonGenerator jsonGenerator,
                SerializerProvider serializerProvider) throws IOException {
            jsonGenerator.writeString(dateTimeZone.getID());
        }
    });
    addSerializer(Sequence.class, new JsonSerializer<Sequence>() {
        @Override
        public void serialize(Sequence value, final JsonGenerator jgen, SerializerProvider provider)
                throws IOException {
            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 new RuntimeException(e);
                    }
                    return null;
                }
            });
            jgen.writeEndArray();
        }
    });
    addSerializer(Yielder.class, new JsonSerializer<Yielder>() {
        @Override
        public void serialize(Yielder yielder, final JsonGenerator jgen, SerializerProvider provider)
                throws IOException {
            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 {
            if (ByteOrder.BIG_ENDIAN.toString().equals(jp.getText())) {
                return ByteOrder.BIG_ENDIAN;
            }
            return ByteOrder.LITTLE_ENDIAN;
        }
    });
}

From source file:org.apache.druid.sql.calcite.expression.builtin.TimeFormatOperatorConversion.java

License:Apache License

@Override
public DruidExpression toDruidExpression(final PlannerContext plannerContext, final RowSignature rowSignature,
        final RexNode rexNode) {
    final RexCall call = (RexCall) rexNode;
    final RexNode timeArg = call.getOperands().get(0);
    final DruidExpression timeExpression = Expressions.toDruidExpression(plannerContext, rowSignature, timeArg);
    if (timeExpression == null) {
        return null;
    }/*from www  .ja v  a2  s  .co  m*/

    final String pattern = OperatorConversions.getOperandWithDefault(call.getOperands(), 1,
            RexLiteral::stringValue, DEFAULT_PATTERN);

    final DateTimeZone timeZone = OperatorConversions.getOperandWithDefault(call.getOperands(), 2,
            operand -> DateTimes.inferTzFromString(RexLiteral.stringValue(operand)),
            plannerContext.getTimeZone());

    return DruidExpression.fromFunctionCall("timestamp_format",
            ImmutableList
                    .of(timeExpression.getExpression(), DruidExpression.stringLiteral(pattern),
                            DruidExpression.stringLiteral(timeZone.getID()))
                    .stream().map(DruidExpression::fromExpression).collect(Collectors.toList()));
}

From source file:org.apache.druid.sql.calcite.expression.builtin.TimeParseOperatorConversion.java

License:Apache License

@Override
public DruidExpression toDruidExpression(final PlannerContext plannerContext, final RowSignature rowSignature,
        final RexNode rexNode) {
    final RexCall call = (RexCall) rexNode;
    final RexNode timeArg = call.getOperands().get(0);
    final DruidExpression timeExpression = Expressions.toDruidExpression(plannerContext, rowSignature, timeArg);
    if (timeExpression == null) {
        return null;
    }/*from  w  ww .  j a v  a  2s . c  o m*/

    final String pattern = OperatorConversions.getOperandWithDefault(call.getOperands(), 1,
            RexLiteral::stringValue, null);

    final DateTimeZone timeZone = OperatorConversions.getOperandWithDefault(call.getOperands(), 2,
            operand -> DateTimes.inferTzFromString(RexLiteral.stringValue(operand)),
            plannerContext.getTimeZone());

    return DruidExpression.fromFunctionCall("timestamp_parse",
            ImmutableList
                    .of(timeExpression.getExpression(), DruidExpression.stringLiteral(pattern),
                            DruidExpression.stringLiteral(timeZone.getID()))
                    .stream().map(DruidExpression::fromExpression).collect(Collectors.toList()));
}