Search in sources :

Example 1 with ScaledDurationField

use of org.joda.time.field.ScaledDurationField in project CoreNLP by stanfordnlp.

the class JodaTimeUtils method getJodaTimePeriod.

protected static Period getJodaTimePeriod(Partial p) {
    if (p.size() > 0) {
        DateTimeFieldType dtType = p.getFieldType(p.size() - 1);
        DurationFieldType dType = dtType.getDurationType();
        Period period = new Period();
        if (period.isSupported(dType)) {
            return period.withField(dType, 1);
        } else {
            DurationField df = dType.getField(p.getChronology());
            if (df instanceof ScaledDurationField) {
                ScaledDurationField sdf = (ScaledDurationField) df;
                return period.withField(sdf.getWrappedField().getType(), sdf.getScalar());
            }
        // PeriodType.forFields(new DurationFieldType[]{dType});
        // return new Period(df.getUnitMillis(), PeriodType.forFields(new DurationFieldType[]{dType}));
        }
    }
    return null;
}
Also used : ScaledDurationField(org.joda.time.field.ScaledDurationField) DurationFieldType(org.joda.time.DurationFieldType) DateTimeFieldType(org.joda.time.DateTimeFieldType) ScaledDurationField(org.joda.time.field.ScaledDurationField)

Aggregations

DateTimeFieldType (org.joda.time.DateTimeFieldType)1 DurationFieldType (org.joda.time.DurationFieldType)1 ScaledDurationField (org.joda.time.field.ScaledDurationField)1