Example usage for org.joda.time LocalDate plusDays

List of usage examples for org.joda.time LocalDate plusDays

Introduction

In this page you can find the example usage for org.joda.time LocalDate plusDays.

Prototype

public LocalDate plusDays(int days) 

Source Link

Document

Returns a copy of this date plus the specified number of days.

Usage

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

@Nonnull
public static LocalDate getCurrentOrNextWeekday() {
    LocalDate aDT = PDTFactory.getCurrentLocalDate();
    while (isWeekend(aDT))
        aDT = aDT.plusDays(1);
    return aDT;//from ww  w.ja v  a2  s .  c om
}

From source file:com.phloc.datetime.PDTUtils.java

License:Apache License

/**
 * Get the next working day based on the current day. If the current day is a
 * working day, the current day is returned. A working day is determined by:
 * it's not a weekend day (usually Saturday or Sunday).
 *
 * @return The next matching date.//  w  w  w .  ja  v  a  2  s .  c  o  m
 */
@Nonnull
public static LocalDate getCurrentOrNextWorkDay() {
    LocalDate aDT = PDTFactory.getCurrentLocalDate();
    while (isWorkDay(aDT))
        aDT = aDT.plusDays(1);
    return aDT;
}

From source file:com.prayer.vakit.times.Times.java

License:Apache License

Collection<Alarm> getAlarms() {
    Collection<Alarm> alarms = new ArrayList<>();

    LocalDate cal = LocalDate.now();
    for (int ii = 0; ii <= 1/* next day */; ii++) {
        for (Vakit v : Vakit.values()) {
            if (isNotificationActive(v)) {
                if (v != Vakit.SABAH) {
                    int vakit = v.ordinal();
                    if (vakit != 0) {
                        vakit--;/*from   ww w  .j  av  a  2  s  .  c  o  m*/
                    }

                    long mills = getTimeCal(cal, vakit).toDateTime().getMillis();
                    if (System.currentTimeMillis() < mills) {
                        Alarm a = new Alarm();
                        a.city = getID();
                        a.early = false;
                        a.cuma = false;
                        a.time = mills;
                        a.vakit = v;
                        a.dayOffset = ii;
                        alarms.add(a);
                    }
                } else {
                    long mills;
                    if (isAfterImsak()) {
                        mills = getTimeCal(cal, 0).toDateTime().getMillis() + getSabahTime() * 60 * 1000;
                    } else {
                        mills = getTimeCal(cal, 1).toDateTime().getMillis() - getSabahTime() * 60 * 1000;
                    }
                    if (System.currentTimeMillis() < mills) {
                        Alarm a = new Alarm();
                        a.city = getID();
                        a.cuma = false;
                        a.early = false;
                        a.time = mills;
                        a.vakit = v;
                        a.dayOffset = ii;
                        alarms.add(a);
                    }
                }
            }

            if (isEarlyNotificationActive(v)) {
                if (v != Vakit.SABAH) {
                    int vakit = v.ordinal();
                    if (vakit != 0) {
                        vakit--;
                    }

                    int early = getEarlyTime(v);
                    long mills = getTimeCal(cal, vakit).toDateTime().getMillis() - early * 60 * 1000;
                    if (System.currentTimeMillis() < mills) {
                        Alarm a = new Alarm();
                        a.city = getID();
                        a.early = true;
                        a.cuma = false;
                        a.time = mills;
                        a.vakit = v;
                        a.dayOffset = ii;
                        alarms.add(a);
                    }
                }
            }
        }
        cal = cal.plusDays(1);
    }
    if (isCumaActive()) {

        int early = getCumaTime();

        DateTime c = DateTime.now().withDayOfWeek(DateTimeConstants.FRIDAY);
        if ((c.getMillis() + 1000) < System.currentTimeMillis()) {
            c = c.plusWeeks(1);
        }
        long mills = getTimeCal(c.toLocalDate(), 2).toDateTime().getMillis();
        mills -= early * 60 * 1000;
        if (System.currentTimeMillis() < mills) {
            Alarm a = new Alarm();
            a.city = getID();
            a.cuma = true;
            a.early = false;
            a.time = mills;
            a.vakit = Vakit.OGLE;
            a.dayOffset = 0;
            alarms.add(a);
        }
    }

    return alarms;
}

From source file:com.prayer.vakit.times.Times.java

License:Apache License

public LocalDateTime getTimeCal(LocalDate date, int time) {
    if (date == null) {
        date = LocalDate.now();/*from w w  w.  j av  a  2s .  c o  m*/
    }
    if ((time < 0) || (time > 5)) {
        while (time >= 6) {
            date = date.plusDays(1);
            time -= 6;
        }

        while (time <= -1) {
            date = date.minusDays(1);
            time += 6;
        }
    }

    LocalDateTime timeCal = date.toLocalDateTime(new LocalTime(getTime(date, time)));
    int h = timeCal.getHourOfDay();
    if ((time >= 3) && (h < 5)) {
        timeCal = timeCal.plusDays(1);
    }
    return timeCal;
}

From source file:com.prayer.vakit.times.Times.java

License:Apache License

public String getTime(LocalDate date, int time) {
    if (date == null) {
        date = LocalDate.now();//  w w w. j av  a 2s .  c om
    }
    if ((time < 0) || (time > 5)) {
        while (time >= 6) {
            date = date.plusDays(1);
            time -= 6;
        }

        while (time == -1) {
            date = date.minusDays(1);
            time += 6;
        }

    }
    String ret = adj(_getTime(date, time), time);
    return ret;
}

From source file:com.qcadoo.mes.assignmentToShift.hooks.AssignmentToShiftHooks.java

License:Open Source License

private Optional<LocalDate> resolveNextStartDate(final Entity assignmentToShift) {
    final LocalDate startDate = LocalDate
            .fromDateFields(assignmentToShift.getDateField(AssignmentToShiftFields.START_DATE));
    final Shift shift = shiftsFactory.buildFrom(assignmentToShift.getBelongsToField(SHIFT));
    final Set<LocalDate> occupiedDates = findNextStartDatesMatching(assignmentToShift.getDataDefinition(),
            shift, startDate);//from   www  . j a  va 2 s  .  co m
    Iterable<Integer> daysRange = ContiguousSet.create(Range.closed(1, DAYS_IN_YEAR),
            DiscreteDomain.integers());
    return FluentIterable.from(daysRange).transform(new Function<Integer, LocalDate>() {

        @Override
        public LocalDate apply(final Integer numOfDay) {
            return startDate.plusDays(numOfDay);
        }
    }).firstMatch(new Predicate<LocalDate>() {

        @Override
        public boolean apply(final LocalDate localDate) {
            return !occupiedDates.contains(localDate) && shift.worksAt(localDate);
        }
    });
}

From source file:com.qcadoo.mes.productionPerShift.dates.OrderRealizationDaysResolver.java

License:Open Source License

private OrderRealizationDay findFirstWorkingDayFrom(final LocalDate orderStartDate, final int startFrom,
        final List<Shift> shifts) {
    for (int offset = startFrom; offset < startFrom + DAYS_IN_YEAR; offset++) {
        List<Shift> workingShifts = getShiftsWorkingAt(orderStartDate.plusDays(offset - 1).getDayOfWeek(),
                shifts);//  w  w w .  j a va  2  s.c  om
        if (!workingShifts.isEmpty()) {
            return new OrderRealizationDay(orderStartDate, offset, workingShifts);
        }
    }
    // assuming that no working shifts in period of year length means that client does not use shifts calendar and there won't
    // be any offsets caused by work free time boundaries.
    return new OrderRealizationDay(orderStartDate, startFrom, Collections.<Shift>emptyList());
}

From source file:com.squid.kraken.v4.api.core.EngineUtils.java

License:Open Source License

/**
 * Convert the facet value into a date. 
 * If the value start with '=', it is expected to be a Expression, in which case we'll try to resolve it to a Date constant.
 * @param ctx//  ww  w  . j  a v a  2s  .co m
 * @param index
 * @param lower 
 * @param value
 * @param compareFromInterval 
 * @return
 * @throws ParseException
 * @throws ScopeException
 * @throws ComputingException 
 */
public Date convertToDate(Universe universe, DimensionIndex index, Bound bound, String value,
        IntervalleObject compareFromInterval) throws ParseException, ScopeException, ComputingException {
    if (value.equals("")) {
        return null;
    } else if (value.startsWith("__")) {
        //
        // support hard-coded shortcuts
        if (value.toUpperCase().startsWith("__COMPARE_TO_")) {
            // for compareTo
            if (compareFromInterval == null) {
                // invalid compare_to selection...
                return null;
            }
            if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_PERIOD")) {
                LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime());
                if (bound == Bound.UPPER) {
                    LocalDate date = localLower.minusDays(1);
                    return date.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(
                            ((Date) compareFromInterval.getUpperBound()).getTime());
                    Days days = Days.daysBetween(localLower, localUpper);
                    LocalDate date = localLower.minusDays(1 + days.getDays());
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_MONTH")) {
                LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime());
                LocalDate compareLower = localLower.minusMonths(1);
                if (bound == Bound.LOWER) {
                    return compareLower.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(
                            ((Date) compareFromInterval.getUpperBound()).getTime());
                    Days days = Days.daysBetween(localLower, localUpper);
                    LocalDate compareUpper = compareLower.plusDays(days.getDays());
                    return compareUpper.toDate();
                }
            }
            if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_YEAR")) {
                LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime());
                LocalDate compareLower = localLower.minusYears(1);
                if (bound == Bound.LOWER) {
                    return compareLower.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(
                            ((Date) compareFromInterval.getUpperBound()).getTime());
                    Days days = Days.daysBetween(localLower, localUpper);
                    LocalDate compareUpper = compareLower.plusDays(days.getDays());
                    return compareUpper.toDate();
                }
            }
        } else {
            // for regular
            // get MIN, MAX first
            Intervalle range = null;
            if (index.getDimension().getType() == Type.CONTINUOUS) {
                if (index.getStatus() == Status.DONE) {
                    List<DimensionMember> members = index.getMembers();
                    if (!members.isEmpty()) {
                        DimensionMember member = members.get(0);
                        Object object = member.getID();
                        if (object instanceof Intervalle) {
                            range = (Intervalle) object;
                        }
                    }
                } else {
                    try {
                        DomainHierarchy hierarchy = universe
                                .getDomainHierarchy(index.getAxis().getParent().getDomain());
                        hierarchy.isDone(index, null);
                    } catch (ComputingException | InterruptedException | ExecutionException
                            | TimeoutException e) {
                        throw new ComputingException("failed to retrieve period interval");
                    }
                }
            }
            if (range == null) {
                range = IntervalleObject.createInterval(new Date(), new Date());
            }
            if (value.equalsIgnoreCase("__ALL")) {
                if (index.getDimension().getType() != Type.CONTINUOUS) {
                    return null;
                }
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    return (Date) range.getLowerBound();
                }
            }
            if (value.equalsIgnoreCase("__LAST_DAY")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    return (Date) range.getUpperBound();
                }
            }
            if (value.equalsIgnoreCase("__LAST_7_DAYS")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.minusDays(6);// 6+1
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__CURRENT_MONTH")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withDayOfMonth(1);
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__CURRENT_YEAR")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1);
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__PREVIOUS_MONTH")) {// the previous complete month
                if (bound == Bound.UPPER) {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withDayOfMonth(1).minusDays(1);
                    return date.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withDayOfMonth(1).minusMonths(1);
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__PREVIOUS_YEAR")) {// the previous complete month
                if (bound == Bound.UPPER) {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1).minusDays(1);
                    return date.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1).minusYears(1);
                    return date.toDate();
                }
            }
        }
        throw new ScopeException("undefined facet expression alias: " + value);
    } else if (value.startsWith("=")) {
        // if the value starts by equal token, this is a formula that can be
        // evaluated
        try {
            String expr = value.substring(1);
            // check if the index content is available or wait for it
            DomainHierarchy hierarchy = universe.getDomainHierarchy(index.getAxis().getParent().getDomain(),
                    true);
            hierarchy.isDone(index, null);
            // evaluate the expression
            Object defaultValue = evaluateExpression(universe, index, expr, compareFromInterval);
            // check we can use it
            if (defaultValue == null) {
                //throw new ScopeException("unable to parse the facet expression as a constant: " + expr);
                // T1769: it's ok to return null
                return null;
            }
            if (!(defaultValue instanceof Date)) {
                throw new ScopeException("unable to parse the facet expression as a date: " + expr);
            }
            // ok, it's a date
            return (Date) defaultValue;
        } catch (ComputingException | InterruptedException | ExecutionException | TimeoutException e) {
            throw new ComputingException("failed to retrieve period interval");
        }
    } else {
        Date date = ServiceUtils.getInstance().toDate(value);
        if (bound == Bound.UPPER
                && !index.getAxis().getDefinitionSafe().getImageDomain().isInstanceOf(IDomain.TIME)) {
            // clear the timestamp
            return new LocalDate(date.getTime()).toDate();
        } else {
            return date;
        }
    }
}

From source file:com.stagecents.common.EffectiveDateInterval.java

License:Open Source License

/**
 * Creates a new EffectiveDateInterval from the given <code>LocalDate</code>
 * start and end dates. The <code>startDate</code> is converted to a
 * <code>DateTime</code> object by setting it to midnight (00:00) at the
 * start of the given day. The <code>endDate</code> is converted to a
 * <code>DateTime</code> object by setting it to midnight (00:00) of the day
 * following the given day.//from  www .  ja  v a  2 s  .c o m
 * <p>
 * If <code>startDate</code> is null, the start date of the
 * EffectiveDateInterval will be set to the beginning of time. If
 * <code>endDate</code> is null, the end date of the EffectiveDateInterval
 * will be set to the end of time.
 * 
 * @param startDate The date on which the EffectiveDateInterval becomes
 *            effective.
 * @param endDate The date after which the EffectiveDateInterval is no
 *            longer effective or the end of time if null.
 * @see http://www.joda.org/joda-time/key_partial.html
 */
public EffectiveDateInterval(LocalDate startDate, LocalDate endDate) {
    if (startDate != null) {
        // Convert start day to midnight
        this.startDate = startDate.toDateTimeAtStartOfDay();
    } else {
        this.startDate = new DateTime(0);
    }
    if (endDate != null) {
        this.endDate = endDate.plusDays(1).toDateTimeAtStartOfDay();
    } else {
        this.endDate = new DateTime(Long.MAX_VALUE);
    }
}

From source file:com.stagecents.gl.api.service.CalendarCommandHandler.java

License:Open Source License

private void checkCalendarGap(PeriodDTO[] periods) {
    boolean gapExists = false;
    LocalDate end = periods[0].getEndDate();
    for (int i = 1; i < periods.length; i++) {
        LocalDate start = periods[i].getStartDate();
        if (!(end.plusDays(1).isEqual(start)) && !(periods[i].isAdjustmentPeriod())) {
            gapExists = true;// w w w.  j  a v  a 2s .c  om
            break;
        }
        end = periods[i].getEndDate();
    }
    if (gapExists) {
        throw new ValidationException("gap found in calendar periods");
    }
}