List of usage examples for org.joda.time DateTime plusYears
public DateTime plusYears(int years)
From source file:org.fenixedu.spaces.domain.occupation.config.YearlyConfig.java
License:Open Source License
@Override public List<Interval> getIntervals() { List<Interval> intervals = new ArrayList<>(); DateTime startDate = getInterval().getStart(); DateTime endDate = getInterval().getEnd(); DateTime start = startDate; while (start.isBefore(endDate) || start.isEqual(endDate)) { intervals.add(new Interval(start.withFields(getStartTime()), start.withFields(getEndTime()))); start = start.plusYears(getRepeatsEvery()); }/*ww w . j av a 2 s .co m*/ return intervals; }
From source file:org.gephi.desktop.timeline.MinimalDrawer.java
License:Open Source License
private void paintUpperRulerForInterval(Graphics2D g2d, DateTime dtFrom, DateTime dtTo) { g2d.setFont(settings.graduations.font); g2d.setColor(settings.graduations.fontColor); int leftMargin = settings.graduations.leftMargin; int textTopPosition = settings.graduations.textTopPosition; int width = getWidth(); int height = getHeight(); // TODO take these from the model Interval interval = new Interval(dtFrom, dtTo); Period p = interval.toPeriod(PeriodType.days()); // try to determine length if we had to show milliseconds int n = p.getDays(); int unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("wednesday ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("jour"); for (int i = 0; i < n; i++) { g2d.drawString(dtFrom.plusDays(i).dayOfWeek().getAsText(LOCALE), leftMargin + 2 + i * (width / n), textTopPosition);// ww w.j av a 2 s . co m g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours()); } return; } unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("wed ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("jou"); for (int i = 0; i < n; i++) { g2d.drawString(dtFrom.plusDays(i).dayOfWeek().getAsShortText(LOCALE), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours()); } return; } p = interval.toPeriod(PeriodType.days()); n = p.getDays(); unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("30", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("j"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getDayOfMonth() + i), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours()); } return; } p = interval.toPeriod(PeriodType.months()); n = p.getMonths(); unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("September ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("mois"); for (int i = 0; i < n; i++) { g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsText(LOCALE), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays()); } return; } unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("dec ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("mo"); for (int i = 0; i < n; i++) { g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsShortText(LOCALE), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays()); } return; } unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("29 ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("m"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getMonthOfYear() + i), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays()); } return; } p = interval.toPeriod(PeriodType.years()); n = p.getYears(); unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("1980 ", null)).getWidth(); if (n < (width / unitSize)) { //System.out.println("year"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months.monthsBetween(dtFrom.plusYears(i), dtFrom.plusYears(i + 1)).getMonths()); } return; } int group = 10; n = p.getYears() / group; if (n < (width / unitSize)) { //System.out.println("10 years"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths()); } return; } group = 20; n = p.getYears() / group; if (n < (width / unitSize)) { //System.out.println("20 years"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths()); } return; } group = 50; n = p.getYears() / group; if (n < (width / unitSize)) { //System.out.println("50 years"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths()); } return; } group = 100; n = p.getYears() / group; if (n / 100 < (width / unitSize)) { //System.out.println("100 years"); for (int i = 0; i < n; i++) { g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n), textTopPosition); g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n), height - settings.graduations.textBottomMargin); paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths()); } } return; }
From source file:org.jasig.portlet.blackboardvcportlet.validations.validators.SessionEndTimeRangeCheckValidator.java
License:Apache License
@Override public boolean isValid(SessionForm value, ConstraintValidatorContext context) { logger.info("isValid() with startTime = {} and value = {}", value.getStartTime(), value.getEndTime()); DateTime startTime = value.getStartTime(); DateTime endTime = value.getEndTime(); long max = startTime.plusYears(1).getMillis(); if (endTime.isBefore(max)) { logger.info("End DateTime is within range, so returning true."); return true; }//from w w w .j a va 2 s .c om logger.info("End DateTime is NOT within range, so returning false."); return false; }
From source file:org.kairosdb.util.Util.java
License:Apache License
/** Computes the duration of the sampling (value * unit) starting at timestamp. //from w ww. j av a 2s . c o m @param timestamp unix timestamp of the start time. @return the duration of the sampling in millisecond. */ public static long getSamplingDuration(long timestamp, Sampling sampling, DateTimeZone timeZone) { long ret = sampling.getValue(); DateTime dt = new DateTime(timestamp, timeZone); switch (sampling.getUnit()) { case YEARS: ret = new org.joda.time.Duration(dt, dt.plusYears((int) sampling.getValue())).getMillis(); break; case MONTHS: ret = new org.joda.time.Duration(dt, dt.plusMonths((int) sampling.getValue())).getMillis(); break; case WEEKS: ret = new org.joda.time.Duration(dt, dt.plusWeeks((int) sampling.getValue())).getMillis(); break; case DAYS: ret = new org.joda.time.Duration(dt, dt.plusDays((int) sampling.getValue())).getMillis(); break; case HOURS: ret = new org.joda.time.Duration(dt, dt.plusHours((int) sampling.getValue())).getMillis(); break; case MINUTES: ret = new org.joda.time.Duration(dt, dt.plusMinutes((int) sampling.getValue())).getMillis(); break; case SECONDS: ret = new org.joda.time.Duration(dt, dt.plusSeconds((int) sampling.getValue())).getMillis(); break; case MILLISECONDS: ret = (long) sampling.getValue(); break; } return ret; }
From source file:org.killbill.billing.subscription.alignment.BaseAligner.java
License:Apache License
private DateTime addOrRemoveDuration(final DateTime input, final Duration duration, boolean add) { DateTime result = input; switch (duration.getUnit()) { case DAYS://from w ww. j a v a2 s .c om result = add ? result.plusDays(duration.getNumber()) : result.minusDays(duration.getNumber()); ; break; case MONTHS: result = add ? result.plusMonths(duration.getNumber()) : result.minusMonths(duration.getNumber()); break; case YEARS: result = add ? result.plusYears(duration.getNumber()) : result.minusYears(duration.getNumber()); break; case UNLIMITED: default: throw new RuntimeException("Trying to move to unlimited time period"); } return result; }
From source file:org.kuali.coeus.propdev.impl.budget.nonpersonnel.AddProjectBudgetLineItemHelper.java
License:Open Source License
protected List<AbstractBudgetRate> getInflationRates(List<AbstractBudgetRate> budgetRates, String rateTypeCode) {/*w w w . j a va2 s.c om*/ List<AbstractBudgetRate> inflationRates = new ArrayList<AbstractBudgetRate>(); for (AbstractBudgetRate budgetRate : budgetLineItem.getBudget().getBudgetRates()) { DateTime budgetRateStartDate = new DateTime(budgetRate.getStartDate().getTime()); DateTime budgetRateEndDate = budgetRateStartDate.plusYears(1).minusDays(1); Interval periodInterval = new Interval(budgetLineItem.getStartDate().getTime(), budgetLineItem.getEndDate().getTime()); Interval rateInterval = new Interval(budgetRateStartDate.getMillis(), budgetRateEndDate.getMillis()); if (StringUtils.equals(rateTypeCode, budgetRate.getRateTypeCode()) && StringUtils.equals(budgetRate.getRateClassType(), RateClassType.INFLATION.getRateClassType()) && budgetLineItem.getOnOffCampusFlag().equals(budgetRate.getOnOffCampusFlag()) && periodInterval.overlaps(rateInterval)) { inflationRates.add(budgetRate); } } return inflationRates; }
From source file:org.n52.iceland.util.DateTimeHelper.java
License:Open Source License
/** * Set the time object to the end values (seconds, minutes, hours, days,..) * if the time Object has not all values * * @param dateTime//w w w . j a v a 2s .co m * Time object * @param isoTimeLength * Length of the time object * @return Modified time object. */ public static DateTime setDateTime2EndOfMostPreciseUnit4RequestedEndPosition(final DateTime dateTime, final int isoTimeLength) { switch (isoTimeLength) { // year case YEAR: return dateTime.plusYears(ONE_VALUE).minusMillis(ONE_VALUE); // year, month case YEAR_MONTH: return dateTime.plusMonths(ONE_VALUE).minusMillis(ONE_VALUE); // year, month, day case YEAR_MONTH_DAY: return dateTime.plusDays(ONE_VALUE).minusMillis(ONE_VALUE); // year, month, day, hour case YEAR_MONTH_DAY_HOUR: return dateTime.plusHours(ONE_VALUE).minusMillis(ONE_VALUE); // year, month, day, hour, minute case YEAR_MONTH_DAY_HOUR_MINUTE: return dateTime.plusMinutes(ONE_VALUE).minusMillis(ONE_VALUE); // year, month, day, hour, minute, second case YEAR_MONTH_DAY_HOUR_MINUTE_SECOND: return dateTime.plusSeconds(ONE_VALUE).minusMillis(ONE_VALUE); default: return dateTime; } }
From source file:org.n52.shetland.util.DateTimeHelper.java
License:Apache License
/** * Set the time object to the end values (seconds, minutes, hours, days,..) * if the time Object has not all values * * @param dateTime//w ww. j a v a2s.c om * Time object * @param isoTimeLength * Length of the time object * @return Modified time object. */ public static DateTime setDateTime2EndOfMostPreciseUnit4RequestedEndPosition(DateTime dateTime, int isoTimeLength) { switch (isoTimeLength) { case YEAR: return dateTime.plusYears(1).minusMillis(1); case YEAR_MONTH: return dateTime.plusMonths(1).minusMillis(1); case YEAR_MONTH_DAY: return dateTime.plusDays(1).minusMillis(1); case YEAR_MONTH_DAY_HOUR: return dateTime.plusHours(1).minusMillis(1); case YEAR_MONTH_DAY_HOUR_MINUTE: return dateTime.plusMinutes(1).minusMillis(1); case YEAR_MONTH_DAY_HOUR_MINUTE_SECOND: return dateTime.plusSeconds(1).minusMillis(1); default: return dateTime; } }
From source file:org.nuxeo.elasticsearch.aggregate.DateHelper.java
License:Apache License
private static DateTime plusDurationAsExpression(DateTime origin, String duration) { int k = getFactor(duration); switch (duration.substring(duration.length() - 1, duration.length())) { case "s": return origin.plusSeconds(k); case "m": return origin.plusMinutes(k); case "h": return origin.plusHours(k); case "d": return origin.plusDays(k); case "w": return origin.plusWeeks(k); case "M": return origin.plusMonths(k); case "y": return origin.plusYears(k); }/* w w w. j a v a2s . c om*/ return invalid(duration); }
From source file:org.nuxeo.elasticsearch.aggregate.DateHelper.java
License:Apache License
private static DateTime plusDurationAsNoun(DateTime origin, String duration) { switch (duration.toLowerCase()) { case "second": return origin.plusSeconds(1); case "minute": return origin.plusMinutes(1); case "hour": return origin.plusHours(1); case "day": return origin.plusDays(1); case "week": return origin.plusWeeks(1); case "month": return origin.plusMonths(1); case "quarter": return origin.plusMonths(3); case "year": return origin.plusYears(1); }//www . ja va 2 s . co m return invalid(duration); }