@Override public Duration parse(String text, Locale locale) throws ParseException { return Duration.parse(text); }
@Override public Duration parse(String text, Locale locale) throws ParseException { return Duration.parse(text); }
/** * Maps {@code stringValue} to {@code Duration}. * * @param stringValue source value as a {@code String} * @return mapped {@code stringValue} to {@code Duration} * @see Duration#parse(CharSequence) */ public static Duration toDuration(String stringValue) { return Duration.parse(stringValue); }
@Nullable private Duration getDuration(Map<String, List<String>> parameters) { final List<String> durations = parameters.getOrDefault("duration", Collections.emptyList()); return durations.isEmpty() ? null : Duration.parse(durations.get(0)); }
private static long parseDelayAsLong(String value) throws RuntimeException { if (value.length() > 1 && (isP(value.charAt(0)) || isP(value.charAt(1)))) { return Duration.parse(value).toMillis(); } return Long.parseLong(value); }
@Override public Duration parse(String value, ChronoUnit unit) { try { return Duration.parse(value); } catch (Exception ex) { throw new IllegalArgumentException( "'" + value + "' is not a valid ISO-8601 duration", ex); } }
@Override protected Duration deserialize(String key, DeserializationContext ctxt) throws IOException { try { return Duration.parse(key); } catch (DateTimeException e) { return _handleDateTimeException(ctxt, Duration.class, e, key); } } }
private static long parseDelayAsLong(String value) throws RuntimeException { if (value.length() > 1 && (isP(value.charAt(0)) || isP(value.charAt(1)))) { return Duration.parse(value).toMillis(); } return Long.parseLong(value); }
@Override public Duration deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { try { return Duration.parse(context.readValue(parser, String.class)); } catch (DateTimeParseException e) { throw new IOException(e); } } }
@Override protected Duration deserialize(String key, DeserializationContext ctxt) throws IOException { try { return Duration.parse(key); } catch (DateTimeException e) { return _handleDateTimeException(ctxt, Duration.class, e, key); } } }
private Duration toDuration(String duration) { return Duration.parse(duration); } }
@Override public Duration convert(byte[] source) { return Duration.parse(toString(source)); } }
private Duration toDuration(String duration) { return Duration.parse(duration); }
static long stringToSeconds(String time) throws NumberFormatException, DateTimeParseException { long duration = 0; if (time.matches(INPUT_HMS_REGEX)) { String textWithoutWhitespaces = time.replaceAll(WHITESPACE_REGEX, ""); //parse input using ISO-8601 Duration format (e.g. 'PT1h30m10s') duration = Duration.parse("PT" + textWithoutWhitespaces).toMillis() / 1000; } else { String[] parts = time.split(":"); // parse from back to front, so as to accept hour:min:sec, min:sec, and sec formats for (int i = parts.length - 1, multiplier = 1; i >= 0 && multiplier <= 3600; i--, multiplier *= 60) { duration += Integer.parseInt(parts[i].trim()) * multiplier; } } return duration; } }
@Override public <X> Duration wrap(X value, WrapperOptions options) { if ( value == null ) { return null; } if ( Duration.class.isInstance( value ) ) { return (Duration) value; } if ( Long.class.isInstance( value ) ) { return Duration.ofNanos( (Long) value ); } if ( String.class.isInstance( value ) ) { return Duration.parse( (String) value ); } throw unknownWrap( value.getClass() ); } }
public static long parseDuration(String durationStr) { if (isPeriod(durationStr)) { return Duration.parse(durationStr).toMillis(); } else { return TimeUtils.parseTimeString(durationStr); } }
@Override public Duration fromString(final String str) { try { return Duration.parse(str); } catch (final DateTimeParseException ex) { final ConversionException exception = new ConversionException("Cannot parse value as duration", ex); exception.add("value", str); throw exception; } } }
@Override public Duration deserialize(JsonParser parser, DeserializationContext context) throws IOException { switch (parser.getCurrentTokenId()) { case JsonTokenId.ID_NUMBER_FLOAT: BigDecimal value = parser.getDecimalValue(); long seconds = value.longValue(); int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds); return Duration.ofSeconds(seconds, nanoseconds); case JsonTokenId.ID_NUMBER_INT: return Duration.ofSeconds(parser.getLongValue()); case JsonTokenId.ID_STRING: String string = parser.getText().trim(); if (string.length() == 0) { return null; } return Duration.parse(string); } throw context.mappingException("Expected type float, integer, or string."); } }
return Duration.parse(string); } catch (DateTimeException e) { return _handleDateTimeException(context, e, string);
Duration duration = Duration.parse(text);