List of usage examples for org.joda.time Duration parse
@FromString public static Duration parse(String str)
From source file:org.apache.tamaya.jodatime.DurationConverter.java
License:Apache License
@Override public Duration convert(String value, ConversionContext context) { String trimmed = Objects.requireNonNull(value).trim(); context.addSupportedFormats(getClass(), "PTa.bS"); context.addSupportedFormats(getClass(), "PdDThHmMsS"); context.addSupportedFormats(getClass(), "ddThh:mm:ss"); try {//from w w w. ja v a 2s .c o m return Duration.parse(value); } catch (Exception e) { ConversionContext subContext = new ConversionContext.Builder(context.getConfiguration(), context.getKey(), context.getTargetType()).setValues(context.getValues()).build(); Period period = null; if (value.startsWith("P")) { period = periodConverter.convert("P0Y0M0W" + value.substring(1), subContext); } if (period == null) { period = periodConverter.convert("P0000-00-" + value, subContext); } if (period != null) { return period.toStandardDuration(); } } return null; }
From source file:org.apereo.portal.spring.properties.ReadableDurationEditor.java
License:Apache License
@Override public void setAsText(String text) throws IllegalArgumentException { this.setValue(Duration.parse(text)); }
From source file:org.celeria.minecraft.backup.ConfigurationModule.java
License:Apache License
@Provides @Singleton/* w ww. j ava 2 s . c o m*/ public Duration provideDurationToKeepBackups(final Configuration configuration) { final String durationToKeepBackups = getProperty(configuration, ConfigurationKey.DURATION_TO_KEEP_BACKUPS); return Duration.parse(durationToKeepBackups); }
From source file:org.n52.iceland.config.spring.converter.DurationConverter.java
License:Apache License
@Override public Duration convert(String source) { return Duration.parse(source); }
From source file:org.springframework.format.datetime.joda.DurationFormatter.java
License:Apache License
@Override public Duration parse(String text, Locale locale) throws ParseException { return Duration.parse(text); }
From source file:org.supercsv.cellprocessor.joda.ParseDuration.java
License:Apache License
/** * {@inheritDoc}//from w w w . j av a 2 s . co m * * @throws SuperCsvCellProcessorException * if value is null or is not a String */ public Object execute(final Object value, final CsvContext context) { validateInputNotNull(value, context); if (!(value instanceof String)) { throw new SuperCsvCellProcessorException(String.class, value, context, this); } final Duration result; try { result = Duration.parse((String) value); } catch (IllegalArgumentException e) { throw new SuperCsvCellProcessorException("Failed to parse value as a Duration", context, this, e); } return next.execute(result, context); }