Example usage for org.joda.time Duration toPeriodFrom

List of usage examples for org.joda.time Duration toPeriodFrom

Introduction

In this page you can find the example usage for org.joda.time Duration toPeriodFrom.

Prototype

public Period toPeriodFrom(ReadableInstant startInstant) 

Source Link

Document

Converts this duration to a Period instance by adding the duration to a start instant to obtain an interval using the standard period type.

Usage

From source file:org.openehr.rm.datatypes.quantity.datetime.DvDuration.java

License:LGPL

/**
 * Create a Duration from two instances of DvWorldTime
 *
 * @param start//w ww . j ava2s.  co m
 * @param end
 */
public static DvDuration getDifference(DvTemporal start, DvTemporal end) {
    Duration d = new Duration(start.getDateTime(), end.getDateTime());
    DvDateTime dt = (DvDateTime) end;
    return new DvDuration(null, null, null, 0.0, false, null, d.toPeriodFrom(start.getDateTime()));
}

From source file:org.openehr.rm.datatypes.quantity.datetime.DvDuration.java

License:LGPL

/**
 * Sum of this quantity and another whose formal type must be the difference
 * type of this quantity.//from w  ww.  j  a  v a2  s  .co  m
 * 
 * @param q
 * @return production of addition
 * @throws ClassCastException
 */
@Override
public DvQuantified<DvDuration> add(DvQuantified q) {
    final DvDuration d = (DvDuration) q;

    DateTime dt = new DateTime(0);
    Duration duration = period.toDurationFrom(dt);
    Duration result = duration.plus(d.period.toDurationFrom(dt));
    Period p = result.toPeriodFrom(dt);

    return new DvDuration(d.getOtherReferenceRanges(), d.getNormalRange(), d.getNormalStatus(), d.getAccuracy(),
            d.isAccuracyPercent(), d.getMagnitudeStatus(), p);
}

From source file:org.openehr.rm.datatypes.quantity.datetime.DvDuration.java

License:LGPL

/**
 * Difference of this quantity and another whose formal type must be the
 * difference type of this quantity type.
 * /*from  w w w  . ja  v  a  2  s  .com*/
 * @param q
 * @return product of substraction
 * @throws ClassCastException
 */
@Override
public DvQuantified<DvDuration> subtract(DvQuantified q) {
    final DvDuration d = (DvDuration) q;

    DateTime dt = new DateTime(0);
    Duration duration = period.toDurationFrom(dt);
    Duration result = duration.minus(d.period.toDurationFrom(dt));
    Period p = result.toPeriodFrom(dt);

    return new DvDuration(d.getOtherReferenceRanges(), d.getNormalRange(), d.getNormalStatus(), d.getAccuracy(),
            d.isAccuracyPercent(), d.getMagnitudeStatus(), p);
}