List of usage examples for org.joda.time Period plusDays
public Period plusDays(int days)
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 www.j a v a 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.apache.arrow.vector.IntervalDayVector.java
License:Apache License
/** * Same as {@link #get(int)}.//from ww w .j a v a 2 s .c o m * * @param index position of element * @return element at given index */ public Period getObject(int index) { if (isSet(index) == 0) { return null; } else { final int startIndex = index * TYPE_WIDTH; final int days = valueBuffer.getInt(startIndex); final int milliseconds = valueBuffer.getInt(startIndex + MILLISECOND_OFFSET); final Period p = new Period(); return p.plusDays(days).plusMillis(milliseconds); } }
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(// ww w . j a v a 2 s . c om Integer.parseInt(monthsFormat.group().substring(0, monthsFormat.group().length() - 1))); } 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; }