public String getStartTime() { try { return UtcTimestampConverter.convert(session.getStartTime(), true); } catch (IOException e) { return "[ERROR]"; } }
private static DateFormat getFormatter(boolean includeMillis) { UtcTimestampConverter converter = UTC_TIMESTAMP_CONVERTER.get(); if (converter == null) { converter = new UtcTimestampConverter(); UTC_TIMESTAMP_CONVERTER.set(converter); } return includeMillis ? converter.utcTimestampFormatMillis : converter.utcTimestampFormat; }
private static void verifyFormat(String value) throws FieldConvertError { assertLength(value, TYPE, LENGTH_INCL_SECONDS, LENGTH_INCL_MILLIS, LENGTH_INCL_MICROS, LENGTH_INCL_NANOS, LENGTH_INCL_PICOS); assertDigitSequence(value, 0, 8, TYPE); assertSeparator(value, 8, '-', TYPE); assertDigitSequence(value, 9, 11, TYPE); assertSeparator(value, 11, ':', TYPE); assertDigitSequence(value, 12, 14, TYPE); assertSeparator(value, 14, ':', TYPE); assertDigitSequence(value, 15, LENGTH_INCL_SECONDS, TYPE); if (value.length() == LENGTH_INCL_MILLIS) { assertSeparator(value, LENGTH_INCL_SECONDS, '.', TYPE); assertDigitSequence(value, 18, LENGTH_INCL_MILLIS, TYPE); } else if (value.length() == LENGTH_INCL_MICROS) { assertSeparator(value, LENGTH_INCL_SECONDS, '.', TYPE); assertDigitSequence(value, 18, LENGTH_INCL_MICROS, TYPE); } else if (value.length() == LENGTH_INCL_NANOS) { assertSeparator(value, LENGTH_INCL_SECONDS, '.', TYPE); assertDigitSequence(value, 18, LENGTH_INCL_NANOS, TYPE); } else if (value.length() == LENGTH_INCL_PICOS) { assertSeparator(value, LENGTH_INCL_SECONDS, '.', TYPE); assertDigitSequence(value, 18, LENGTH_INCL_PICOS, TYPE); } else if (value.length() != LENGTH_INCL_SECONDS) { throwFieldConvertError(value, TYPE); } }
/** * Convert a timestamp string into a Date. * Date has up to millisecond precision. * * @param value the timestamp String * @return the parsed timestamp * @exception FieldConvertError raised if timestamp is an incorrect format. */ public static Date convert(String value) throws FieldConvertError { verifyFormat(value); long timeOffset = getTimeOffsetSeconds(value); if (value.length() >= LENGTH_INCL_MILLIS) { // format has already been verified // accept up to picosenconds but parse only up to milliseconds timeOffset += parseLong(value.substring(18, LENGTH_INCL_MILLIS)); } return new Date(getMillisForDay(value) + timeOffset); }
private static void verifyFormat(String value) throws FieldConvertError { String type = "timestamp"; 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, type); } assertDigitSequence(value, 0, 8, type); assertSeparator(value, 8, '-', type); assertDigitSequence(value, 9, 11, type); assertSeparator(value, 11, ':', type); assertDigitSequence(value, 12, 14, type); assertSeparator(value, 14, ':', type); assertDigitSequence(value, 15, LENGTH_INCL_SECONDS, type); if (value.length() == LENGTH_INCL_MILLIS) { assertSeparator(value, LENGTH_INCL_SECONDS, '.', type); assertDigitSequence(value, 18, LENGTH_INCL_MILLIS, type); } else if (value.length() == LENGTH_INCL_MICROS) { assertSeparator(value, LENGTH_INCL_SECONDS, '.', type); assertDigitSequence(value, 18, LENGTH_INCL_MICROS, type); } else if (value.length() == LENGTH_INCL_NANOS) { assertSeparator(value, LENGTH_INCL_SECONDS, '.', type); assertDigitSequence(value, 18, LENGTH_INCL_NANOS, type); } else if (value.length() == LENGTH_INCL_PICOS) { assertSeparator(value, LENGTH_INCL_SECONDS, '.', type); assertDigitSequence(value, 18, LENGTH_INCL_PICOS, type); } else if (value.length() != LENGTH_INCL_SECONDS) { throwFieldConvertError(value, type); } } }
/** * Convert a timestamp string into a Date. * * @param value the timestamp String * @return the parsed timestamp * @exception FieldConvertError raised if timestamp is an incorrect format. */ public static Date convert(String value) throws FieldConvertError { verifyFormat(value); long timeOffset = (parseLong(value.substring(9, 11)) * 3600000L) + (parseLong(value.substring(12, 14)) * 60000L) + (parseLong(value.substring(15, LENGTH_INCL_SECONDS)) * 1000L); if (value.length() == LENGTH_INCL_MILLIS || value.length() == LENGTH_INCL_MICROS || value.length() == LENGTH_INCL_NANOS || value.length() == LENGTH_INCL_PICOS) { // accept up to picosenconds but parse only up to milliseconds timeOffset += parseLong(value.substring(18, LENGTH_INCL_MILLIS)); } return new Date(getMillisForDay(value) + timeOffset); }
/** * Convert a timestamp string into a LocalDateTime object. * LocalDateTime has up to nanosecond precision. * * @param value the timestamp String * @return the parsed timestamp * @exception FieldConvertError raised if timestamp is an incorrect format. */ public static LocalDateTime convertToLocalDateTime(String value) throws FieldConvertError { verifyFormat(value); int length = value.length(); try { switch (length) { case LENGTH_INCL_SECONDS: return LocalDateTime.parse(value, FORMATTER_SECONDS); case LENGTH_INCL_MILLIS: return LocalDateTime.parse(value, FORMATTER_MILLIS); case LENGTH_INCL_MICROS: return LocalDateTime.parse(value, FORMATTER_MICROS); case LENGTH_INCL_NANOS: case LENGTH_INCL_PICOS: return LocalDateTime.parse(value.substring(0, LENGTH_INCL_NANOS), FORMATTER_NANOS); default: throwFieldConvertError(value, TYPE); } } catch (DateTimeParseException e) { throwFieldConvertError(value, TYPE); } return null; }
/** * Convert a timestamp (represented as a Date) to a String. * * @param d the date to convert * @param includeMilliseconds controls whether milliseconds are included in * the result * @return the formatted timestamp */ public static String convert(Date d, boolean includeMilliseconds) { return getFormatter(includeMilliseconds).format(d); }
/** * Convert a timestamp string into a Date. * Date has up to millisecond precision. * * @param value the timestamp String * @return the parsed timestamp * @exception FieldConvertError raised if timestamp is an incorrect format. */ public static Date convert(String value) throws FieldConvertError { verifyFormat(value); long timeOffset = getTimeOffsetSeconds(value); if (value.length() >= LENGTH_INCL_MILLIS) { // format has already been verified // accept up to picosenconds but parse only up to milliseconds timeOffset += parseLong(value.substring(18, LENGTH_INCL_MILLIS)); } return new Date(getMillisForDay(value) + timeOffset); }
/** * Convert a timestamp string into a LocalDateTime object. * LocalDateTime has up to nanosecond precision. * * @param value the timestamp String * @return the parsed timestamp * @exception FieldConvertError raised if timestamp is an incorrect format. */ public static LocalDateTime convertToLocalDateTime(String value) throws FieldConvertError { verifyFormat(value); int length = value.length(); try { switch (length) { case LENGTH_INCL_SECONDS: return LocalDateTime.parse(value, FORMATTER_SECONDS); case LENGTH_INCL_MILLIS: return LocalDateTime.parse(value, FORMATTER_MILLIS); case LENGTH_INCL_MICROS: return LocalDateTime.parse(value, FORMATTER_MICROS); case LENGTH_INCL_NANOS: case LENGTH_INCL_PICOS: return LocalDateTime.parse(value.substring(0, LENGTH_INCL_NANOS), FORMATTER_NANOS); default: throwFieldConvertError(value, TYPE); } } catch (DateTimeParseException e) { throwFieldConvertError(value, TYPE); } return null; }
/** * Convert a timestamp (represented as a Date) to a String. * * @param d the date to convert * @param includeMilliseconds controls whether milliseconds are included in * the result * @return the formatted timestamp */ public static String convert(Date d, boolean includeMilliseconds) { return getFormatter(includeMilliseconds).format(d); }
private void writeTimeStamp(OutputStream out) throws IOException { String formattedTime = UtcTimestampConverter.convert(SystemTime.getDate(), includeMillis); //i18n_datetime out.write(formattedTime.getBytes()); out.write(TIME_STAMP_DELIMETER); }
private static void verifyFormat(String value) throws FieldConvertError { assertLength(value, TYPE, LENGTH_INCL_SECONDS, LENGTH_INCL_MILLIS, LENGTH_INCL_MICROS, LENGTH_INCL_NANOS, LENGTH_INCL_PICOS); assertDigitSequence(value, 0, 8, TYPE); assertSeparator(value, 8, '-', TYPE); assertDigitSequence(value, 9, 11, TYPE); assertSeparator(value, 11, ':', TYPE); assertDigitSequence(value, 12, 14, TYPE); assertSeparator(value, 14, ':', TYPE); assertDigitSequence(value, 15, LENGTH_INCL_SECONDS, TYPE); if (value.length() == LENGTH_INCL_MILLIS) { assertSeparator(value, LENGTH_INCL_SECONDS, '.', TYPE); assertDigitSequence(value, 18, LENGTH_INCL_MILLIS, TYPE); } else if (value.length() == LENGTH_INCL_MICROS) { assertSeparator(value, LENGTH_INCL_SECONDS, '.', TYPE); assertDigitSequence(value, 18, LENGTH_INCL_MICROS, TYPE); } else if (value.length() == LENGTH_INCL_NANOS) { assertSeparator(value, LENGTH_INCL_SECONDS, '.', TYPE); assertDigitSequence(value, 18, LENGTH_INCL_NANOS, TYPE); } else if (value.length() == LENGTH_INCL_PICOS) { assertSeparator(value, LENGTH_INCL_SECONDS, '.', TYPE); assertDigitSequence(value, 18, LENGTH_INCL_PICOS, TYPE); } else if (value.length() != LENGTH_INCL_SECONDS) { throwFieldConvertError(value, TYPE); } }
/** * Convert a timestamp (represented as a Date) to a String. * * @param d the date to convert * @param includeMilliseconds controls whether milliseconds are included in * the result * @return the formatted timestamp */ public static String convert(Date d, boolean includeMilliseconds) { return getFormatter(includeMilliseconds).format(d); }
private static DateFormat getFormatter(boolean includeMillis) { UtcTimestampConverter converter = UTC_TIMESTAMP_CONVERTER.get(); if (converter == null) { converter = new UtcTimestampConverter(); UTC_TIMESTAMP_CONVERTER.set(converter); } return includeMillis ? converter.utcTimestampFormatMillis : converter.utcTimestampFormat; }
private void log(String message, String type) { out.println("<" + UtcTimestampConverter.convert(SystemTime.getDate(), includeMillis) + ", " + sessionID + ", " + type + "> (" + message + ")"); }
private static DateFormat getFormatter(boolean includeMillis) { UtcTimestampConverter converter = UTC_TIMESTAMP_CONVERTER.get(); if (converter == null) { converter = new UtcTimestampConverter(); UTC_TIMESTAMP_CONVERTER.set(converter); } return includeMillis ? converter.utcTimestampFormatMillis : converter.utcTimestampFormat; }
public String getStartTime() { try { return UtcTimestampConverter.convert(session.getStartTime(), true); } catch (IOException e) { return "[ERROR]"; } }