Example usage for org.joda.time Period getDays

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

Introduction

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

Prototype

public int getDays() 

Source Link

Document

Gets the days field part of the period.

Usage

From source file:io.druid.sql.calcite.expression.builtin.TimeFloorOperatorConversion.java

License:Apache License

private static boolean periodIsDayMultiple(final Period period) {
    return period.getMillis() == 0 && period.getSeconds() == 0 && period.getMinutes() == 0
            && period.getHours() == 0 && (period.getDays() > 0 || period.getWeeks() > 0
                    || period.getMonths() > 0 || period.getYears() > 0);
}

From source file:io.konig.dao.core.ChartWriterFactory.java

License:Apache License

private Formatter categoryFormatter(Chart chart) {

    ChartCategories categories = chart.getCategories();
    if (categories instanceof DateTimeCategories) {
        String pattern = null;/*from  www.  j  a  v a 2 s.  c om*/
        DateTimeCategories c = (DateTimeCategories) categories;
        Period period = c.getInterval();

        if (period.getHours() > 0) {
            pattern = HOUR;
        } else if (period.getDays() > 0) {
            pattern = DATE;
        } else if (period.getMonths() > 0) {
            pattern = MONTH;
        } else if (period.getYears() > 0) {
            pattern = YEAR;
        } else {
            throw new RuntimeException("Unsupported period: " + period.toString());
        }
        return new TemporalFormatter(DateTimeFormat.forPattern(pattern));
    }
    if (categories instanceof LabelCategories) {
        return new Formatter() {
            @Override
            public String format(Object value) {
                return (String) value;
            }
        };
    }
    // TODO: support other categories
    throw new RuntimeException("Category type not supported");

}

From source file:it.f2informatica.webapp.utils.PeriodParser.java

License:Apache License

private String appendDays(Period period) {
    int days = period.getDays();
    if (days <= 0) {
        return " " + String.valueOf(days) + " " + getMessage("global.days");
    }/*from   ww w .j  av a2s .  c  o  m*/
    return " " + String.valueOf(days) + " "
            + ((days == 1) ? getMessage("global.day") : getMessage("global.days"));
}

From source file:net.longfalcon.newsj.Backfill.java

License:Open Source License

private int daysOld(DateTime then) {
    DateTime now = DateTime.now();// w w w. j  a  v a 2  s.c  o m
    if (then == null || then.isAfter(now)) {
        return 0;
    } else {
        Period period = new Period(then, now);
        return period.getDays();
    }
}

From source file:net.longfalcon.view.DateView.java

License:Open Source License

public Period roundPeriod(Period period) {
    int fieldCount = 0;
    int years = period.getYears();
    int months = period.getMonths();
    int weeks = period.getWeeks();
    int days = period.getDays();
    int hours = period.getHours();
    int minutes = period.getMinutes();
    int seconds = period.getSeconds();
    if (years > 0) {
        fieldCount++;//from www .  jav  a2  s  .  co  m
    }
    if (months > 0) {
        fieldCount++;
    }

    if (fieldCount > 1) {
        return new Period(years, months, 0, 0, 0, 0, 0, 0);
    }

    if (weeks > 0) {
        fieldCount++;
    }

    if (fieldCount > 1) {
        return new Period(0, months, weeks, 0, 0, 0, 0, 0);
    }

    if (days > 0) {
        fieldCount++;
    }

    if (fieldCount > 1) {
        return new Period(0, 0, weeks, days, 0, 0, 0, 0);
    }

    if (hours > 0) {
        fieldCount++;
    }

    if (fieldCount > 1) {
        return new Period(0, 0, 0, days, hours, 0, 0, 0);
    }

    if (minutes > 0) {
        fieldCount++;
    }

    if (fieldCount > 1) {
        return new Period(0, 0, 0, 0, hours, minutes, 0, 0);
    }

    return new Period(0, 0, 0, 0, 0, minutes, seconds, 0);
}

From source file:net.objectlab.kit.datecalc.joda.LocalDatePeriodCountCalculator.java

License:Apache License

public int dayDiff(final LocalDate start, final LocalDate end, final PeriodCountBasis basis) {
    int diff = 0;

    switch (basis) {
    case CONV_30_360:
        diff = diffConv30v360(start, end);
        break;//ww  w  .  j  a  v  a2s.  c  o  m

    case CONV_360E_ISDA:
        diff = diff360EIsda(start, end);
        break;

    case CONV_360E_ISMA:
        diff = diff360EIsma(start, end);
        break;
    default:
        final Period p = new Period(start, end, PeriodType.days());
        diff = p.getDays();
    }

    return diff;
}

From source file:nz.co.gregs.dbvolution.databases.definitions.DBDefinition.java

License:Apache License

/**
 * Creates a string representation of a DateRepeat from the Period
 *
 * @param interval the interval to be transformed into a DateRepeat.
 * @return a DateRpeat as an SQL string/*from  www . jav a  2  s  .c o  m*/
 */
public String transformPeriodIntoDateRepeat(Period interval) {
    StringBuilder str = new StringBuilder();
    str.append("'").append(DateRepeatExpression.INTERVAL_PREFIX);
    str.append(interval.getYears()).append(DateRepeatExpression.YEAR_SUFFIX);
    str.append(interval.getMonths()).append(DateRepeatExpression.MONTH_SUFFIX);
    str.append(interval.getDays() + (interval.getWeeks() * 7)).append(DateRepeatExpression.DAY_SUFFIX);
    str.append(interval.getHours()).append(DateRepeatExpression.HOUR_SUFFIX);
    str.append(interval.getMinutes()).append(DateRepeatExpression.MINUTE_SUFFIX);
    str.append(interval.getSeconds()).append(DateRepeatExpression.SECOND_SUFFIX);
    str.append("'");
    return str.toString();
}

From source file:nz.co.gregs.dbvolution.internal.datatypes.DateRepeatImpl.java

License:Apache License

/**
 *
 * @param interval/*from w w  w  . j a v  a 2s.  c  o  m*/
 * @return the DateRepeat equivalent of the Period value
 */
public static String getDateRepeatString(Period interval) {
    if (interval == null) {
        return null;
    }
    int years = interval.getYears();
    int months = interval.getMonths();
    int days = interval.getDays() + interval.getWeeks() * 7;
    int hours = interval.getHours();
    int minutes = interval.getMinutes();

    int millis = interval.getMillis();
    double seconds = interval.getSeconds() + (millis / 1000.0);
    String intervalString = "P" + years + "Y" + months + "M" + days + "D" + hours + "h" + minutes + "n"
            + seconds + "s";
    return intervalString;
}

From source file:org.alfresco.util.DateUtil.java

License:Open Source License

/**
 * Calculate the number of days between start and end dates based on the <b>default</b> timezone.
 * If the end date is before the start date, the returned value is negative.
 *
 * @param startMs start date in milliseconds
 * @param endMs   end date in milliseconds
 * @return number days between//from w w  w. j  a  v a  2 s  .c  o  m
 */
public static int calculateDays(long startMs, long endMs) {
    DateTime startDateTime = new DateTime(startMs).withTimeAtStartOfDay();
    DateTime endDateTime = new DateTime(endMs).withTimeAtStartOfDay();

    int days;
    if (endDateTime.isBefore(startDateTime)) {
        Interval interval = new Interval(endDateTime, startDateTime);
        Period period = interval.toPeriod(PeriodType.days());
        days = 0 - period.getDays();
    } else {
        Interval interval = new Interval(startDateTime, endDateTime);
        Period period = interval.toPeriod(PeriodType.days());
        days = period.getDays();
    }
    return days;
}

From source file:org.apache.drill.exec.vector.DateUtilities.java

License:Apache License

public static StringBuilder intervalDayStringBuilder(Period value) {
    return intervalDayStringBuilder(value.getDays(), periodToMillis(value));
}