Example usage for org.joda.time YearMonthDay toDateTime

List of usage examples for org.joda.time YearMonthDay toDateTime

Introduction

In this page you can find the example usage for org.joda.time YearMonthDay toDateTime.

Prototype

public DateTime toDateTime(TimeOfDay time) 

Source Link

Document

Converts this object to a DateTime using a TimeOfDay to fill in the missing fields and using the default time zone.

Usage

From source file:net.sourceforge.fenixedu.domain.space.EventSpaceOccupation.java

License:Open Source License

protected DateTime getInstant(boolean firstInstant, YearMonthDay begin, final YearMonthDay end,
        final HourMinuteSecond beginTime, final HourMinuteSecond endTime, final FrequencyType frequency,
        final DiaSemana diaSemana, final Boolean dailyFrequencyMarkSaturday,
        final Boolean dailyFrequencyMarkSunday) {

    DateTime instantResult = null;/*www .j a va2s .  c  o m*/
    begin = getBeginDateInSpecificWeekDay(diaSemana, begin);

    if (frequency == null) {
        if (!begin.isAfter(end)) {
            if (firstInstant) {
                return begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0));
            } else {
                return end.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0));
            }
        }
    } else {
        int numberOfDaysToSum = frequency.getNumberOfDays();
        while (true) {
            if (begin.isAfter(end)) {
                break;
            }

            DateTime intervalEnd = begin
                    .toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0));
            if (!frequency.equals(FrequencyType.DAILY) || ((dailyFrequencyMarkSaturday
                    || intervalEnd.getDayOfWeek() != SATURDAY_IN_JODA_TIME)
                    && (dailyFrequencyMarkSunday || intervalEnd.getDayOfWeek() != SUNDAY_IN_JODA_TIME))) {

                if (firstInstant) {
                    return begin
                            .toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0));
                } else {
                    instantResult = intervalEnd;
                }
            }
            begin = begin.plusDays(numberOfDaysToSum);
        }
    }
    return instantResult;
}

From source file:net.sourceforge.fenixedu.domain.space.EventSpaceOccupation.java

License:Open Source License

protected static Interval createNewInterval(YearMonthDay begin, YearMonthDay end, HourMinuteSecond beginTime,
        HourMinuteSecond endTime) {//from  www  . ja  v a2 s.co m
    return new Interval(begin.toDateTime(new TimeOfDay(beginTime.getHour(), beginTime.getMinuteOfHour(), 0, 0)),
            end.toDateTime(new TimeOfDay(endTime.getHour(), endTime.getMinuteOfHour(), 0, 0)));
}

From source file:net.sourceforge.fenixedu.domain.space.LessonInstanceSpaceOccupation.java

License:Open Source License

@Override
public List<Interval> getEventSpaceOccupationIntervals(YearMonthDay startDateToSearch,
        YearMonthDay endDateToSearch) {

    List<Interval> result = new ArrayList<Interval>();
    Collection<LessonInstance> lessonInstances = getLessonInstancesSet();

    DateTime startDateTime = startDateToSearch != null ? startDateToSearch.toDateTimeAtMidnight() : null;
    DateTime endDateTime = endDateToSearch != null ? endDateToSearch.toDateTime(new TimeOfDay(23, 59, 59))
            : null;//from w w w . j a  v  a2 s  . co m

    for (LessonInstance lessonInstance : lessonInstances) {
        if (startDateTime == null || (!lessonInstance.getEndDateTime().isBefore(startDateTime)
                && !lessonInstance.getBeginDateTime().isAfter(endDateTime))) {

            result.add(new Interval(lessonInstance.getBeginDateTime(), lessonInstance.getEndDateTime()));
        }
    }
    return result;
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.DateColumnYearMonthDayMapper.java

License:Apache License

@Override
public Date toNonNullValue(YearMonthDay value) {

    if (databaseZone == null) {
        return Date.valueOf(LOCAL_DATE_FORMATTER.print((LocalDate) (value.toLocalDate())));
    }//from  ww w .j a va 2s .c  o m

    DateTime zonedValue = value.toDateTime(value.toLocalDate().toDateTimeAtStartOfDay());

    final Date date = new Date(zonedValue.getMillis());
    return date;
}