Example usage for org.joda.time DateMidnight toDateTime

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

Introduction

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

Prototype

DateTime toDateTime();

Source Link

Document

Get this object as a DateTime.

Usage

From source file:com.enonic.cms.core.content.index.queryexpression.DateCompareEvaluator.java

License:Open Source License

private ReadableDateTime createLowerBoundDate(DateMidnight date) {
    return date.toDateTime();
}

From source file:com.enonic.cms.core.content.index.queryexpression.DateCompareEvaluator.java

License:Open Source License

private ReadableDateTime createUpperBoundDate(DateMidnight date) {
    DateTime dateMidnight = date.toDateTime();
    return dateMidnight.plus(new Period(23, 59, 59, 999));
}

From source file:com.excilys.ebi.bank.service.impl.BankServiceImpl.java

License:Apache License

@Override
public Calendar getCalendar(Integer year, Integer month) {

    Calendar calendar = new Calendar();

    // build months
    List<DateTime> months = calendar.getMonths();

    DateMidnight thisMonth = getDefaultDateTime().toDateMidnight().withDayOfMonth(1);
    months.add(thisMonth.toDateTime());

    // display last 6 months
    while (months.size() < 6) {
        thisMonth = thisMonth.minusMonths(1);
        months.add(thisMonth.toDateTime());
    }/*from  w ww .jav  a2  s . c o m*/

    reverse(months);

    // build selectedMonth
    if (year != null) {
        notNull(month, "month is required if year is specified");
        DateTime selectedMonth = new DateMidnight().withDayOfMonth(1).withYear(year).withMonthOfYear(month)
                .toDateTime();
        calendar.setSelectedMonth(selectedMonth);
    }

    return calendar;
}

From source file:com.google.android.apps.paco.Experiment.java

License:Open Source License

private void generateNextPeriod(DateMidnight generatingPeriodStart, AlarmStore alarmStore) {
    if (isExperimentOver(generatingPeriodStart.toDateTime())) {
        return;//ww  w  .  j a  v  a 2 s .  c o m
    }
    alarmStore.deleteSignalsForPeriod(getId(), generatingPeriodStart.getMillis());

    List<DateTime> signalTimes = generateSignalTimesForPeriod(generatingPeriodStart);
    storeSignalTimes(generatingPeriodStart, signalTimes, alarmStore);
}

From source file:com.google.android.apps.paco.Experiment.java

License:Open Source License

private List<DateTime> generateSignalTimesForPeriod(DateMidnight periodStart) {
    return new EsmGenerator2().generateForSchedule(periodStart.toDateTime(),
            (SignalSchedule) getSignalingMechanisms().get(0));
}

From source file:com.google.android.apps.paco.NonESMSignalGenerator.java

License:Open Source License

private DateTime getNextScheduleDay(DateTime midnightTomorrow) {

    switch (schedule.getScheduleType()) {
    case SignalSchedule.DAILY:
        return nextRepeatDaily(midnightTomorrow);

    case SignalSchedule.WEEKDAY:
        int tomorrowDOW = midnightTomorrow.getDayOfWeek();
        if (tomorrowDOW > DateTimeConstants.FRIDAY) {
            return midnightTomorrow.plusDays(8 - tomorrowDOW);
        } else {/*from   ww  w. j a  va2 s.  co m*/
            return midnightTomorrow;
        }

    case SignalSchedule.WEEKLY:
        int scheduleDays = schedule.getWeekDaysScheduled();
        if (scheduleDays == 0) {
            return null;
        }
        for (int i = 0; i < 8; i++) { // go at least to the same day next week.
            int midnightTomorrowDOW = midnightTomorrow.getDayOfWeek();
            Integer nowDowIndex = SignalSchedule.DAYS_OF_WEEK[midnightTomorrowDOW == 7 ? 0
                    : midnightTomorrowDOW]; // joda is 1 based & counts Monday as first day of the week so Sunday is 7 instead of 0.
            if ((scheduleDays & nowDowIndex) == nowDowIndex) {
                return nextRepeatWeekly(midnightTomorrow);
            }
            midnightTomorrow = midnightTomorrow.plusDays(1);

        }
        throw new IllegalStateException("Cannot get to here. Weekly must repeat at least once a week");

    case SignalSchedule.MONTHLY:
        if (schedule.getByDayOfMonth()) {
            int midnightDOM = midnightTomorrow.getDayOfMonth();
            int scheduledDOM = schedule.getDayOfMonth();
            if (midnightDOM == scheduledDOM) {
                return midnightTomorrow;
            } else if (midnightDOM > scheduledDOM) {
                MutableDateTime mutableDateTime = midnightTomorrow.plusMonths(1).toMutableDateTime();
                mutableDateTime.setDayOfMonth(scheduledDOM);
                return nextRepeatMonthly(mutableDateTime.toDateTime());
            } else {
                return nextRepeatMonthly(midnightTomorrow.plusDays(scheduledDOM - midnightDOM));
            }
        } else {
            Integer nthOfMonth = schedule.getNthOfMonth();
            Integer dow = getDOWFromIndexedValue(); // only one selection, so take log2 to get index of dow
            DateMidnight nthDowDate = getNthDOWOfMonth(midnightTomorrow, nthOfMonth, dow).toDateMidnight();
            DateTime returnDate = null;
            if (nthDowDate.equals(midnightTomorrow)) {
                returnDate = midnightTomorrow;
            } else if (nthDowDate.isAfter(midnightTomorrow)) {
                returnDate = nthDowDate.toDateTime();
            } else {
                returnDate = getNthDOWOfMonth(midnightTomorrow.plusMonths(1), nthOfMonth, dow).toDateTime();
            }
            return nextRepeatMonthly(returnDate);
        }
    default:
        throw new IllegalStateException("Schedule has an unknown type: " + schedule.getScheduleType());
    }
}

From source file:com.latlab.common.model.PeriodUtils.java

/**
 * Obtains a Map of {@link YearQuarterDate} for all the quarters of the
 * specified year. If <code>year</code> value is 0 or less, it is assumed
 * that the year is the current year./*from   w w  w  . ja v a 2s.com*/
 *
 * @param year
 * @return
 */
public static Map<Period, DateRange> getQuarterDates(int year) {
    Map<Period, DateRange> quarterMap = new HashMap<>();

    DateMidnight refDate = new DateMidnight();
    if (year > 0) {
        refDate = refDate.withYear(year);
    }

    refDate = refDate.withMonthOfYear(1).withDayOfMonth(1);
    Date startDate1 = refDate.toDate();
    refDate = refDate.plusMonths(2);
    refDate = refDate.withDayOfMonth(refDate.dayOfMonth().getMaximumValue());
    Date endDate1 = new DateTime(refDate.toDateTime()).withHourOfDay(23).withMinuteOfHour(59)
            .withSecondOfMinute(59).toDate();

    DateRange quarterDate = new DateRange(Period.FIRST_QUARTER, year, startDate1, endDate1);
    quarterMap.put(quarterDate.getPeriod(), quarterDate);

    refDate = refDate.withMonthOfYear(4).withDayOfMonth(1);
    Date starteDate2 = refDate.toDate();
    refDate = refDate.plusMonths(2);
    refDate = refDate.withDayOfMonth(refDate.dayOfMonth().getMaximumValue());
    Date endDate2 = new DateTime(refDate.toDateTime()).withHourOfDay(23).withMinuteOfHour(59)
            .withSecondOfMinute(59).toDate();
    DateRange quarterDate2 = new DateRange(Period.SECOND_QUARTER, year, starteDate2, endDate2);
    quarterMap.put(quarterDate2.getPeriod(), quarterDate2);

    refDate = refDate.withMonthOfYear(7).withDayOfMonth(1);
    Date starteDate3 = refDate.toDate();
    refDate = refDate.plusMonths(2);
    refDate = refDate.withDayOfMonth(refDate.dayOfMonth().getMaximumValue());
    Date endDate3 = new DateTime(refDate.toDateTime()).withHourOfDay(23).withMinuteOfHour(59)
            .withSecondOfMinute(59).toDate();
    DateRange quarterDate3 = new DateRange(Period.THIRD_QUARTER, year, starteDate3, endDate3);
    quarterMap.put(quarterDate3.getPeriod(), quarterDate3);

    refDate = refDate.withMonthOfYear(10).withDayOfMonth(1);
    Date starteDate4 = refDate.toDate();
    refDate = refDate.plusMonths(2);
    refDate = refDate.withDayOfMonth(refDate.dayOfMonth().getMaximumValue());
    Date endDate4 = new DateTime(refDate.toDateTime()).withHourOfDay(23).withMinuteOfHour(59)
            .withSecondOfMinute(59).toDate();
    DateRange quarterDate4 = new DateRange(Period.LAST_QUARTER, refDate.getYear(), starteDate4, endDate4);
    quarterMap.put(quarterDate4.getPeriod(), quarterDate4);
    return quarterMap;
}

From source file:com.pacoapp.paco.shared.scheduling.NonESMSignalGenerator.java

License:Open Source License

private DateTime getNextScheduleDay(DateTime midnightTomorrow) {

    switch (schedule.getScheduleType()) {
    case Schedule.DAILY:
        return nextRepeatDaily(midnightTomorrow);

    case Schedule.WEEKDAY:
        int tomorrowDOW = midnightTomorrow.getDayOfWeek();
        if (tomorrowDOW > DateTimeConstants.FRIDAY) {
            return midnightTomorrow.plusDays(8 - tomorrowDOW);
        } else {/* ww  w  .  j a  v  a  2  s. c o m*/
            return midnightTomorrow;
        }

    case Schedule.WEEKLY:
        int scheduleDays = schedule.getWeekDaysScheduled();
        if (scheduleDays == 0) {
            return null;
        }
        for (int i = 0; i < 8; i++) { // go at least to the same day next week.
            int midnightTomorrowDOW = midnightTomorrow.getDayOfWeek();
            Integer nowDowIndex = Schedule.DAYS_OF_WEEK[midnightTomorrowDOW == 7 ? 0 : midnightTomorrowDOW]; // joda is 1 based & counts Monday as first day of the week so Sunday is 7 instead of 0.
            if ((scheduleDays & nowDowIndex) == nowDowIndex) {
                return nextRepeatWeekly(midnightTomorrow);
            }
            midnightTomorrow = midnightTomorrow.plusDays(1);

        }
        throw new IllegalStateException("Cannot get to here. Weekly must repeat at least once a week");

    case Schedule.MONTHLY:
        if (schedule.getByDayOfMonth()) {
            int midnightDOM = midnightTomorrow.getDayOfMonth();
            int scheduledDOM = schedule.getDayOfMonth();
            if (midnightDOM == scheduledDOM) {
                return midnightTomorrow;
            } else if (midnightDOM > scheduledDOM) {
                MutableDateTime mutableDateTime = midnightTomorrow.plusMonths(1).toMutableDateTime();
                mutableDateTime.setDayOfMonth(scheduledDOM);
                return nextRepeatMonthly(mutableDateTime.toDateTime());
            } else {
                return nextRepeatMonthly(midnightTomorrow.plusDays(scheduledDOM - midnightDOM));
            }
        } else {
            Integer nthOfMonth = schedule.getNthOfMonth();
            Integer dow = getDOWFromIndexedValue(); // only one selection, so take log2 to get index of dow
            DateMidnight nthDowDate = getNthDOWOfMonth(midnightTomorrow, nthOfMonth, dow).toDateMidnight();
            DateTime returnDate = null;
            if (nthDowDate.equals(midnightTomorrow)) {
                returnDate = midnightTomorrow;
            } else if (nthDowDate.isAfter(midnightTomorrow)) {
                returnDate = nthDowDate.toDateTime();
            } else {
                returnDate = getNthDOWOfMonth(midnightTomorrow.plusMonths(1), nthOfMonth, dow).toDateTime();
            }
            return nextRepeatMonthly(returnDate);
        }
    default:
        throw new IllegalStateException("Schedule has an unknown type: " + schedule.getScheduleType());
    }
}

From source file:ddf.metrics.plugin.webconsole.MetricsWebConsolePlugin.java

License:Open Source License

private static String urlEncodeDate(DateMidnight date) throws UnsupportedEncodingException {
    return urlEncodeDate(date.toDateTime());
}

From source file:dk.teachus.backend.dao.hibernate.HibernateBookingDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)//from   ww  w . j av  a2  s . c om
public List<PupilBooking> getPaidBookings(Teacher teacher, DateMidnight startDate, DateMidnight endDate) {
    DetachedCriteria c = DetachedCriteria.forClass(PupilBookingImpl.class);

    c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL));
    c.createCriteria("pupil").add(Restrictions.eq("teacher", teacher)).add(Restrictions.eq("active", true))
            .createCriteria("teacher").add(Restrictions.eq("active", true));
    c.add(Restrictions.eq("paid", true));
    c.add(Restrictions.eq("active", true));

    if (startDate != null && endDate != null) {
        c.add(Restrictions.between("date", startDate.toDateTime(), endDate.toDateTime()));
    } else if (startDate != null) {
        c.add(Restrictions.gt("date", startDate.toDateTime()));
    } else if (endDate != null) {
        c.add(Restrictions.lt("date", endDate.toDateTime()));
    }

    c.addOrder(Order.asc("date"));

    return getHibernateTemplate().findByCriteria(c);
}