public TimestampEncoding(Type type, Slice nullSequence, DateTimeZone hiveStorageTimeZone) { this.type = type; this.nullSequence = nullSequence; this.dateTimeFormatter = HIVE_TIMESTAMP_PARSER.withZone(hiveStorageTimeZone); }
/** * Returns a new formatter that will use the UTC zone in preference * to the zone of the printed object, or default zone on a parse. * <p> * When printing, UTC will be used in preference to the zone * from the datetime that would otherwise be used. * <p> * When parsing, UTC will be set on the parsed datetime. * <p> * If both an override chronology and an override zone are set, the * override zone will take precedence over the zone in the chronology. * * @return the new formatter, never null * @since 2.0 */ public DateTimeFormatter withZoneUTC() { return withZone(DateTimeZone.UTC); }
@Deprecated public static String printTimeWithoutTimeZone(TimeZoneKey timeZoneKey, long value) { return TIME_FORMATTER.withZone(getDateTimeZone(timeZoneKey)).print(value); }
private Patterns(String prefix, String patternString) { this.prefix = prefix; this.dateFormat = DateTimeFormat.forPattern(patternString).withZone(DateTimeZone.forID(ConfigurationKeys.PST_TIMEZONE_NAME)); } }
public static long parseHiveTimestamp(String value, DateTimeZone timeZone) { return HIVE_TIMESTAMP_PARSER.withZone(timeZone).parseMillis(value); }
/** * Parse a string (without a zone) as a value of TIME type, interpreted in {@code timeZoneKey} zone. * * @return stack representation of legacy TIME type */ @Deprecated public static long parseTimeWithoutTimeZone(TimeZoneKey timeZoneKey, String value) { return TIME_FORMATTER.withZone(getDateTimeZone(timeZoneKey)).parseMillis(value); }
public static String printTimeWithTimeZone(long timeWithTimeZone) { DateTimeZone timeZone = unpackDateTimeZone(timeWithTimeZone); long millis = unpackMillisUtc(timeWithTimeZone); return TIME_WITH_TIME_ZONE_FORMATTER.withZone(timeZone).print(millis); }
@VisibleForTesting GoogleAnalyticsUnsampledExtractor(WorkUnitState state, Extractor<S, D> actualExtractor, Analytics gaService) throws IOException { this.wuState = state; this.googleAnalyticsFormatter = DateTimeFormat.forPattern(DATE_FORMAT) .withZone(DateTimeZone.forID(state.getProp(SOURCE_TIMEZONE, DEFAULT_SOURCE_TIMEZONE))); this.watermarkFormatter = DateTimeFormat.forPattern(WATERMARK_INPUTFORMAT) .withZone(DateTimeZone.forID(state.getProp(SOURCE_TIMEZONE, DEFAULT_SOURCE_TIMEZONE))); this.actualExtractor = actualExtractor; this.gaService = gaService; this.nextWatermark = -1; }
private static long toUnixTimeMicros(Object obj, Type type, String name) { if (Number.class.isAssignableFrom(obj.getClass())) { return ((Number) obj).longValue(); } else if (obj instanceof String) { String s = (String) obj; s = s.trim().replace(' ', 'T'); long millis = ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC).parseMillis(s); return millis * 1000; } else { handleInvalidValue(name, type, obj); return 0; } }
public static void testDate() { DateTimeFormatter df = DateTimeFormat.forPattern("dd MM yyyy HH:mm:ss.SSS Z"); DateTime temp = df.withOffsetParsed().parseDateTime("30 11 2012 12:08:56.235 +0700"); DateTimeZone theZone = temp.getZone(); Date date = temp.toDate(); DateTime dateTime = new DateTime(date); DateTimeFormatter df2 = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSZZ"); DateTimeFormatter df3 = df2.withZone(theZone); System.out.println(dateTime.toString(df2)); System.out.println(dateTime.toString(df3)); }
public DateTimeFormatPatternSpec(String timeFormat, String sdfPatternWithTz) { _timeFormat = TimeFormat.valueOf(timeFormat); if (_timeFormat.equals(TimeFormat.SIMPLE_DATE_FORMAT)) { Matcher m = SDF_PATTERN_WITH_TIMEZONE.matcher(sdfPatternWithTz); _sdfPattern = sdfPatternWithTz; if (m.find()) { _sdfPattern = m.group(SDF_PATTERN_GROUP).trim(); String timezoneString = m.group(TIMEZONE_GROUP).trim(); _dateTimeZone = DateTimeZone.forTimeZone(TimeZone.getTimeZone(timezoneString)); } _dateTimeFormatter = DateTimeFormat.forPattern(_sdfPattern).withZone(_dateTimeZone); } }
/** * Get the DateTimeFormatter with the this context's settings * applied to the base {@code formatter}. * @param formatter the base formatter that establishes default * formatting rules, generally context-independent * @return the contextual DateTimeFormatter */ public DateTimeFormatter getFormatter(DateTimeFormatter formatter) { if (this.chronology != null) { formatter = formatter.withChronology(this.chronology); } if (this.timeZone != null) { formatter = formatter.withZone(this.timeZone); } else { LocaleContext localeContext = LocaleContextHolder.getLocaleContext(); if (localeContext instanceof TimeZoneAwareLocaleContext) { TimeZone timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone(); if (timeZone != null) { formatter = formatter.withZone(DateTimeZone.forTimeZone(timeZone)); } } } return formatter; }
@Override public String evaluate(FunctionArgs args, EvaluationContext context) { final DateTime dateTime = value.required(args, context); final DateTimeFormatter formatter = format.required(args, context); if (dateTime == null || formatter == null) { return null; } final DateTimeZone timeZone = timeZoneParam.optional(args, context).orElse(DateTimeZone.UTC); return formatter.withZone(timeZone).print(dateTime); }
dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone));
protected Calendar parseDate(String date) throws Exception { Calendar dateCalendar = null; try { dateCalendar = ISODateTimeFormat.dateTimeParser().withZone(DateTimeZone.forTimeZone( clockReader.getCurrentTimeZone())).parseDateTime(date).toCalendar(null); } catch (IllegalArgumentException e) { // try to parse a java.util.date to string back to a java.util.date dateCalendar = new GregorianCalendar(); DateFormat DATE_FORMAT = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy", Locale.ENGLISH); dateCalendar.setTime(DATE_FORMAT.parse(date)); } return dateCalendar; }
@Override public DateTime evaluate(FunctionArgs args, EvaluationContext context, DateTimeZone timezone) { final String dateString = valueParam.required(args, context); final String pattern = patternParam.required(args, context); final Optional<String> localeString = localeParam.optional(args, context); if (dateString == null || pattern == null) { return null; } final Locale locale = localeString.map(Locale::forLanguageTag).orElse(Locale.getDefault()); final DateTimeFormatter formatter = DateTimeFormat .forPattern(pattern) .withLocale(locale) .withZone(timezone); return formatter.parseDateTime(dateString); }
private Optional<DateTimeFormatter> getTimestampToPathFormatter(State state, int numBranches, int branchId) { String propName = ForkOperatorUtils.getPropertyNameForBranch(WRITER_PARTITION_PATTERN, numBranches, branchId); if (state.contains(propName)) { return Optional.of(DateTimeFormat.forPattern(state.getProp(propName)).withZone(this.timeZone)); } return Optional.absent(); }
@Override public Date resolveEndDate(String endDateString) { return ISODateTimeFormat.dateTimeParser().withZone(DateTimeZone.forTimeZone(clockReader.getCurrentTimeZone())).parseDateTime(endDateString).toCalendar(null).getTime(); }
private void testJodaStylePatterns(String style, Locale locale, Date date) throws Exception { DateFormatter formatter = new DateFormatter(); formatter.setTimeZone(UTC); formatter.setStylePattern(style); DateTimeFormatter jodaFormatter = DateTimeFormat.forStyle(style).withLocale(locale).withZone(DateTimeZone.UTC); String jodaPrinted = jodaFormatter.print(date.getTime()); assertThat("Unable to print style pattern " + style, formatter.print(date, locale), is(equalTo(jodaPrinted))); assertThat("Unable to parse style pattern " + style, formatter.parse(jodaPrinted, locale), is(equalTo(date))); }
public Converter(Class<T> targetType, DynamoDBTypeConvertedTimestamp annotation) { this.formatter = DateTimeFormat.forPattern(annotation.pattern()).withZone( DateTimeZone.forTimeZone(StandardTypeConverters.Scalar.TIME_ZONE.<TimeZone>convert(annotation.timeZone())) ); this.converter = StandardTypeConverters.factory().getConverter(DateTime.class, targetType); }