Example usage for org.joda.time Period plusWeeks

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

Introduction

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

Prototype

public Period plusWeeks(int weeks) 

Source Link

Document

Returns a new period plus the specified number of weeks added.

Usage

From source file:nl.mpcjanssen.simpletask.util.Util.java

License:Open Source License

public static DateTime addInterval(DateTime date, String interval) {
    Pattern p = Pattern.compile("(\\d+)([dwmy])");
    Matcher m = p.matcher(interval.toLowerCase());
    int amount;// w  w  w.ja va  2  s. c om
    String type;
    if (date == null) {
        date = new DateTime();
    }
    m.find();
    if (m.groupCount() == 2) {
        amount = Integer.parseInt(m.group(1));
        type = m.group(2).toLowerCase();
    } else {
        return null;
    }
    Period period = new Period(0);
    if (type.equals("d")) {
        period = period.plusDays(amount);
    } else if (type.equals("w")) {
        period = period.plusWeeks(amount);
    } else if (type.equals("m")) {
        period = period.plusMonths(amount);
    } else if (type.equals("y")) {
        period = period.plusYears(amount);
    }
    return date.plus(period);
}

From source file:org.jevis.application.unit.SampleRateNode.java

License:Open Source License

private void setPeriod(TextField field) {
    Period newPeriod = Period.ZERO;

    if (sliderMinutes.getValue() != 0) {
        newPeriod = newPeriod.plusMinutes((int) sliderMinutes.getValue());
    }//from  www . ja  v a 2s . c  o m
    if (sliderSecounds.getValue() != 0) {
        newPeriod = newPeriod.plusSeconds((int) sliderSecounds.getValue());
    }
    if (sliderHours.getValue() != 0) {
        newPeriod = newPeriod.plusHours((int) sliderHours.getValue());
    }
    if (sliderMonth.getValue() != 0) {
        newPeriod = newPeriod.plusMonths((int) sliderMonth.getValue());
    }
    if (sliderWeek.getValue() != 0) {
        newPeriod = newPeriod.plusWeeks((int) sliderWeek.getValue());
    }

    field.setText(newPeriod.toString());
    _returnPeriod = newPeriod;
}