public static DateTimeZone getDateTimeZone(TimeZoneKey zoneKey) { return DATE_TIME_ZONES[zoneKey.getKey()]; }
public static ISOChronology getChronology(TimeZoneKey zoneKey) { return CHRONOLOGIES[zoneKey.getKey()]; }
public static DateTimeZone getDateTimeZone(TimeZoneKey zoneKey) { return DATE_TIME_ZONES[zoneKey.getKey()]; }
public static ISOChronology getChronology(TimeZoneKey zoneKey) { return CHRONOLOGIES[zoneKey.getKey()]; }
public static long packDateTimeWithZone(long millisUtc, TimeZoneKey timeZoneKey) { requireNonNull(timeZoneKey, "timeZoneKey is null"); return pack(millisUtc, timeZoneKey.getKey()); }
@Test public void testMaxTimeZoneKey() { boolean foundMax = false; for (TimeZoneKey timeZoneKey : TimeZoneKey.getTimeZoneKeys()) { assertTrue(timeZoneKey.getKey() <= MAX_TIME_ZONE_KEY, timeZoneKey + " key is larger than max key " + MAX_TIME_ZONE_KEY); foundMax = foundMax || (timeZoneKey.getKey() == MAX_TIME_ZONE_KEY); } assertTrue(foundMax, "Did not find a time zone with the MAX_TIME_ZONE_KEY"); }
@Test public void testMaxTimeZoneKey() { boolean foundMax = false; for (TimeZoneKey timeZoneKey : TimeZoneKey.getTimeZoneKeys()) { assertTrue(timeZoneKey.getKey() <= MAX_TIME_ZONE_KEY, timeZoneKey + " key is larger than max key " + MAX_TIME_ZONE_KEY); foundMax = foundMax || (timeZoneKey.getKey() == MAX_TIME_ZONE_KEY); } assertTrue(foundMax, "Did not find a time zone with the MAX_TIME_ZONE_KEY"); }
@Test public void testZoneKeyIdRange() { boolean[] hasValue = new boolean[MAX_TIME_ZONE_KEY + 1]; for (TimeZoneKey timeZoneKey : TimeZoneKey.getTimeZoneKeys()) { short key = timeZoneKey.getKey(); assertTrue(key >= 0, timeZoneKey + " has a negative time zone key"); assertFalse(hasValue[key], "Another time zone has the same zone key as " + timeZoneKey); hasValue[key] = true; } // previous spot for Canada/East-Saskatchewan assertFalse(hasValue[2040]); hasValue[2040] = true; // previous spot for EST assertFalse(hasValue[2180]); hasValue[2180] = true; // previous spot for HST assertFalse(hasValue[2186]); hasValue[2186] = true; // previous spot for MST assertFalse(hasValue[2196]); hasValue[2196] = true; for (int i = 0; i < hasValue.length; i++) { assertTrue(hasValue[i], "There is no time zone with key " + i); } }
@Test public void testZoneKeyIdRange() { boolean[] hasValue = new boolean[MAX_TIME_ZONE_KEY + 1]; for (TimeZoneKey timeZoneKey : TimeZoneKey.getTimeZoneKeys()) { short key = timeZoneKey.getKey(); assertTrue(key >= 0, timeZoneKey + " has a negative time zone key"); assertFalse(hasValue[key], "Another time zone has the same zone key as " + timeZoneKey); hasValue[key] = true; } // previous spot for Canada/East-Saskatchewan assertFalse(hasValue[2040]); hasValue[2040] = true; // previous spot for EST assertFalse(hasValue[2180]); hasValue[2180] = true; // previous spot for HST assertFalse(hasValue[2186]); hasValue[2186] = true; // previous spot for MST assertFalse(hasValue[2196]); hasValue[2196] = true; for (int i = 0; i < hasValue.length; i++) { assertTrue(hasValue[i], "There is no time zone with key " + i); } }
private static long parseMillis(TimeZoneKey timeZoneKey, Locale locale, Slice dateTime, Slice formatString) { DateTimeFormatter formatter = DATETIME_FORMATTER_CACHE.get(formatString) .withChronology(CHRONOLOGIES[timeZoneKey.getKey()]) .withLocale(locale); try { return formatter.parseMillis(dateTime.toString(UTF_8)); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e); } } }
@Test public void testZoneKeyData() { Hasher hasher = Hashing.murmur3_128().newHasher(); SortedSet<TimeZoneKey> timeZoneKeysSortedByKey = ImmutableSortedSet.copyOf(new Comparator<TimeZoneKey>() { @Override public int compare(TimeZoneKey left, TimeZoneKey right) { return Short.compare(left.getKey(), right.getKey()); } }, TimeZoneKey.getTimeZoneKeys()); for (TimeZoneKey timeZoneKey : timeZoneKeysSortedByKey) { hasher.putShort(timeZoneKey.getKey()); hasher.putString(timeZoneKey.getId(), StandardCharsets.UTF_8); } // Zone file should not (normally) be changed, so let's make this more difficult assertEquals(hasher.hash().asLong(), -4582158485614614451L, "zone-index.properties file contents changed!"); }
@Test public void testZoneKeyData() { Hasher hasher = Hashing.murmur3_128().newHasher(); SortedSet<TimeZoneKey> timeZoneKeysSortedByKey = ImmutableSortedSet.copyOf(new Comparator<TimeZoneKey>() { @Override public int compare(TimeZoneKey left, TimeZoneKey right) { return Short.compare(left.getKey(), right.getKey()); } }, TimeZoneKey.getTimeZoneKeys()); for (TimeZoneKey timeZoneKey : timeZoneKeysSortedByKey) { hasher.putShort(timeZoneKey.getKey()); hasher.putString(timeZoneKey.getId(), StandardCharsets.UTF_8); } // Zone file should not (normally) be changed, so let's make this more difficult assertEquals(hasher.hash().asLong(), -4582158485614614451L, "zone-index.properties file contents changed!"); }
@Description("Formats a timestamp") @ScalarFunction("to_char") @SqlType(StandardTypes.VARCHAR) public static Slice toChar( ConnectorSession session, @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone, @SqlType(StandardTypes.VARCHAR) Slice formatString) { DateTimeFormatter formatter = DATETIME_FORMATTER_CACHE.get(formatString) .withChronology(CHRONOLOGIES[unpackZoneKey(timestampWithTimeZone).getKey()]) .withLocale(session.getLocale()); return utf8Slice(formatter.print(unpackMillisUtc(timestampWithTimeZone))); }
@Test public void testZoneKeyLookup() { for (TimeZoneKey timeZoneKey : TimeZoneKey.getTimeZoneKeys()) { assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getKey()), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId()), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId().toUpperCase(ENGLISH)), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId().toLowerCase(ENGLISH)), timeZoneKey); } }
@Test public void testZoneKeyLookup() { for (TimeZoneKey timeZoneKey : TimeZoneKey.getTimeZoneKeys()) { assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getKey()), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId()), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId().toUpperCase(ENGLISH)), timeZoneKey); assertSame(TimeZoneKey.getTimeZoneKey(timeZoneKey.getId().toLowerCase(ENGLISH)), timeZoneKey); } }
@Test public void testUTC() assertEquals(UTC_KEY.getKey(), 0); assertEquals(UTC_KEY.getId(), "UTC");
@Test public void testUTC() assertEquals(UTC_KEY.getKey(), 0); assertEquals(UTC_KEY.getId(), "UTC");