Example usage for org.joda.time LocalDateTime isBefore

List of usage examples for org.joda.time LocalDateTime isBefore

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime isBefore.

Prototype

public boolean isBefore(ReadablePartial partial) 

Source Link

Document

Is this partial earlier than the specified partial.

Usage

From source file:com.mklinke.breakplanner.model.Break.java

License:Apache License

/**
 * @param time//from w ww  . ja  v a2  s.c o  m
 *          the time for the break
 * @throws IllegalArgumentException
 *           if the time is null or in the past
 */
public void setTime(LocalDateTime time) {
    LocalDateTime aMinuteAgo = new LocalDateTime().minusMinutes(1);
    if (time == null || time.isBefore(aMinuteAgo)) {
        throw new IllegalArgumentException("Invalid time: " + time);
    }
    this.time = time;
}

From source file:com.weekcalendar.WeekCalendarFragment.java

License:Open Source License

/**
 * Set set date of the selected week/*from  w ww  .  ja v a 2 s .com*/
 */
public void setDateWeek(Calendar calendar) {
    LocalDateTime ldt = LocalDateTime.fromCalendarFields(calendar);
    AppController.getInstance().setSelected(ldt);
    int nextPage = Weeks.weeksBetween(mStartDate, ldt).getWeeks();
    if (nextPage < 0 || (nextPage == 0 && ldt.isBefore(mStartDate))) {
        // make selected date to previous week on viewpager onSelected:
        // if result is negative or it is 0 weeks but earlier than week start date.
        --nextPage;
    }
    if (nextPage >= -mMiddlePoint && nextPage < mMiddlePoint) {
        mViewPager.setCurrentItem(nextPage + mMiddlePoint);
        if (mCalenderListener != null) {
            mCalenderListener.onSelectDate(ldt);
        }
        WeekFragment fragment = (WeekFragment) mViewPager.getAdapter().instantiateItem(mViewPager,
                nextPage + mMiddlePoint);
        fragment.ChangeSelector(ldt);
    }
}

From source file:control.Xray.java

/**
 * Tjekker om en given dato er i en given tidsperiode.
 *
 * @param dateTime metoden returnerer sand, hvis denne parameter ligger i
 * den givne periode./* w w w . ja v a2  s . co  m*/
 * @param periodStart definerer periodens start.
 * @param periodEnd definerer periodens slutning.
 * @return
 */
public boolean isDateInPeriod(LocalDateTime dateTime, LocalDateTime periodStart, LocalDateTime periodEnd) {
    boolean inPeriod = false;

    if (dateTime.isEqual(periodStart) || (dateTime.isBefore(periodEnd) && dateTime.isAfter(periodStart))) {
        inPeriod = true;
    }

    return inPeriod;
}

From source file:control.Xray.java

public ArrayList<LocalDateTime> getDatesInPeriod(LocalDateTime startTime, LocalDateTime endTime) {
    ArrayList<LocalDateTime> dates = new ArrayList<>();
    LocalDateTime currentDate = new LocalDateTime(startTime);
    currentDate = currentDate.withHourOfDay(0);
    currentDate = currentDate.withMinuteOfHour(0);

    while (currentDate.isBefore(endTime)) {
        dates.add(currentDate);/* ww  w .  j  a v a2s  .  co m*/
        currentDate = currentDate.plusDays(1);
    }

    return dates;
}

From source file:de.avanux.smartapplianceenabler.appliance.ConsecutiveDaysTimeframe.java

License:Open Source License

public List<TimeframeInterval> getIntervals(LocalDateTime now) {
    if (start != null && end != null) {
        LocalDateTime earliestStartNextOccurrence = start.toNextOccurrence(now);
        LocalDateTime latestEndNextOccurrence = end.toNextOccurrence(now);
        LocalDateTime earliestStartDateTime = earliestStartNextOccurrence;
        if (latestEndNextOccurrence.isBefore(earliestStartNextOccurrence)
                && now.isBefore(latestEndNextOccurrence)) {
            earliestStartDateTime = start.toLastOccurrence(now);
        }/* w  w w.  j  a  va 2s .c o  m*/
        LocalDateTime latestEndDateTime = end.toNextOccurrence(earliestStartDateTime);
        Interval interval = new Interval(earliestStartDateTime.toDateTime(), latestEndDateTime.toDateTime())
                .withChronology(ISOChronology.getInstance());
        TimeframeInterval timeframeInterval = new TimeframeInterval(this, interval);
        return Collections.singletonList(timeframeInterval);
    }
    return null;
}

From source file:de.avanux.smartapplianceenabler.appliance.DayTimeframe.java

License:Open Source License

/**
 * Returns true, if the end time is after midnight.
 * @param earliestStartDateTime the start time
 * @param latestEndDateTime the end time
 * @return/*from  www.  jav a 2s  .c o  m*/
 */
private boolean isOverMidnight(LocalDateTime earliestStartDateTime, LocalDateTime latestEndDateTime) {
    return latestEndDateTime.isBefore(earliestStartDateTime);
}

From source file:de.avanux.smartapplianceenabler.appliance.RunningTimeMonitor.java

License:Open Source License

/**
 * Updates remainingMinRunningTime for the given instant. The value may become negative!
 * Subsequent calls to this method within one second are omitted.
 * @param now//from   ww  w .j  a va  2s. c  om
 */
protected void update(LocalDateTime now) {
    // update not more than once per second in order to avoid spamming the log
    if (lastUpdate == null || now.isBefore(lastUpdate)
            || new Interval(lastUpdate.toDateTime(), now.toDateTime()).toDurationMillis() > 1000) {
        activateTimeframeInterval(now, schedules);
        deactivateExpiredTimeframeInterval(now);
        logger.debug("activeTimeframeInterval=" + activeTimeframeInterval + " statusChangedAt="
                + statusChangedAt + " intervalBegin=" + intervalBegin + " running=" + running);

        Interval interval = null;
        if (running) {
            // running
            if (intervalBegin == null) {
                // running was set to true after interval begin
                interval = new Interval(statusChangedAt.toDateTime(), now.toDateTime());
            } else {
                // no status change in interval
                interval = new Interval(intervalBegin.toDateTime(), now.toDateTime());
            }
            intervalBegin = now;
        } else if (intervalBegin != null && statusChangedAt != null) {
            // running was set to false after interval begin
            interval = new Interval(intervalBegin.toDateTime(), statusChangedAt.toDateTime());
            intervalBegin = null;
            statusChangedAt = null;
        }
        if (interval != null && remainingMinRunningTime != null && remainingMaxRunningTime != null) {
            int intervalSeconds = Double.valueOf(interval.toDuration().getMillis() / 1000).intValue();
            remainingMinRunningTime = remainingMinRunningTime - intervalSeconds;
            remainingMaxRunningTime = remainingMaxRunningTime - intervalSeconds;
        }
        lastUpdate = now;
    }
}

From source file:energy.usef.core.service.rest.sender.SenderService.java

License:Apache License

/**
 * Sends an outgoing message to a recipient. If an attempt is not successful, the application tries the repeat the attempt a
 * predefined number of times.//from  w w  w .j a va  2 s . c o m
 *
 * @param xmlString XML representation of the message
 * @throws BusinessException
 */
public void sendMessage(String xmlString) {
    LOGGER.debug("Started sending message");
    LOGGER_CONFIDENTIAL.debug("Trying to send message {} ", xmlString);

    Message dtoMessage = (Message) XMLUtil.xmlToMessage(xmlString,
            config.getBooleanProperty(ConfigParam.VALIDATE_OUTGOING_XML).booleanValue());
    energy.usef.core.model.Message storedMessage = messageService.storeMessage(xmlString, dtoMessage,
            MessageDirection.OUTBOUND);

    LocalDateTime validUntil = dtoMessage.getMessageMetadata().getValidUntil();
    if (validUntil != null && validUntil.isBefore(DateTimeUtil.getCurrentDateTime())) {
        reportMessageNotSentError(storedMessage, dtoMessage, "validUntil time has passed", null);
        return;
    }
    try {
        // create a Backoff Strategy based on Precedence
        BackOff backoff = createExponentialBackOff(dtoMessage.getMessageMetadata().getPrecedence());
        // get retries
        int retries = getHttpRequestMaxRetries(dtoMessage.getMessageMetadata().getPrecedence());

        // create the url
        String url = createUrl(dtoMessage);

        SignedMessage signedMessage = createSignedMessage(xmlString, dtoMessage);

        HttpRequest request = buildHttpRequest(url, signedMessage, backoff, retries);

        // send request
        HttpResponse response = request.execute();

        notificationHelperService.notifyNoMessageResponse(xmlString, dtoMessage);

        handleResponseStatuses(storedMessage, dtoMessage, response);
        response.disconnect();

    } catch (HttpResponseException e) {
        reportMessageNotSentError(storedMessage, dtoMessage, e.getMessage(), e.getStatusCode());
    } catch (IOException | BusinessException e) {
        reportMessageNotSentError(storedMessage, dtoMessage, e.getMessage(), null);
    }
}

From source file:energy.usef.core.util.DateTimeUtil.java

License:Apache License

/**
 * Gets the number of milliseconds until the next occurence of the local time (which is the current day or the day after).
 *
 * @param localTime {@link LocalTime}// w  w w .j av  a 2s.c  o  m
 * @return the number of milliseconds.
 */
public static Long millisecondDelayUntilNextTime(LocalTime localTime) {
    LocalDateTime schedule = getCurrentDateWithTime(localTime);
    if (schedule.isBefore(getCurrentDateTime())) {
        schedule = schedule.plusDays(1);
    }
    return new Duration(getCurrentDateTime().toDateTime(), schedule.toDateTime()).getMillis();
}

From source file:net.rrm.ehour.report.reports.element.AssignmentAggregateReportElement.java

License:Open Source License

/**
 * Get the progress (booked hours) in percentage of the allotted hours, leaving out the overrun
 * or for date ranges use the current date vs start & end date (if they're both null)
 *///from w  ww.ja va  2  s  . c  o m
public Optional<Float> getProgressPercentage() {
    Optional<Float> percentage = Optional.absent();

    if (projectAssignment == null) {
        return Optional.absent();
    }

    if (projectAssignment.getAssignmentType().isAllottedType()) {
        if (hours != null && projectAssignment.getAllottedHours() != null && hours.floatValue() > 0
                && projectAssignment.getAllottedHours() > 0) {
            percentage = Optional.of((hours.floatValue() / projectAssignment.getAllottedHours()) * 100);

        }
    } else if (projectAssignment.getAssignmentType().isDateType() && projectAssignment.getDateStart() != null
            && projectAssignment.getDateEnd() != null) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime start = new LocalDateTime(projectAssignment.getDateStart());
        LocalDateTime end = new LocalDateTime(projectAssignment.getDateEnd());

        if (now.isBefore(start)) {
            percentage = Optional.of(0f);
        } else if (now.isAfter(end)) {
            percentage = Optional.of(100f);
        } else {
            float totalRange = Days.daysBetween(start, end).getDays();
            float daysConsumed = Days.daysBetween(start, now).getDays();

            percentage = Optional.of((daysConsumed / totalRange) * 100);
        }

        // if percentage is above 100 for daterange the user can't book anymore hours
        // so don't display more than 100%
        if (percentage.get() > 100) {
            percentage = Optional.of(100f);
        }
    }

    return percentage;
}