Example usage for org.joda.time Period years

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

Introduction

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

Prototype

public static Period years(int years) 

Source Link

Document

Create a period with a specified number of years.

Usage

From source file:com.billing.ng.entities.BillingPeriod.java

License:Open Source License

/**
 * Returns a Joda Time <code>Period</code> representing the period of time
 * between the start of any given cycle and the Nth cycle (give as cycleNumber).
 *
 * @param cycleNumber cycle number/*from   ww  w. j  a v  a2  s.  c o  m*/
 * @return period of time
 */
public Period getPeriodOfTime(Integer cycleNumber) {
    Integer interval = cycleNumber * getInterval();

    switch (getType()) {
    case DAY:
        return Period.days(interval);
    case WEEK:
        return Period.weeks(interval);
    case MONTH:
        return Period.months(interval);
    case YEAR:
        return Period.years(interval);
    }
    return null;
}

From source file:com.netflix.iep.config.Strings.java

License:Apache License

private static Period parseAtPeriod(String amt, String unit) {
    int v = Integer.valueOf(amt);
    if (unit.equals("s") || unit.equals("second") || unit.equals("seconds"))
        return Period.seconds(v);
    if (unit.equals("m") || unit.equals("min") || unit.equals("minute") || unit.equals("minutes"))
        return Period.minutes(v);
    if (unit.equals("h") || unit.equals("hour") || unit.equals("hours"))
        return Period.hours(v);
    if (unit.equals("d") || unit.equals("day") || unit.equals("days"))
        return Period.days(v);
    if (unit.equals("w") || unit.equals("wk") || unit.equals("week") || unit.equals("weeks"))
        return Period.weeks(v);
    if (unit.equals("month") || unit.equals("months"))
        return Period.months(v);
    if (unit.equals("y") || unit.equals("year") || unit.equals("years"))
        return Period.years(v);
    throw new IllegalArgumentException("unknown unit " + unit);
}

From source file:com.serotonin.m2m2.Common.java

License:Open Source License

public static Period getPeriod(int periodType, int periods) {
    switch (periodType) {
    case TimePeriods.MILLISECONDS:
        return Period.millis(periods);
    case TimePeriods.SECONDS:
        return Period.seconds(periods);
    case TimePeriods.MINUTES:
        return Period.minutes(periods);
    case TimePeriods.HOURS:
        return Period.hours(periods);
    case TimePeriods.DAYS:
        return Period.days(periods);
    case TimePeriods.WEEKS:
        return Period.weeks(periods);
    case TimePeriods.MONTHS:
        return Period.months(periods);
    case TimePeriods.YEARS:
        return Period.years(periods);
    default:/*from   ww w .  j ava2 s  . co  m*/
        throw new ShouldNeverHappenException("Unsupported time period: " + periodType);
    }
}

From source file:de.ifgi.airbase.feeder.data.EEAMeasurementType.java

License:Open Source License

public Period getPeriod() {
    switch (this) {
    case HOUR:/*from  w w w.j  a  v a  2s . c om*/
        return Period.hours(1);
    case THREE_HOURS:
        return Period.hours(3);
    case EIGHT_HOURS:
        return Period.hours(8);
    case DAY:
    case DAY_MAX:
        return Period.days(1);
    case WEEK:
        return Period.weeks(1);
    case TWO_WEEKS:
        return Period.weeks(2);
    case FOUR_WEEKS:
        return Period.weeks(4);
    case MONTH:
        return Period.months(1);
    case THREE_MONTH:
        return Period.months(3);
    case YEAR:
        return Period.years(1);
    case VAR:
    default:
        throw new Error("Period not known");
    }
}

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

License:Apache License

private Period toPeriod(ShapeQuery query) throws DaoException {
    String value = query.getParameters().get("timeInterval.durationUnit");
    if (value == null) {
        throw new DaoException("durationUnit is not defined");
    }//w ww.  j av a 2  s .  com
    value = value.toLowerCase();
    switch (value) {

    case "second":
        return Period.seconds(1);

    case "hour":
        return Period.hours(1);

    case "day":
        return Period.days(1);

    case "week":
        return Period.weeks(1);

    case "month":
        return Period.months(1);

    case "quarter":
        return Period.months(3);

    case "year":
        return Period.years(1);

    }
    throw new DaoException("Invalid durationUnit: " + value);
}

From source file:net.sourceforge.fenixedu.presentationTier.renderers.providers.coordinator.tutor.MonthYearsProviderTutorshipManagement.java

License:Open Source License

@Override
public Object provide(Object source, Object currentValue) {

    List<String> result = new ArrayList<String>();

    ChangeTutorshipBean tutorshipBean = (ChangeTutorshipBean) source;

    Partial startMonthYear = tutorshipBean.getTutorship().getStartDate();
    startMonthYear = startMonthYear.plus(Period.years(2));

    Partial endMonthYear = startMonthYear.plus(Period.years(Tutorship.TUTORSHIP_MAX_PERIOD));

    while (startMonthYear.compareTo(endMonthYear) < 0) {
        String line = tutorshipBean.generateMonthYearOption(startMonthYear.get(DateTimeFieldType.monthOfYear()),
                startMonthYear.get(DateTimeFieldType.year()));
        result.add(line);/*from   w  w  w.j av  a  2s .co m*/

        startMonthYear = startMonthYear.plus(Period.months(1));
    }

    return result;
}

From source file:org.apache.drill.test.rowSet.RowSetUtilities.java

License:Apache License

/**
 * Ad-hoc, test-only method to set a Period from an integer. Periods are made up of
 * months and millseconds. There is no mapping from one to the other, so a period
 * requires at least two number. Still, we are given just one (typically from a test
 * data generator.) Use that int value to "spread" some value across the two kinds
 * of fields. The result has no meaning, but has the same comparison order as the
 * original ints.//from  w  w w  .jav  a2 s  . c o m
 *
 * @param writer column writer for a period column
 * @param minorType the Drill data type
 * @param value the integer value to apply
 * @throws VectorOverflowException
 */

public static Period periodFromInt(MinorType minorType, int value) {
    switch (minorType) {
    case INTERVAL:
        return Duration.millis(value).toPeriod();
    case INTERVALYEAR:
        return Period.years(value / 12).withMonths(value % 12);
    case INTERVALDAY:
        int sec = value % 60;
        value = value / 60;
        int min = value % 60;
        value = value / 60;
        return Period.days(value).withMinutes(min).withSeconds(sec);
    default:
        throw new IllegalArgumentException("Writer is not an interval: " + minorType);
    }
}

From source file:org.isisaddons.module.fakedata.dom.JodaPeriods.java

License:Apache License

@Programmatic
public Period yearsBetween(final int minYears, final int maxYears) {
    return Period.years(fake.ints().between(minYears, maxYears));
}

From source file:org.jevis.jeconfig.sample.SampleEditor.java

License:Open Source License

/**
 *
 * @param att/*from  w  w w . j  a v a  2 s  .  c o m*/
 * @param from
 * @param until
 * @param extensions
 */
private void updateSamples(final JEVisAttribute att, final DateTime from, final DateTime until,
        List<SampleEditorExtension> extensions) {
    System.out.println("update samples");
    try {
        samples.clear();

        _from = from;
        _until = until;

        if (_dataProcessor != null) {
            Options.setStartEnd(_dataProcessor, _from, _until, true, true);
            _dataProcessor.restResult();
        }

        Task aggrigate = null;
        if (_mode == AGGREGATION.None) {

        } else if (_mode == AGGREGATION.Daily) {
            aggrigate = new TaskImp();
            aggrigate.setJEVisDataSource(att.getDataSource());
            aggrigate.setID("Dynamic");
            aggrigate.setProcessor(new AggrigatorProcessor());
            aggrigate.addOption(Options.PERIOD, Period.days(1).toString());
        } else if (_mode == AGGREGATION.Monthly) {
            aggrigate = new TaskImp();
            aggrigate.setJEVisDataSource(att.getDataSource());
            aggrigate.setID("Dynamic");
            aggrigate.setProcessor(new AggrigatorProcessor());
            aggrigate.addOption(Options.PERIOD, Period.months(1).toString());
        } else if (_mode == AGGREGATION.Weekly) {
            aggrigate = new TaskImp();
            aggrigate.setJEVisDataSource(att.getDataSource());
            aggrigate.setID("Dynamic");
            aggrigate.setProcessor(new AggrigatorProcessor());
            aggrigate.addOption(Options.PERIOD, Period.weeks(1).toString());
        } else if (_mode == AGGREGATION.Yearly) {
            System.out.println("year.....  " + Period.years(1).toString());
            aggrigate = new TaskImp();
            aggrigate.setJEVisDataSource(att.getDataSource());
            aggrigate.setID("Dynamic");
            aggrigate.setProcessor(new AggrigatorProcessor());
            aggrigate.addOption(Options.PERIOD, Period.years(1).toString());
        }

        if (_dataProcessor == null) {
            if (aggrigate != null) {
                Task input = new TaskImp();
                input.setJEVisDataSource(att.getDataSource());
                input.setID("Dynamic Input");
                input.setProcessor(new InputProcessor());
                input.getOptions().put(InputProcessor.ATTRIBUTE_ID, _attribute.getName());
                input.getOptions().put(InputProcessor.OBJECT_ID, _attribute.getObject().getID() + "");
                aggrigate.setSubTasks(Arrays.asList(input));
                samples.addAll(aggrigate.getResult());
            } else {
                samples.addAll(att.getSamples(from, until));
            }

        } else {
            if (aggrigate != null) {
                aggrigate.setSubTasks(Arrays.asList(_dataProcessor));
                samples.addAll(aggrigate.getResult());
            } else {
                samples.addAll(_dataProcessor.getResult());
            }
        }

        for (SampleEditorExtension ex : extensions) {
            ex.setSamples(att, samples);
        }

        _dataChanged = true;
        _visibleExtension.update();
    } catch (JEVisException ex) {
        ex.printStackTrace();
    }
}

From source file:org.kalypso.commons.time.PeriodUtils.java

License:Open Source License

public static Period getPeriod(final int calendarField, final int amount) {
    switch (calendarField) {
    case Calendar.YEAR:
        return Period.years(amount);

    case Calendar.MONTH:
        return Period.months(amount);

    case Calendar.WEEK_OF_YEAR:
    case Calendar.WEEK_OF_MONTH:
        return Period.weeks(amount);

    case Calendar.DAY_OF_MONTH:
    case Calendar.DAY_OF_YEAR:
    case Calendar.DAY_OF_WEEK:
    case Calendar.DAY_OF_WEEK_IN_MONTH:
        return Period.days(amount);

    case Calendar.HOUR:
    case Calendar.HOUR_OF_DAY:
        return Period.hours(amount);

    case Calendar.MINUTE:
        return Period.minutes(amount);

    case Calendar.SECOND:
        return Period.seconds(amount);

    case Calendar.MILLISECOND:
        return Period.millis(amount);

    case Calendar.AM_PM:
    case Calendar.ERA:
    default:/*from w ww  . j av a 2  s.co  m*/
        throw new UnsupportedOperationException();
    }
}