private DateTimeFormatter applyLocale(DateTimeFormatter dateTimeFormatter) { return dateTimeFormatter.withLocale(Locale.US); }
/** * Output the date using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @param locale Locale to use, null means default * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern, Locale locale) throws IllegalArgumentException { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); }
/** * Obtain a DateTimeFormatter with user-specific settings applied to the given base Formatter. * @param formatter the base formatter that establishes default formatting rules * (generally user independent) * @param locale the current user locale (may be {@code null} if not known) * @return the user-specific DateTimeFormatter */ public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, @Nullable Locale locale) { DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter); JodaTimeContext context = getJodaTimeContext(); return (context != null ? context.getFormatter(formatterToUse) : formatterToUse); }
/** * Output the date using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @param locale Locale to use, null means default * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern, Locale locale) throws IllegalArgumentException { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); }
/** * Output the date using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @param locale Locale to use, null means default * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern, Locale locale) throws IllegalArgumentException { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); }
/** * Output the time using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @param locale Locale to use, null means default * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern, Locale locale) throws IllegalArgumentException { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); }
/** * Output the year-month using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @param locale Locale to use, null means default * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern, Locale locale) throws IllegalArgumentException { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); }
/** * Output the instant using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @param locale Locale to use, null means default * @return the formatted string, not null * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern, Locale locale) throws IllegalArgumentException { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); }
/** * Output the month-day using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @param locale Locale to use, null means default * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern, Locale locale) throws IllegalArgumentException { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); }
/** * Output the month-day using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @param locale Locale to use, null means default * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern, Locale locale) throws IllegalArgumentException { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); }
/** * Output the time using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @param locale Locale to use, null means default * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern, Locale locale) throws IllegalArgumentException { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); }
/** * Output the date using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @param locale Locale to use, null means default * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern, Locale locale) throws IllegalArgumentException { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); }
/** * Output the date using the specified format pattern. * * @param pattern the pattern specification, null means use <code>toString</code> * @param locale Locale to use, null means default * @see org.joda.time.format.DateTimeFormat */ public String toString(String pattern, Locale locale) throws IllegalArgumentException { if (pattern == null) { return toString(); } return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); }
/** * Obtain a DateTimeFormatter with user-specific settings applied to the given base Formatter. * @param formatter the base formatter that establishes default formatting rules * (generally user independent) * @param locale the current user locale (may be {@code null} if not known) * @return the user-specific DateTimeFormatter */ public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, @Nullable Locale locale) { DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter); JodaTimeContext context = getJodaTimeContext(); return (context != null ? context.getFormatter(formatterToUse) : formatterToUse); }
private static Slice dateFormat(ISOChronology chronology, Locale locale, long timestamp, Slice formatString) { DateTimeFormatter formatter = DATETIME_FORMATTER_CACHE.get(formatString) .withChronology(chronology) .withLocale(locale); return utf8Slice(formatter.print(timestamp)); }
private static Slice formatDatetime(ISOChronology chronology, Locale locale, long timestamp, Slice formatString) { try { return utf8Slice(DateTimeFormat.forPattern(formatString.toStringUtf8()) .withChronology(chronology) .withLocale(locale) .print(timestamp)); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e); } }
public CustomDateTimeJsonFieldDecoder(DecoderColumnHandle columnHandle) { this.columnHandle = requireNonNull(columnHandle, "columnHandle is null"); if (!SUPPORTED_TYPES.contains(columnHandle.getType())) { throwUnsupportedColumnType(columnHandle); } checkArgument(columnHandle.getFormatHint() != null, "format hint not defined for column '%s'", columnHandle.getName()); try { formatter = DateTimeFormat.forPattern(columnHandle.getFormatHint()).withLocale(Locale.ENGLISH).withZoneUTC(); } catch (IllegalArgumentException e) { throw new PrestoException( GENERIC_USER_ERROR, format("invalid joda pattern '%s' passed as format hint for column '%s'", columnHandle.getFormatHint(), columnHandle.getName())); } }
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))); }
@Description("parses the specified date/time by the given format") @ScalarFunction @LiteralParameters({"x", "y"}) @SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) public static long parseDatetime(ConnectorSession session, @SqlType("varchar(x)") Slice datetime, @SqlType("varchar(y)") Slice formatString) { try { return packDateTimeWithZone(parseDateTimeHelper( DateTimeFormat.forPattern(formatString.toStringUtf8()) .withChronology(getChronology(session.getTimeZoneKey())) .withOffsetParsed() .withLocale(session.getLocale()), datetime.toStringUtf8())); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e); } }
@ScalarFunction @LiteralParameters({"x", "y"}) @SqlType(StandardTypes.TIMESTAMP) public static long dateParse(ConnectorSession session, @SqlType("varchar(x)") Slice dateTime, @SqlType("varchar(y)") Slice formatString) { DateTimeFormatter formatter = DATETIME_FORMATTER_CACHE.get(formatString) .withChronology(session.isLegacyTimestamp() ? getChronology(session.getTimeZoneKey()) : UTC_CHRONOLOGY) .withLocale(session.getLocale()); try { return formatter.parseMillis(dateTime.toStringUtf8()); } catch (IllegalArgumentException e) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e); } }