use of org.joda.time.DurationFieldType in project joda-time by JodaOrg.
the class BasePeriod method mergePeriodInto.
/**
* Merges the fields from another period.
*
* @param values the array of values to update
* @param period the period to add from, not null
* @return the updated values
* @throws IllegalArgumentException if an unsupported field's value is non-zero
*/
protected int[] mergePeriodInto(int[] values, ReadablePeriod period) {
for (int i = 0, isize = period.size(); i < isize; i++) {
DurationFieldType type = period.getFieldType(i);
int value = period.getValue(i);
checkAndUpdate(type, values, value);
}
return values;
}
use of org.joda.time.DurationFieldType in project joda-time by JodaOrg.
the class BasePeriod method setPeriodInternal.
/**
* Private method called from constructor.
*/
private void setPeriodInternal(ReadablePeriod period) {
int[] newValues = new int[size()];
for (int i = 0, isize = period.size(); i < isize; i++) {
DurationFieldType type = period.getFieldType(i);
int value = period.getValue(i);
checkAndUpdate(type, newValues, value);
}
setValues(newValues);
}
use of org.joda.time.DurationFieldType in project h2o-3 by h2oai.
the class PrettyPrint method toAge.
public static String toAge(Date from, Date to) {
if (from == null || to == null)
return "N/A";
final Period period = new Period(from.getTime(), to.getTime());
DurationFieldType[] dtf = new ArrayList<DurationFieldType>() {
{
add(DurationFieldType.years());
add(DurationFieldType.months());
add(DurationFieldType.days());
if (period.getYears() == 0 && period.getMonths() == 0 && period.getDays() == 0) {
add(DurationFieldType.hours());
add(DurationFieldType.minutes());
}
}
}.toArray(new DurationFieldType[0]);
PeriodFormatter pf = PeriodFormat.getDefault();
return pf.print(period.normalizedStandard(PeriodType.forFields(dtf)));
}
use of org.joda.time.DurationFieldType in project presto by prestodb.
the class DateTimeUtils method parsePeriod.
private static Period parsePeriod(PeriodFormatter periodFormatter, String value) {
boolean negative = value.startsWith("-");
if (negative) {
value = value.substring(1);
}
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;
}
use of org.joda.time.DurationFieldType in project CoreNLP by stanfordnlp.
the class JodaTimeUtils method isMoreGeneral.
// Returns if df1 is more general than df2
public static boolean isMoreGeneral(DateTimeFieldType df1, DateTimeFieldType df2, Chronology chronology) {
DurationFieldType df1DurationFieldType = df1.getDurationType();
DurationFieldType df2DurationFieldType = df2.getDurationType();
if (!df2DurationFieldType.equals(df1DurationFieldType)) {
DurationField df1Unit = df1DurationFieldType.getField(chronology);
DurationFieldType p = df2.getRangeDurationType();
if (p != null) {
DurationField df2Unit = df2DurationFieldType.getField(chronology);
int cmp = df1Unit.compareTo(df2Unit);
if (cmp > 0) {
return true;
}
}
}
return false;
}
Aggregations