Strings { public static Duration asDuration(String timeString) { if (timeString == null) { return null; } Matcher matcher = TIME_PATTERN.matcher(timeString); if (!matcher.matches()) { throw new RuntimeException("Unexpected format for TIME column: " + timeString); } long hours = Long.parseLong(matcher.group(1)); long minutes = Long.parseLong(matcher.group(2)); long seconds = Long.parseLong(matcher.group(3)); long nanoSeconds = 0; String microSecondsString = matcher.group(5); if (microSecondsString != null) { nanoSeconds = Long.parseLong(Strings.justifyLeft(microSecondsString, 9, '0')); } if (hours >= 0) { return Duration.ofHours(hours) .plusMinutes(minutes) .plusSeconds(seconds) .plusNanos(nanoSeconds); } else { return Duration.ofHours(hours) .minusMinutes(minutes) .minusSeconds(seconds) .minusNanos(nanoSeconds); } } private  Strings(); static Set<T> setOf(String input, Function<String, String[]> splitter, Function<String, T> factory); static List<T> listOf(String input, Function<String, String[]> splitter, Function<String, T> factory); static Set<T> setOf(String input, char delimiter, Function<String, T> factory); static Set<T> setOf(String input, Function<String, T> factory); static Set<Pattern> setOfRegex(String input, int regexFlags); static Set<Pattern> setOfRegex(String input); static List<Pattern> listOfRegex(String input, int regexFlags); static List<String> splitLines(final String content); static int compareTo(CharSequence str1, CharSequence str2); static boolean equalsIgnoreCase(String str1, String str2); static String join(CharSequence delimiter, int[] values); static String join(CharSequence delimiter, Iterable<T> values); static String join(CharSequence delimiter, Iterable<T> values, Function<T, String> conversion); static String trim(String str); static String trim(String str, CharacterPredicate predicate); static String createString(final char charToRepeat,
                                      int numberOfRepeats); static String pad(String original,
                             int length,
                             char padChar); static String setLength(String original,
                                   int length,
                                   char padChar); static String justify(Justify justify,
                                 String str,
                                 final int width,
                                 char padWithChar); static String justifyRight(String str,
                                      final int width,
                                      char padWithChar); static String justifyLeft(String str,
                                     final int width,
                                     char padWithChar); static String justifyCenter(String str,
                                       final int width,
                                       char padWithChar); static String getStackTrace(Throwable throwable); static Number asNumber(String value); static Number asNumber(String value, Supplier<Number> defaultValueProvider); static int asInt(String value, int defaultValue); static long asLong(String value, long defaultValue); static double asDouble(String value, double defaultValue); static boolean asBoolean(String value, boolean defaultValue); static Duration asDuration(String timeString); static String duration(long durationInMillis); static Function<String, String> replaceVariablesWith(Function<String, String> replacementsByVariableName); static String replaceVariables(String value, Function<String, String> replacementsByVariableName); static boolean isUuid(String str); static boolean isNullOrEmpty(String str); static boolean isNumeric(String str); static String unquoteIdentifierPart(String identifierPart); static byte[] hexStringToByteArray(String hexString); static boolean startsWithIgnoreCase(String str, String prefix); static String getBegin(String str, int length);  }
@Test @FixFor("DBZ-1164") public void asDurationShouldConvertValue() { assertThat(Strings.asDuration(null)).isNull(); assertThat(Strings.asDuration("24:00:00")).isEqualTo(Duration.parse("PT24H")); assertThat(Strings.asDuration("18:02:54.123")).isEqualTo(Duration.parse("PT18H2M54.123S")); assertThat(Strings.asDuration("18:02:54.123456789")).isEqualTo(Duration.parse("PT18H2M54.123456789S")); assertThat(Strings.asDuration("24:00:01")).isEqualTo(Duration.parse("PT24H1S")); }