Example usage for org.joda.time DateTimeZone convertUTCToLocal

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

Introduction

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

Prototype

public long convertUTCToLocal(long instantUTC) 

Source Link

Document

Converts an actual UTC instant to a local instant with the same local time.

Usage

From source file:com.facebook.presto.hive.GenericHiveRecordCursor.java

License:Apache License

private static long getLongOrTimestamp(Object value, DateTimeZone hiveTimeZone) {
    if (value instanceof Timestamp) {
        // The Hive SerDe parses timestamps using the default time zone of
        // this JVM, but the data might have been written using a different
        // time zone. We need to convert it to the configured time zone.

        // the timestamp that Hive parsed using the JVM time zone
        long parsedJvmMillis = ((Timestamp) value).getTime();

        // remove the JVM time zone correction from the timestamp
        DateTimeZone jvmTimeZone = DateTimeZone.getDefault();
        long hiveMillis = jvmTimeZone.convertUTCToLocal(parsedJvmMillis);

        // convert to UTC using the real time zone for the underlying data
        long utcMillis = hiveTimeZone.convertLocalToUTC(hiveMillis, false);

        return utcMillis;
    }//from w  w w.j  a va2s.co  m
    return ((Number) value).longValue();
}

From source file:com.facebook.presto.hive.util.Statistics.java

License:Apache License

private static OptionalLong getTimestampValue(DateTimeZone timeZone, Block block) {
    // TODO #7122
    return block.isNull(0) ? OptionalLong.empty()
            : OptionalLong.of(MILLISECONDS.toSeconds(timeZone.convertUTCToLocal(block.getLong(0, 0))));
}

From source file:io.confluent.connect.hdfs.partitioner.TimeBasedPartitioner.java

License:Apache License

public static long getPartition(long timeGranularityMs, long timestamp, DateTimeZone timeZone) {
    long adjustedTimeStamp = timeZone.convertUTCToLocal(timestamp);
    long partitionedTime = (adjustedTimeStamp / timeGranularityMs) * timeGranularityMs;
    return timeZone.convertLocalToUTC(partitionedTime, false);
}

From source file:io.confluent.connect.hdfs.partitioner.TimeUtils.java

License:Apache License

private static long getPartition(long timeGranularityMs, long timestamp, DateTimeZone timeZone) {
    long adjustedTimeStamp = timeZone.convertUTCToLocal(timestamp);
    long partitionedTime = (adjustedTimeStamp / timeGranularityMs) * timeGranularityMs;
    return timeZone.convertLocalToUTC(partitionedTime, false);
}

From source file:io.confluent.connect.storage.partitioner.TimeBasedPartitioner.java

License:Open Source License

public static long getPartition(long timeGranularityMs, long timestamp, DateTimeZone timeZone) {
    long adjustedTimestamp = timeZone.convertUTCToLocal(timestamp);
    long partitionedTime = (adjustedTimestamp / timeGranularityMs) * timeGranularityMs;
    return timeZone.convertLocalToUTC(partitionedTime, false);
}

From source file:io.confluent.connect.storage.util.DateTimeUtils.java

License:Open Source License

/**
 * Calculates next period of periodMs after currentTimeMs
 * starting from midnight in given timeZone.
 * If the next period is in next day then 12am of next day
 * will be returned//from ww  w.jav a  2  s. co m
 *
 * @param currentTimeMs time to calculate at
 * @param periodMs period in ms
 * @param timeZone timezone to get midnight time
 * @return timestamp in ms
 */
public static long getNextTimeAdjustedByDay(long currentTimeMs, long periodMs, DateTimeZone timeZone) {
    long startOfDay = timeZone
            .convertLocalToUTC(timeZone.convertUTCToLocal(currentTimeMs) / DAY_IN_MS * DAY_IN_MS, true);
    long nextPeriodOffset = ((currentTimeMs - startOfDay) / periodMs + 1) * periodMs;
    long offset = Math.min(nextPeriodOffset, DAY_IN_MS);
    return startOfDay + offset;
}

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

License:Apache License

private static long getLongExpressedValue(Object value, DateTimeZone hiveTimeZone) {
    if (value instanceof Date) {
        long storageTime = ((Date) value).getTime();
        // convert date from VM current time zone to UTC
        long utcMillis = storageTime + DateTimeZone.getDefault().getOffset(storageTime);
        return TimeUnit.MILLISECONDS.toDays(utcMillis);
    }//from w  w  w.  java2 s .com
    if (value instanceof Timestamp) {
        // The Hive SerDe parses timestamps using the default time zone of
        // this JVM, but the data might have been written using a different
        // time zone. We need to convert it to the configured time zone.

        // the timestamp that Hive parsed using the JVM time zone
        long parsedJvmMillis = ((Timestamp) value).getTime();

        // remove the JVM time zone correction from the timestamp
        DateTimeZone jvmTimeZone = DateTimeZone.getDefault();
        long hiveMillis = jvmTimeZone.convertUTCToLocal(parsedJvmMillis);

        // convert to UTC using the real time zone for the underlying data
        long utcMillis = hiveTimeZone.convertLocalToUTC(hiveMillis, false);

        return utcMillis;
    }
    if (value instanceof Float) {
        return floatToRawIntBits(((Float) value));
    }
    return ((Number) value).longValue();
}

From source file:io.prestosql.plugin.hive.util.Statistics.java

License:Apache License

private static OptionalLong getTimestampValue(DateTimeZone timeZone, Block block) {
    // TODO https://github.com/prestodb/presto/issues/7122
    return block.isNull(0) ? OptionalLong.empty()
            : OptionalLong.of(MILLISECONDS.toSeconds(timeZone.convertUTCToLocal(block.getLong(0, 0))));
}

From source file:org.cleverbus.common.Tools.java

License:Apache License

/**
 * Converts UTC instant of {@link DateTime} to local instant of {@link DateTime} with default time zone.
 *
 * @param utcTime the UTC time/*from   ww w.  jav a  2  s .  com*/
 * @return the local time
 */
public static DateTime fromUTC(DateTime utcTime) {
    DateTimeZone dateTimeZone = DateTimeZone.getDefault();
    long localTime = dateTimeZone.convertUTCToLocal(utcTime.getMillis());
    return new DateTime(localTime, dateTimeZone);
}

From source file:org.cleverbus.common.Tools.java

License:Apache License

/**
 * Converts UTC time in millis to local {@link DateTime} with default time zone.
 *
 * @param utcMillis the UTC time in millis
 * @return the local time//from ww w .j av a  2  s  .  co  m
 */
public static DateTime fromUTC(long utcMillis) {
    DateTimeZone dateTimeZone = DateTimeZone.getDefault();
    long localTime = dateTimeZone.convertUTCToLocal(utcMillis);
    return new DateTime(localTime, dateTimeZone);
}