Example usage for org.joda.time.chrono ISOChronology getZone

List of usage examples for org.joda.time.chrono ISOChronology getZone

Introduction

In this page you can find the example usage for org.joda.time.chrono ISOChronology getZone.

Prototype

public DateTimeZone getZone() 

Source Link

Usage

From source file:com.facebook.presto.type.DateOperators.java

License:Apache License

@ScalarOperator(CAST)
@SqlType(TimestampType.class)
public static long castToTimestamp(ConnectorSession session, @SqlType(DateType.class) long value) {
    // date is encoded as milliseconds at midnight in UTC
    // convert to midnight if the session timezone
    ISOChronology chronology = getChronology(session.getTimeZoneKey());
    return value - chronology.getZone().getOffset(value);
}

From source file:com.facebook.presto.type.DateOperators.java

License:Apache License

@ScalarOperator(CAST)
@SqlType(TimestampWithTimeZoneType.class)
public static long castToTimestampWithTimeZone(ConnectorSession session, @SqlType(DateType.class) long value) {
    // date is encoded as milliseconds at midnight in UTC
    // convert to midnight if the session timezone
    ISOChronology chronology = getChronology(session.getTimeZoneKey());
    long millis = value - chronology.getZone().getOffset(value);
    return packDateTimeWithZone(millis, session.getTimeZoneKey());
}

From source file:com.facebook.presto.type.DateTimeOperators.java

License:Apache License

public static int modulo24Hour(ISOChronology chronology, long millis) {
    return chronology.millisOfDay().get(millis) - chronology.getZone().getOffset(millis);
}

From source file:com.facebook.presto.type.TimeOperators.java

License:Apache License

@ScalarOperator(CAST)
@SqlType(StandardTypes.TIME_WITH_TIME_ZONE)
public static long castToTimeWithTimeZone(ConnectorSession session, @SqlType(StandardTypes.TIME) long value) {
    if (session.isLegacyTimestamp()) {
        return packDateTimeWithZone(value, session.getTimeZoneKey());
    } else {/*from  w  ww  . j a v a 2s  .co  m*/
        ISOChronology localChronology = getChronology(session.getTimeZoneKey());

        // This cast does treat TIME as wall time in session TZ. This means that in order to get
        // its UTC representation we need to shift the value by the offset of TZ.
        // We use value offset in this place to be sure that we will have same hour represented
        // in TIME WITH TIME ZONE. Calculating real TZ offset will happen when really required.
        // This is done due to inadequate TIME WITH TIME ZONE representation.
        return packDateTimeWithZone(localChronology.getZone().convertLocalToUTC(value, false),
                session.getTimeZoneKey());
    }
}

From source file:com.facebook.presto.type.TimestampOperators.java

License:Apache License

@ScalarOperator(CAST)
@SqlType(DateType.class)
public static long castToDate(ConnectorSession session, @SqlType(TimestampType.class) long value) {
    // round down the current timestamp to days
    ISOChronology chronology = getChronology(session.getTimeZoneKey());
    long date = chronology.dayOfYear().roundFloor(value);
    // date is currently midnight in timezone of the session
    // convert to UTC
    return date + chronology.getZone().getOffset(date);
}

From source file:com.facebook.presto.type.TimestampWithTimeZoneOperators.java

License:Apache License

@ScalarOperator(CAST)
@SqlType(DateType.class)
public static long castToDate(@SqlType(TimestampWithTimeZoneType.class) long value) {
    // round down the current timestamp to days
    ISOChronology chronology = unpackChronology(value);
    long date = chronology.dayOfYear().roundFloor(unpackMillisUtc(value));
    // date is currently midnight in timezone of the original value
    // convert to UTC
    return date + chronology.getZone().getOffset(date);
}

From source file:com.facebook.presto.type.TimeWithTimeZoneOperators.java

License:Apache License

@ScalarOperator(CAST)
@SqlType(StandardTypes.TIMESTAMP)/*from   w ww . ja  va 2  s. c  om*/
public static long castToTimestamp(ConnectorSession session,
        @SqlType(StandardTypes.TIME_WITH_TIME_ZONE) long value) {
    if (session.isLegacyTimestamp()) {
        return unpackMillisUtc(value);
    } else {
        // This is hack that we need to use as the timezone interpretation depends on date (not only on time)
        // TODO remove REFERENCE_TIMESTAMP_UTC when removing support for political time zones in TIME WIT TIME ZONE
        long currentMillisOfDay = ChronoField.MILLI_OF_DAY
                .getFrom(Instant.ofEpochMilli(REFERENCE_TIMESTAMP_UTC).atZone(ZoneOffset.UTC));
        long timeMillisUtcInCurrentDay = REFERENCE_TIMESTAMP_UTC - currentMillisOfDay + unpackMillisUtc(value);

        ISOChronology chronology = getChronology(unpackZoneKey(value));
        return unpackMillisUtc(value) + chronology.getZone().getOffset(timeMillisUtcInCurrentDay);
    }
}

From source file:io.prestosql.operator.scalar.DateTimeFunctions.java

License:Apache License

@Description("current timestamp without time zone")
@ScalarFunction("localtimestamp")
@SqlType(StandardTypes.TIMESTAMP)//from   w w  w . j  ava  2 s  .  co m
public static long localTimestamp(ConnectorSession session) {
    if (session.isLegacyTimestamp()) {
        return session.getStartTime();
    }
    ISOChronology localChronology = getChronology(session.getTimeZoneKey());
    return localChronology.getZone().convertUTCToLocal(session.getStartTime());
}

From source file:io.prestosql.type.DateOperators.java

License:Apache License

@ScalarOperator(CAST)
@SqlType(StandardTypes.TIMESTAMP)/*from w ww  . j  a v  a  2 s  .  c o  m*/
public static long castToTimestamp(ConnectorSession session, @SqlType(StandardTypes.DATE) long value) {
    if (session.isLegacyTimestamp()) {
        long utcMillis = TimeUnit.DAYS.toMillis(value);

        // date is encoded as milliseconds at midnight in UTC
        // convert to midnight in the session timezone
        ISOChronology chronology = getChronology(session.getTimeZoneKey());
        return utcMillis - chronology.getZone().getOffset(utcMillis);
    } else {
        return TimeUnit.DAYS.toMillis(value);
    }
}

From source file:io.prestosql.type.DateOperators.java

License:Apache License

@ScalarOperator(CAST)
@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE)
public static long castToTimestampWithTimeZone(ConnectorSession session,
        @SqlType(StandardTypes.DATE) long value) {
    long utcMillis = TimeUnit.DAYS.toMillis(value);

    // date is encoded as milliseconds at midnight in UTC
    // convert to midnight in the session timezone
    ISOChronology chronology = getChronology(session.getTimeZoneKey());
    long millis = utcMillis - chronology.getZone().getOffset(utcMillis);
    return packDateTimeWithZone(millis, session.getTimeZoneKey());
}