List of usage examples for org.joda.time Period plusMonths
public Period plusMonths(int months)
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;//from w w w . j a va 2 s . co m 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 w w w .ja v a 2 s . 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; }
From source file:voldemort.store.readonly.mr.utils.HadoopUtils.java
License:Apache License
public static Period parsePeriod(String periodStr) { Matcher monthsFormat = Pattern.compile("[0-9][0-9]*M").matcher(periodStr); Matcher daysFormat = Pattern.compile("[0-9][0-9]*d").matcher(periodStr); Matcher hoursFormat = Pattern.compile("[0-9][0-9]*h").matcher(periodStr); Matcher minutesFormat = Pattern.compile("[0-9][0-9]*m").matcher(periodStr); Period period = new Period(); while (monthsFormat.find()) { period = period.plusMonths( Integer.parseInt(monthsFormat.group().substring(0, monthsFormat.group().length() - 1))); }//from w w w .j av a 2 s . c om while (daysFormat.find()) { period = period .plusDays(Integer.parseInt(daysFormat.group().substring(0, daysFormat.group().length() - 1))); } while (hoursFormat.find()) { period = period.plusHours( Integer.parseInt(hoursFormat.group().substring(0, hoursFormat.group().length() - 1))); } while (minutesFormat.find()) { period = period.plusMinutes( Integer.parseInt(minutesFormat.group().substring(0, minutesFormat.group().length() - 1))); } return period; }