Example usage for org.joda.time.format PeriodParser parseInto

List of usage examples for org.joda.time.format PeriodParser parseInto

Introduction

In this page you can find the example usage for org.joda.time.format PeriodParser parseInto.

Prototype

int parseInto(ReadWritablePeriod period, String periodStr, int position, Locale locale);

Source Link

Document

Parses a period from the given text, at the given position, saving the result into the fields of the given ReadWritablePeriod.

Usage

From source file:org.apache.tamaya.jodatime.PeriodConverter.java

License:Apache License

@Override
public Period convert(String value, ConversionContext context) {
    String trimmed = Objects.requireNonNull(value).trim();

    context.addSupportedFormats(PeriodConverter.class, "PyYmMwWdDThHmMsS");
    context.addSupportedFormats(PeriodConverter.class, "Pyyyy-mm-ddThh:mm:ss");

    MutablePeriod result = null;/*  w w w  .ja va 2  s.com*/
    PeriodParser format = null;

    if (isISOFormat(trimmed)) {
        format = ISO_FORMAT;
    } else if (isAlternativeFormat(trimmed)) {
        format = ALTERNATIVE_FORMAT;
    }

    if (format != null) {
        result = new MutablePeriod();
        int parseResult = format.parseInto(result, trimmed, 0, Locale.ENGLISH);

        if (parseResult < 0) {
            result = null;
        }
    }

    return result != null ? result.toPeriod() : null;
}