List of usage examples for org.joda.time Period negated
public Period negated()
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 ww. 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; }
From source file:mobi.daytoday.DayToDay.DateWrap.java
License:Apache License
/** * Find the difference between the two dates and express it in natural * language/*w ww . j av a 2 s . c om*/ * * @param dateOne * - date in DATE_FORMAT format * @param dateTwo * - date in DATE_FORMAT format * @return time between the two given dates in natural terms * @throws Exception * - if there is any error */ public static String naturalInterval(String dateOne, String dateTwo) throws Exception { DateTime firstDate = dtForm.parseDateTime(dateOne); DateTime secondDate = dtForm.parseDateTime(dateTwo); Period period = new Period(firstDate, secondDate); PeriodFormatter formatter = new PeriodFormatterBuilder().appendYears().appendSuffix(" year ", " years ") .appendMonths().appendSuffix(" month ", " months ").appendWeeks().appendSuffix(" week ", " weeks ") .appendDays().appendSuffix(" day", " days").printZeroNever().toFormatter(); if (formatter.print(period).matches(".*-.*")) { return formatter.print(period.negated()); } return formatter.print(period); }