List of usage examples for org.joda.time Period plusYears
public Period plusYears(int years)
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 ava 2 s .c o 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.apache.arrow.vector.IntervalYearVector.java
License:Apache License
/** * Same as {@link #get(int)}.//from w w w .ja v a 2 s . c om * * @param index position of element * @return element at given index */ public Period getObject(int index) { if (isSet(index) == 0) { return null; } else { final int interval = valueBuffer.getInt(index * TYPE_WIDTH); final int years = (interval / org.apache.arrow.vector.util.DateUtility.yearsToMonths); final int months = (interval % org.apache.arrow.vector.util.DateUtility.yearsToMonths); final Period p = new Period(); return p.plusYears(years).plusMonths(months); } }