Skip to content

Commit

Permalink
Account for zone offset in record decoder TIME WITH TIME ZONE decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesjmorgan authored and losipiuk committed Sep 14, 2020
1 parent 05b1226 commit 456e1fa
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.prestosql.spi.type.TimeZoneKey;
import io.prestosql.spi.type.Type;

import java.time.Instant;
import java.util.concurrent.TimeUnit;

import static io.prestosql.decoder.DecoderErrorCode.DECODER_CONVERSION_NOT_SUPPORTED;
Expand All @@ -31,6 +32,7 @@
import static io.prestosql.spi.type.TimestampType.TIMESTAMP_MILLIS;
import static io.prestosql.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS;
import static io.prestosql.spi.type.Timestamps.MICROSECONDS_PER_MILLISECOND;
import static io.prestosql.spi.type.Timestamps.MILLISECONDS_PER_SECOND;
import static io.prestosql.spi.type.Timestamps.NANOSECONDS_PER_MILLISECOND;
import static io.prestosql.spi.type.Timestamps.PICOSECONDS_PER_MILLISECOND;
import static java.lang.String.format;
Expand Down Expand Up @@ -81,7 +83,8 @@ public final long getLong()
return packDateTimeWithZone(millis, getTimeZone());
}
if (type.equals(TIME_WITH_TIME_ZONE)) {
return packTimeWithTimeZone(millis * NANOSECONDS_PER_MILLISECOND, 0);
int offsetMinutes = getTimeZone().getZoneId().getRules().getOffset(Instant.ofEpochMilli(millis)).getTotalSeconds() / 60;
return packTimeWithTimeZone((millis + (offsetMinutes * 60 * MILLISECONDS_PER_SECOND)) * NANOSECONDS_PER_MILLISECOND, offsetMinutes);
}

throw new IllegalStateException("Unsupported type: " + type);
Expand Down

0 comments on commit 456e1fa

Please sign in to comment.