private static DateFormat getFormatter(boolean includeMillis) { UtcTimeOnlyConverter converter = UTC_TIME_CONVERTER.get(); if (converter == null) { converter = new UtcTimeOnlyConverter(); UTC_TIME_CONVERTER.set(converter); } return includeMillis ? converter.utcTimeFormatMillis : converter.utcTimeFormat; }
/** * Convert between a String and a time * * @param value the string to parse * @return a date object representing the time * @throws FieldConvertError raised for invalid time string */ public static Date convert(String value) throws FieldConvertError { Date d = null; assertLength(value, TYPE, LENGTH_INCL_SECONDS, LENGTH_INCL_MILLIS, LENGTH_INCL_MICROS, LENGTH_INCL_NANOS, LENGTH_INCL_PICOS); try { final boolean includeMillis = (value.length() >= LENGTH_INCL_MILLIS); d = getFormatter(includeMillis).parse(includeMillis ? value.substring(0, LENGTH_INCL_MILLIS) : value); } catch (ParseException e) { throwFieldConvertError(value, TYPE); } return d; }
public static LocalTime convertToLocalTime(String value) throws FieldConvertError { assertLength(value, TYPE, LENGTH_INCL_SECONDS, LENGTH_INCL_MILLIS, LENGTH_INCL_MICROS, LENGTH_INCL_NANOS, LENGTH_INCL_PICOS); try { int length = value.length(); switch (length) { case LENGTH_INCL_SECONDS: return LocalTime.parse(value, FORMATTER_SECONDS); case LENGTH_INCL_MILLIS: return LocalTime.parse(value, FORMATTER_MILLIS); case LENGTH_INCL_MICROS: return LocalTime.parse(value, FORMATTER_MICROS); case LENGTH_INCL_NANOS: return LocalTime.parse(value, FORMATTER_NANOS); case LENGTH_INCL_PICOS: return LocalTime.parse(value.substring(0, LENGTH_INCL_NANOS), FORMATTER_NANOS); default: throwFieldConvertError(value, TYPE); } } catch (DateTimeParseException e) { throwFieldConvertError(value, TYPE); } return null; }
/** * Convert between a String and a time * * @param value the string to parse * @return a date object representing the time * @throws FieldConvertError raised for invalid time string */ public static Date convert(String value) throws FieldConvertError { Date d = null; if (value.length() != LENGTH_INCL_SECONDS && value.length() != LENGTH_INCL_MILLIS && value.length() != LENGTH_INCL_MICROS && value.length() != LENGTH_INCL_NANOS && value.length() != LENGTH_INCL_PICOS) { throwFieldConvertError(value, "time"); } try { final boolean includeMillis = (value.length() >= LENGTH_INCL_MILLIS); d = getFormatter(includeMillis).parse(includeMillis ? value.substring(0, LENGTH_INCL_MILLIS) : value); } catch (ParseException e) { throwFieldConvertError(value, "time"); } return d; }
public void setUtcTimeOnly(int field, LocalTime value, boolean includeMilliseconds) { setField(new StringField(field, UtcTimeOnlyConverter.convert(value, includeMilliseconds ? UtcTimestampPrecision.MILLIS : UtcTimestampPrecision.SECONDS))); }
/** * Convert a time (represented as a Date) to a String (HH:MM:SS or HH:MM:SS.SSS) * * @param d the date with the time to convert * @param includeMilliseconds controls whether milliseconds are included in the result * @return a String representing the time. */ public static String convert(Date d, boolean includeMilliseconds) { return getFormatter(includeMilliseconds).format(d); }
public LocalTime getUtcTimeOnly(int field) throws FieldNotFound { try { return UtcTimeOnlyConverter.convertToLocalTime(getString(field)); } catch (final FieldConvertError e) { throw newIncorrectDataException(e, field); } }
public Date getUtcTimeOnly(int field) throws FieldNotFound { try { return UtcTimeOnlyConverter.convert(getString(field)); } catch (final FieldConvertError e) { throw newIncorrectDataException(e, field); } }
public static LocalTime convertToLocalTime(String value) throws FieldConvertError { assertLength(value, TYPE, LENGTH_INCL_SECONDS, LENGTH_INCL_MILLIS, LENGTH_INCL_MICROS, LENGTH_INCL_NANOS, LENGTH_INCL_PICOS); try { int length = value.length(); switch (length) { case LENGTH_INCL_SECONDS: return LocalTime.parse(value, FORMATTER_SECONDS); case LENGTH_INCL_MILLIS: return LocalTime.parse(value, FORMATTER_MILLIS); case LENGTH_INCL_MICROS: return LocalTime.parse(value, FORMATTER_MICROS); case LENGTH_INCL_NANOS: return LocalTime.parse(value, FORMATTER_NANOS); case LENGTH_INCL_PICOS: return LocalTime.parse(value.substring(0, LENGTH_INCL_NANOS), FORMATTER_NANOS); default: throwFieldConvertError(value, TYPE); } } catch (DateTimeParseException e) { throwFieldConvertError(value, TYPE); } return null; }
/** * Convert a time (represented as a Date) to a String (HH:MM:SS or HH:MM:SS.SSS) * * @param d the date with the time to convert * @param includeMilliseconds controls whether milliseconds are included in the result * @return a String representing the time. */ public static String convert(Date d, boolean includeMilliseconds) { return getFormatter(includeMilliseconds).format(d); }
public LocalTime getUtcTimeOnly(int field) throws FieldNotFound { try { return UtcTimeOnlyConverter.convertToLocalTime(getString(field)); } catch (final FieldConvertError e) { throw newIncorrectDataException(e, field); } }
/** * Convert between a String and a time * * @param value the string to parse * @return a date object representing the time * @throws FieldConvertError raised for invalid time string */ public static Date convert(String value) throws FieldConvertError { Date d = null; assertLength(value, TYPE, LENGTH_INCL_SECONDS, LENGTH_INCL_MILLIS, LENGTH_INCL_MICROS, LENGTH_INCL_NANOS, LENGTH_INCL_PICOS); try { final boolean includeMillis = (value.length() >= LENGTH_INCL_MILLIS); d = getFormatter(includeMillis).parse(includeMillis ? value.substring(0, LENGTH_INCL_MILLIS) : value); } catch (ParseException e) { throwFieldConvertError(value, TYPE); } return d; }
public void setUtcTimeOnly(int field, LocalTime value, UtcTimestampPrecision precision) { setField(new StringField(field, UtcTimeOnlyConverter.convert(value, precision))); }
private static DateFormat getFormatter(boolean includeMillis) { UtcTimeOnlyConverter converter = UTC_TIME_CONVERTER.get(); if (converter == null) { converter = new UtcTimeOnlyConverter(); UTC_TIME_CONVERTER.set(converter); } return includeMillis ? converter.utcTimeFormatMillis : converter.utcTimeFormat; }
/** * Convert a time (represented as a Date) to a String (HH:MM:SS or HH:MM:SS.SSS) * * @param d the date with the time to convert * @param includeMilliseconds controls whether milliseconds are included in the result * @return a String representing the time. */ public static String convert(Date d, boolean includeMilliseconds) { return getFormatter(includeMilliseconds).format(d); }
public void setUtcTimeOnly(int field, LocalTime value, UtcTimestampPrecision precision) { setField(new StringField(field, UtcTimeOnlyConverter.convert(value, precision))); }
private static DateFormat getFormatter(boolean includeMillis) { UtcTimeOnlyConverter converter = UTC_TIME_CONVERTER.get(); if (converter == null) { converter = new UtcTimeOnlyConverter(); UTC_TIME_CONVERTER.set(converter); } return includeMillis ? converter.utcTimeFormatMillis : converter.utcTimeFormat; }
public void setUtcTimeOnly(int field, LocalTime value, boolean includeMilliseconds) { setField(new StringField(field, UtcTimeOnlyConverter.convert(value, includeMilliseconds ? UtcTimestampPrecision.MILLIS : UtcTimestampPrecision.SECONDS))); }
public void setUtcTimeOnly(int field, Date value, boolean includeMillseconds) { setField(new StringField(field, UtcTimeOnlyConverter.convert(value, includeMillseconds))); }
break; case UTCTIMEONLY: UtcTimeOnlyConverter.convert(field.getValue()); break; case UTCTIMESTAMP: