Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions core/trino-main/src/main/java/io/trino/util/DateTimeZoneIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.util;

import io.airlift.log.Logger;
import io.trino.spi.type.DateTimeEncoding;
import io.trino.spi.type.TimeZoneKey;
import org.joda.time.DateTime;
Expand All @@ -26,6 +27,8 @@

public final class DateTimeZoneIndex
{
private static final Logger log = Logger.get(DateTimeZoneIndex.class);

private DateTimeZoneIndex() {}

private static final DateTimeZone[] DATE_TIME_ZONES;
Expand All @@ -38,18 +41,25 @@ private DateTimeZoneIndex() {}
DATE_TIME_ZONES = new DateTimeZone[MAX_TIME_ZONE_KEY + 1];
CHRONOLOGIES = new ISOChronology[MAX_TIME_ZONE_KEY + 1];
FIXED_ZONE_OFFSET = new int[MAX_TIME_ZONE_KEY + 1];
for (TimeZoneKey timeZoneKey : getTimeZoneKeys()) {
short zoneKey = timeZoneKey.getKey();
DateTimeZone dateTimeZone = DateTimeZone.forID(timeZoneKey.getId());
DATE_TIME_ZONES[zoneKey] = dateTimeZone;
CHRONOLOGIES[zoneKey] = ISOChronology.getInstance(dateTimeZone);
if (dateTimeZone.isFixed() && dateTimeZone.getOffset(0) % 60_000 == 0) {
FIXED_ZONE_OFFSET[zoneKey] = dateTimeZone.getOffset(0) / 60_000;
}
else {
FIXED_ZONE_OFFSET[zoneKey] = VARIABLE_ZONE;
try {
for (TimeZoneKey timeZoneKey : getTimeZoneKeys()) {
short zoneKey = timeZoneKey.getKey();
DateTimeZone dateTimeZone = DateTimeZone.forID(timeZoneKey.getId());
DATE_TIME_ZONES[zoneKey] = dateTimeZone;
CHRONOLOGIES[zoneKey] = ISOChronology.getInstance(dateTimeZone);
if (dateTimeZone.isFixed() && dateTimeZone.getOffset(0) % 60_000 == 0) {
FIXED_ZONE_OFFSET[zoneKey] = dateTimeZone.getOffset(0) / 60_000;
}
else {
FIXED_ZONE_OFFSET[zoneKey] = VARIABLE_ZONE;
}
}
}
catch (Exception e) {
// log static initializer failure to ensure it's visible
log.error(e, "DateTimeZoneIndex initialization failed");
throw e;
}
}

public static ISOChronology getChronology(TimeZoneKey zoneKey)
Expand Down