List of usage examples for org.joda.time DateTime plusYears
public DateTime plusYears(int years)
From source file:influent.server.dataaccess.DataAccessHelper.java
License:MIT License
public static DateTime getExclusiveEndDate(FL_DateRange date) { if (date == null) { return null; }/*from ww w . ja v a 2 s . c o m*/ DateTime d = new DateTime((long) date.getStartDate(), DateTimeZone.UTC); switch (date.getDurationPerBin().getInterval()) { case SECONDS: return d.plusSeconds(date.getNumBins().intValue()); case HOURS: return d.plusHours(date.getNumBins().intValue()); case DAYS: return d.plusDays(date.getNumBins().intValue()); case WEEKS: return d.plusWeeks(date.getNumBins().intValue()); case MONTHS: return d.plusMonths(date.getNumBins().intValue()); case QUARTERS: return d.plusMonths(date.getNumBins().intValue() * 3); case YEARS: return d.plusYears(date.getNumBins().intValue()); } return d; }
From source file:io.renren.common.utils.DateUtils.java
License:Apache License
/** * ?/?/* w w w .jav a 2s . c o m*/ * * @param date * @param years ? * @return /?? */ public static Date addDateYears(Date date, int years) { DateTime dateTime = new DateTime(date); return dateTime.plusYears(years).toDate(); }
From source file:io.warp10.script.functions.ADDYEARS.java
License:Apache License
@Override public Object apply(WarpScriptStack stack) throws WarpScriptException { Object top = stack.pop();/* w w w . j a v a 2 s.c o m*/ if (!(top instanceof Long)) { throw new WarpScriptException(getName() + " expects a number of years on top of the stack."); } int years = ((Number) top).intValue(); top = stack.pop(); String tz = null; if (top instanceof String) { tz = top.toString(); top = stack.pop(); if (!(top instanceof Long)) { throw new WarpScriptException( getName() + " operates on a tselements list, timestamp, or timestamp and timezone."); } } else if (!(top instanceof List) && !(top instanceof Long)) { throw new WarpScriptException( getName() + " operates on a tselements list, timestamp, or timestamp and timezone."); } if (top instanceof Long) { long instant = ((Number) top).longValue(); if (null == tz) { tz = "UTC"; } DateTimeZone dtz = DateTimeZone.forID(null == tz ? "UTC" : tz); DateTime dt = new DateTime(instant / Constants.TIME_UNITS_PER_MS, dtz); dt = dt.plusYears(years); long ts = dt.getMillis() * Constants.TIME_UNITS_PER_MS + (instant % Constants.TIME_UNITS_PER_MS); stack.push(ts); } else { List<Object> elts = new ArrayList<Object>((List<Object>) top); int year = ((Number) elts.get(0)).intValue(); year += years; elts.set(0, (long) year); // Now check if we are in ferbuary and if this is coherent with // a possibly non leap year if (elts.size() > 2) { int month = ((Number) elts.get(1)).intValue(); int day = ((Number) elts.get(2)).intValue(); if (2 == month && day > 28) { if ((0 != year % 4) || (0 == year % 100)) { elts.set(2, (long) 28); } } } stack.push(elts); } return stack; }
From source file:kr.debop4j.timeperiod.calendars.DateDiff.java
License:Apache License
private int calcYears() { if (Objects.equal(start, end)) return 0; int compareDay = Math.min(end.getDayOfMonth(), timeCalendar.getDaysInMonth(getStartYear(), getEndMonthOfYear())); DateTime compareDate = new DateTime(getStartYear(), getEndMonthOfYear(), compareDay, 0, 0) .plusMillis(end.getMillisOfDay()); if (end.compareTo(start) > 0) { if (compareDate.compareTo(start) < 0) compareDate = compareDate.plusYears(1); } else if (compareDate.compareTo(start) > 0) { compareDate = compareDate.plusYears(-1); }// w ww .j a va 2s. c om return getEndYear() - timeCalendar.getYear(compareDate); }
From source file:kr.debop4j.timeperiod.timerange.YearRange.java
License:Apache License
/** * Add years./*from w w w . ja v a 2 s.co m*/ * * @param years the years * @return the year range */ public YearRange addYears(int years) { DateTime baseTime = Times.startTimeOfYear(getStartYear()); return new YearRange(baseTime.plusYears(years), getTimeCalendar()); }
From source file:kr.debop4j.timeperiod.timerange.YearTimeRange.java
License:Apache License
private static TimeRange getPeriodOf(int year, int yearCount) { assert yearCount > 0; DateTime startYear = Times.startTimeOfYear(year); return new TimeRange(startYear, startYear.plusYears(yearCount)); }
From source file:kr.debop4j.timeperiod.tools.Durations.java
License:Apache License
/** * ?? @param year the year/*from ww w . j a v a2s.co m*/ * * @return the duration */ public static Duration year(int year) { DateTime start = Times.startTimeOfYear(year); DateTime end = start.plusYears(1); return new Duration(start, end); }
From source file:kr.debop4j.timeperiod.tools.Times.java
License:Apache License
/** ? ?(years) ?? */ public static TimeRange getRelativeYearPeriod(DateTime start, int years) { return getTimeRange(start, start.plusYears(years)); }
From source file:kr.debop4j.timeperiod.tools.Times.java
License:Apache License
/** ? ? ? . */ public static List<ITimePeriod> foreachYears(ITimePeriod period) { assert period != null; if (isTraceEnabled) log.trace("[{}]? Year ...", period); List<ITimePeriod> years = Lists.newArrayList(); if (period.isAnytime()) return years; assertHasPeriod(period);//from ww w . ja v a 2s .c o m if (Times.isSameYear(period.getStart(), period.getEnd())) { years.add(new TimeRange(period)); return years; } years.add(new TimeRange(period.getStart(), Times.endTimeOfYear(period.getStart()))); DateTime current = Times.startTimeOfYear(period.getStart()).plusYears(1); int endYear = period.getEnd().getYear(); ITimeCalendar calendar = TimeCalendar.getDefault(); while (current.getYear() < endYear) { years.add(Times.getYearRange(current, calendar)); current = current.plusYears(1); } if (current.compareTo(period.getEnd()) < 0) { years.add(new TimeRange(Times.startTimeOfYear(current), period.getEnd())); } return years; }
From source file:net.link.util.common.KeyUtils.java
License:Open Source License
public static X509Certificate generateSelfSignedCertificate(KeyPair keyPair, String dn) { DateTime now = new DateTime(); DateTime future = now.plusYears(10); return generateSelfSignedCertificate(keyPair, dn, now, future, null, true, false); }