Example usage for org.joda.time Period getFieldTypes

List of usage examples for org.joda.time Period getFieldTypes

Introduction

In this page you can find the example usage for org.joda.time Period getFieldTypes.

Prototype

public DurationFieldType[] getFieldTypes() 

Source Link

Document

Gets an array of the field types that this period supports.

Usage

From source file:ee.ut.soras.test_ajavt.KiiruseTestiTulemus.java

License:Open Source License

private String convertToOtherFields(double timeInMills) {
    Period p = new Period((long) timeInMills, PeriodType.millis());
    p = p.normalizedStandard();//from w w  w.j a  v a 2 s. c om
    DurationFieldType[] fieldTypes = p.getFieldTypes();
    int[] values = p.getValues();
    if (values.length == fieldTypes.length) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < values.length; i++) {
            if (values[i] != 0) {
                sb.append(values[i] + " " + fieldTypes[i].getName() + " ");
            }
        }
        return sb.toString();
    }
    return p.toString();
}

From source file:io.prestosql.util.DateTimeUtils.java

License:Apache License

private static Period parsePeriod(PeriodFormatter periodFormatter, String value) {
    boolean negative = value.startsWith("-");
    if (negative) {
        value = value.substring(1);/*from w  w  w. j a  v a  2 s  .c o  m*/
    }

    Period period = periodFormatter.parsePeriod(value);
    for (DurationFieldType type : period.getFieldTypes()) {
        checkArgument(period.get(type) >= 0, "Period field %s is negative", type);
    }

    if (negative) {
        period = period.negated();
    }
    return period;
}