Java Code Examples for org.joda.time.ReadWritablePeriod#clear()

The following examples show how to use org.joda.time.ReadWritablePeriod#clear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringConverter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Extracts duration values from an object of this converter's type, and
 * sets them into the given ReadWritableDuration.
 *
 * @param period  period to get modified
 * @param object  the String to convert, must not be null
 * @param chrono  the chronology to use
 * @return the millisecond duration
 * @throws ClassCastException if the object is invalid
 */
public void setInto(ReadWritablePeriod period, Object object, Chronology chrono) {
    String str = (String) object;
    PeriodFormatter parser = ISOPeriodFormat.standard();
    period.clear();
    int pos = parser.parseInto(period, str, 0);
    if (pos < str.length()) {
        if (pos < 0) {
            // Parse again to get a better exception thrown.
            parser.withParseType(period.getPeriodType()).parseMutablePeriod(str);
        }
        throw new IllegalArgumentException("Invalid format: \"" + str + '"');
    }
}
 
Example 2
Source File: StringConverter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Extracts duration values from an object of this converter's type, and
 * sets them into the given ReadWritableDuration.
 *
 * @param period  period to get modified
 * @param object  the String to convert, must not be null
 * @param chrono  the chronology to use
 * @return the millisecond duration
 * @throws ClassCastException if the object is invalid
 */
public void setInto(ReadWritablePeriod period, Object object, Chronology chrono) {
    String str = (String) object;
    PeriodFormatter parser = ISOPeriodFormat.standard();
    period.clear();
    int pos = parser.parseInto(period, str, 0);
    if (pos < str.length()) {
        if (pos < 0) {
            // Parse again to get a better exception thrown.
            parser.withParseType(period.getPeriodType()).parseMutablePeriod(str);
        }
        throw new IllegalArgumentException("Invalid format: \"" + str + '"');
    }
}