private Object readResolve() throws ObjectStreamException { return forID(iID); } }
private Object readResolve() throws ObjectStreamException { return forID(iID); } }
private static void put(Map<String, DateTimeZone> map, String name, String id) { try { map.put(name, DateTimeZone.forID(id)); } catch (RuntimeException ex) { // ignore } } //-------------------------------------------------------------------------
private static void put(Map<String, DateTimeZone> map, String name, String id) { try { map.put(name, DateTimeZone.forID(id)); } catch (RuntimeException ex) { // ignore } } //-------------------------------------------------------------------------
private static DateTimeZone buildTimeZone(Object timeZoneId) { if (timeZoneId instanceof String) { try { final String timeZoneString = (String) timeZoneId; final String zoneId = firstNonNull(emptyToNull(timeZoneString.trim()), "Etc/UTC"); return DateTimeZone.forID(zoneId); } catch (IllegalArgumentException e) { return DEFAULT_TIME_ZONE; } } else { return DEFAULT_TIME_ZONE; } }
@Override public void setTimeZone(final String timeZone) { DateTimeZone dateTimeZone = null; if (timeZone != null) { try { dateTimeZone = DateTimeZone.forID(timeZone); } catch (IllegalArgumentException e) { LOG.error("Invalid timezone \"{}\", falling back to UTC.", timeZone); } } setTimeZone(dateTimeZone); }
@Override public DateTimeZone getTimeZone() { final Object o = fields.get(TIMEZONE); try { if (o != null) { return DateTimeZone.forID(o.toString()); } } catch (IllegalArgumentException e) { LOG.warn("Invalid timezone \"{}\" saved for user \"{}\"", o, getName()); } return null; }
@SuppressForbidden(reason = "DateTimeZone#forID") public static DateTimeZone inferTzFromString(String tzId) { try { return DateTimeZone.forID(tzId); } catch (IllegalArgumentException e) { // also support Java timezone strings return DateTimeZone.forTimeZone(TimeZone.getTimeZone(tzId)); } }
public static void setTimezone(String tz) { Set<String> idSet = DateTimeZone.getAvailableIDs(); if(idSet.contains(tz)) _timezone = DateTimeZone.forID(tz); else Log.err("Attempted to set unrecognized timezone: "+ tz); }
@Override protected DateTime evaluate(FunctionArgs args, EvaluationContext context, DateTimeZone timezone) { final Object datish = value.required(args, context); if (datish instanceof DateTime) { return (DateTime) datish; } if (datish instanceof Date) { return new DateTime(datish); } if (datish instanceof ZonedDateTime) { final ZonedDateTime zonedDateTime = (ZonedDateTime) datish; final DateTimeZone timeZone = DateTimeZone.forID(zonedDateTime.getZone().getId()); return new DateTime(zonedDateTime.toInstant().toEpochMilli(), timeZone); } return null; }
public static void assertDateTimeZoneEquals(String zoneId, DateTimeZone actualTimeZone) { DateTimeZone expectedDateTimeZone; if (isUtcZoneId(zoneId)) { expectedDateTimeZone = DateTimeZone.UTC; } else { expectedDateTimeZone = DateTimeZone.forID(zoneId); } assertEquals(actualTimeZone, expectedDateTimeZone); } }
@AssistedInject public CEFCodec(@Assisted Configuration configuration) { this.configuration = configuration; this.parser = CEFParserFactory.create(); DateTimeZone timezone; try { timezone = DateTimeZone.forID(configuration.getString(CK_TIMEZONE)); } catch (Exception e) { LOG.warn("Could not configure CEF input timezone. Falling back to local default. Please check the error message:", e); timezone = DEFAULT_TIMEZONE; } this.timezone = timezone; this.locale = Locale.forLanguageTag(configuration.getString(CK_LOCALE, "")); this.useFullNames = configuration.getBoolean(CK_USE_FULL_NAMES); }
protected TimezoneAwareFunction() { timeZoneParam = ParameterDescriptor .string(TIMEZONE, DateTimeZone.class) .transform(id -> DateTimeZone.forID(UPPER_ZONE_MAP.getOrDefault(id.toUpperCase(Locale.ENGLISH), "UTC"))) .optional() .description("The timezone to apply to the date, defaults to UTC") .build(); }
@Test public void testFromUnixTimeWithTimeZone() { String zoneId = "Asia/Shanghai"; DateTime expected = new DateTime(1970, 1, 1, 10, 0, 0, DateTimeZone.forID(zoneId)); assertFunction(format("from_unixtime(7200, '%s')", zoneId), TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(expected)); zoneId = "Asia/Tokyo"; expected = new DateTime(1970, 1, 1, 11, 0, 0, DateTimeZone.forID(zoneId)); assertFunction(format("from_unixtime(7200, '%s')", zoneId), TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(expected)); zoneId = "Europe/Moscow"; expected = new DateTime(1970, 1, 1, 5, 0, 0, DateTimeZone.forID(zoneId)); assertFunction(format("from_unixtime(7200, '%s')", zoneId), TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(expected)); zoneId = "America/New_York"; expected = new DateTime(1969, 12, 31, 21, 0, 0, DateTimeZone.forID(zoneId)); assertFunction(format("from_unixtime(7200, '%s')", zoneId), TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(expected)); zoneId = "America/Chicago"; expected = new DateTime(1969, 12, 31, 20, 0, 0, DateTimeZone.forID(zoneId)); assertFunction(format("from_unixtime(7200, '%s')", zoneId), TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(expected)); zoneId = "America/Los_Angeles"; expected = new DateTime(1969, 12, 31, 18, 0, 0, DateTimeZone.forID(zoneId)); assertFunction(format("from_unixtime(7200, '%s')", zoneId), TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(expected)); }
static DateTimeZone nonDefaultTimeZone() { String defaultId = DateTimeZone.getDefault().getID(); for (String id : DateTimeZone.getAvailableIDs()) { if (!id.equals(defaultId)) { DateTimeZone zone = DateTimeZone.forID(id); if (zone.getStandardOffset(0) != 0) { return zone; } } } throw new IllegalStateException("no non-default timezone"); } }
@Test public void testParseDatetime() { assertFunction("parse_datetime('1960/01/22 03:04', 'YYYY/MM/DD HH:mm')", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(new DateTime(1960, 1, 22, 3, 4, 0, 0, DATE_TIME_ZONE))); assertFunction("parse_datetime('1960/01/22 03:04 Asia/Oral', 'YYYY/MM/DD HH:mm ZZZZZ')", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(new DateTime(1960, 1, 22, 3, 4, 0, 0, DateTimeZone.forID("Asia/Oral")))); assertFunction("parse_datetime('1960/01/22 03:04 +0500', 'YYYY/MM/DD HH:mm Z')", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(new DateTime(1960, 1, 22, 3, 4, 0, 0, DateTimeZone.forOffsetHours(5)))); }
@Override public FormatWriter createFileFormatWriter( ConnectorSession session, File targetFile, List<String> columnNames, List<Type> columnTypes, HiveCompressionCodec compressionCodec) throws IOException { return new PrestoDwrfFormatWriter( targetFile, columnNames, columnTypes, DateTimeZone.forID(session.getTimeZoneKey().getId()), compressionCodec); }
@Override public FormatWriter createFileFormatWriter( ConnectorSession session, File targetFile, List<String> columnNames, List<Type> columnTypes, HiveCompressionCodec compressionCodec) throws IOException { return new PrestoOrcFormatWriter( targetFile, columnNames, columnTypes, DateTimeZone.forID(session.getTimeZoneKey().getId()), compressionCodec); } },
@Override public FormatWriter createFileFormatWriter( ConnectorSession session, File targetFile, List<String> columnNames, List<Type> columnTypes, HiveCompressionCodec compressionCodec) throws IOException { return new PrestoRcFileFormatWriter( targetFile, columnTypes, new TextRcFileEncoding(DateTimeZone.forID(session.getTimeZoneKey().getId())), compressionCodec); } },
private void setup(JodaTimeFormatterRegistrar registrar) { conversionService = new FormattingConversionService(); DefaultConversionService.addDefaultConverters(conversionService); registrar.registerFormatters(conversionService); JodaTimeBean bean = new JodaTimeBean(); bean.getChildren().add(new JodaTimeBean()); binder = new DataBinder(bean); binder.setConversionService(conversionService); LocaleContextHolder.setLocale(Locale.US); JodaTimeContext context = new JodaTimeContext(); context.setTimeZone(DateTimeZone.forID("-05:00")); JodaTimeContextHolder.setJodaTimeContext(context); }