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:dk.teachus.backend.dao.hibernate.HibernateBookingDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)/*  w  w w  . ja  va2  s  . co  m*/
public List<PupilBooking> getUnPaidBookings(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", false));
    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);
}

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

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)//from  w w  w. j a v a 2  s .co m
public Bookings getBookings(Teacher teacher, DateMidnight fromDate, DateMidnight toDate) {
    DetachedCriteria c = DetachedCriteria.forClass(BookingImpl.class);

    DateTime start = fromDate.toDateTime().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0)
            .withMillisOfSecond(0);
    DateTime end = toDate.toDateTime().withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59)
            .withMillisOfSecond(999);

    c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL));
    c.createCriteria("teacher").add(Restrictions.eq("active", true));
    c.add(Restrictions.eq("teacher", teacher));
    c.add(Restrictions.between("date", start, end));
    c.add(Restrictions.eq("active", true));

    c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);

    List<Booking> bookings = getHibernateTemplate().findByCriteria(c);
    List<Booking> filteredBookings = filterBookings(bookings);

    return new BookingsImpl(filteredBookings);
}

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

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)/*from  w w w  .  j ava 2s . c  om*/
public List<PupilBooking> getAllBookings(DateMidnight fromDate, DateMidnight toDate) {
    DetachedCriteria c = DetachedCriteria.forClass(PupilBookingImpl.class);
    c.createCriteria("pupil").add(Restrictions.eq("active", true));
    c.createCriteria("teacher").add(Restrictions.eq("active", true));
    c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL));
    Disjunction disjunction = Restrictions.disjunction();
    disjunction.add(Restrictions.and(Restrictions.ge("createDate", fromDate.toDateTime()),
            Restrictions.le("createDate", toDate.toDateTime())));
    disjunction.add(Restrictions.and(Restrictions.ge("updateDate", fromDate.toDateTime()),
            Restrictions.le("updateDate", toDate.toDateTime())));
    c.add(disjunction);

    c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);

    List<PupilBooking> bookings = getHibernateTemplate().findByCriteria(c);

    return bookings;
}

From source file:net.naonedbus.bean.horaire.EmptyHoraire.java

License:Open Source License

public EmptyHoraire(final int textId, final DateMidnight date) {
    mTextId = textId;/*from w  ww . ja  v a 2  s . c om*/
    setJour(date);
    setHoraire(date.toDateTime());
    setSection(date);
}

From source file:op.care.dfn.PnlDFN.java

License:Open Source License

private java.util.List<Component> addCommands() {

    java.util.List<Component> list = new ArrayList<Component>();

    /***/*from  w  ww .j a  v a 2  s  . c o  m*/
     *      _     _            _       _     _
     *     | |__ | |_ _ __    / \   __| | __| |
     *     | '_ \| __| '_ \  / _ \ / _` |/ _` |
     *     | |_) | |_| | | |/ ___ \ (_| | (_| |
     *     |_.__/ \__|_| |_/_/   \_\__,_|\__,_|
     *
     */
    if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) {

        final JideButton btnAdd = GUITools.createHyperlinkButton(SYSTools.xx("nursingrecords.dfn.btnadd"),
                SYSConst.icon22add, null);
        btnAdd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                if (!resident.isActive()) {
                    OPDE.getDisplayManager()
                            .addSubMessage(new DisplayMessage("misc.msg.cantChangeInactiveResident"));
                    return;
                }

                final JidePopup popup = new JidePopup();
                popup.setMovable(false);
                PnlSelectIntervention pnl = new PnlSelectIntervention(new Closure() {
                    @Override
                    public void execute(Object o) {
                        popup.hidePopup();
                        if (o != null) {
                            Object[] objects = (Object[]) o;
                            EntityManager em = OPDE.createEM();
                            try {
                                em.getTransaction().begin();
                                em.lock(em.merge(resident), LockModeType.OPTIMISTIC);

                                for (Object obj : objects) {
                                    Intervention intervention = em.merge((Intervention) obj);
                                    DFN dfn = em.merge(new DFN(resident, intervention));

                                    // Set Target and Actual according to the setting of JDCDate
                                    DateTime now = new DateTime();
                                    DateMidnight onDemandPIT = new DateMidnight(jdcDate.getDate());
                                    DateTime newDateTime = onDemandPIT.toDateTime()
                                            .plusHours(now.getHourOfDay()).plusMinutes(now.getMinuteOfHour())
                                            .plusSeconds(now.getSecondOfMinute());
                                    dfn.setSoll(newDateTime.toDate());
                                    dfn.setIst(newDateTime.toDate());

                                    CollapsiblePane cp1 = createCP4(dfn);
                                    synchronized (mapDFN2Pane) {
                                        mapDFN2Pane.put(dfn, cp1);
                                    }
                                    synchronized (mapShift2DFN) {
                                        mapShift2DFN.get(dfn.getShift()).add(dfn);
                                    }
                                }

                                em.getTransaction().commit();

                                CollapsiblePane cp2 = createCP4(DFNTools.SHIFT_ON_DEMAND);
                                synchronized (mapShift2Pane) {
                                    mapShift2Pane.put(DFNTools.SHIFT_ON_DEMAND, cp2);
                                }
                                buildPanel(false);
                                try {
                                    synchronized (mapShift2Pane) {
                                        mapShift2Pane.get(DFNTools.SHIFT_ON_DEMAND).setCollapsed(false);
                                    }
                                } catch (PropertyVetoException e) {
                                    OPDE.debug(e);
                                }

                            } catch (OptimisticLockException ole) {
                                OPDE.warn(ole);
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                    OPDE.getMainframe().emptyFrame();
                                    OPDE.getMainframe().afterLogin();
                                }
                                OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                            } catch (Exception e) {
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                OPDE.fatal(e);
                            } finally {
                                em.close();
                            }
                        }
                    }
                });
                popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS));
                popup.getContentPane().add(pnl);
                popup.setOwner(btnAdd);
                popup.removeExcludedComponent(pnl);
                popup.setDefaultFocusComponent(pnl);
                GUITools.showPopup(popup, SwingConstants.NORTH);
            }
        });
        list.add(btnAdd);

    }

    final JideButton printPrescription = GUITools.createHyperlinkButton("nursingrecords.dfn.print",
            SYSConst.icon22print2, new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent actionEvent) {

                    String html = "";

                    synchronized (mapShift2DFN) {
                        html += "<h1 id=\"fonth1\" >" + ResidentTools.getFullName(resident) + "</h1>";
                        html += SYSConst.html_h2(SYSTools.xx("nursingrecords.bhp") + ": "
                                + SYSConst.html_bold(DateFormat.getDateInstance().format(jdcDate.getDate())));

                        for (Byte shift : new Byte[] { DFNTools.SHIFT_ON_DEMAND, DFNTools.SHIFT_VERY_EARLY,
                                DFNTools.SHIFT_EARLY, DFNTools.SHIFT_LATE, DFNTools.SHIFT_VERY_LATE }) {
                            html += DFNTools.getDFNsAsHTMLtable(mapShift2DFN.get(shift));
                        }
                    }

                    SYSFilesTools.print(html, true);
                }
            });
    list.add(printPrescription);
    return list;
}

From source file:org.apereo.portal.events.aggr.dao.jpa.AcademicTermDetailImpl.java

License:Apache License

public AcademicTermDetailImpl(DateMidnight start, DateMidnight end, String termName) {
    Validate.notNull(start);/*from  w  w w  . j  a va  2 s  .  co m*/
    Validate.notNull(end);
    Validate.notNull(termName);
    if (start.isEqual(end) || end.isBefore(start)) {
        throw new IllegalArgumentException("end cannot be before or equal to start");
    }
    this.id = -1;
    this.start = start.toDateTime();
    this.end = end.toDateTime();
    this.termName = termName;
    this.init();
}

From source file:org.apereo.portal.events.aggr.dao.jpa.AcademicTermDetailImpl.java

License:Apache License

@Override
public void setStart(DateMidnight start) {
    this.startDateMidnight = start;
    this.start = start.toDateTime();
}

From source file:org.apereo.portal.events.aggr.dao.jpa.AcademicTermDetailImpl.java

License:Apache License

@Override
public void setEnd(DateMidnight end) {
    this.endDateMidnight = end;
    this.end = end.toDateTime();
}

From source file:org.apereo.portal.portlets.statistics.BaseStatisticsReportController.java

License:Apache License

/** Build the aggregation {@link DataTable} */
protected final DataTable buildAggregationReport(F form) throws TypeMismatchException {
    //Pull data out of form for per-group fetching
    final AggregationInterval interval = form.getInterval();
    final DateMidnight start = form.getStart();
    final DateMidnight end = form.getEnd();

    final DateTime startDateTime = start.toDateTime();
    //Use a query end of the end date at 23:59:59
    final DateTime endDateTime = end.plusDays(1).toDateTime().minusSeconds(1);

    //Get the list of DateTimes used on the X axis in the report
    final List<DateTime> reportTimes = this.intervalHelper.getIntervalStartDateTimesBetween(interval,
            startDateTime, endDateTime, maxIntervals);

    final Map<D, SortedSet<T>> groupedAggregations = createColumnDiscriminatorMap(form);

    //Determine the ValueType of the date/time column. Use the most specific column type possible
    final ValueType dateTimeColumnType;
    if (interval.isHasTimePart()) {
        //If start/end are the same day just display the time
        if (startDateTime.toDateMidnight().equals(endDateTime.toDateMidnight())) {
            dateTimeColumnType = ValueType.TIMEOFDAY;
        }//from   www  .j a va 2  s  .  c  o  m
        //interval has time data and start/end are on different days, show full date time
        else {
            dateTimeColumnType = ValueType.DATETIME;
        }
    }
    //interval is date only
    else {
        dateTimeColumnType = ValueType.DATE;
    }

    //Setup the date/time column description
    final ColumnDescription dateTimeColumn;
    switch (dateTimeColumnType) {
    case TIMEOFDAY: {
        dateTimeColumn = new ColumnDescription("time", dateTimeColumnType, "Time");
        break;
    }
    default: {
        dateTimeColumn = new ColumnDescription("date", dateTimeColumnType, "Date");
    }
    }

    final DataTable table = new JsonDataTable();
    table.addColumn(dateTimeColumn);

    //Setup columns in the DataTable
    final Set<D> columnGroups = groupedAggregations.keySet();
    for (final D columnMapping : columnGroups) {
        final Collection<ColumnDescription> columnDescriptions = this.getColumnDescriptions(columnMapping,
                form);
        table.addColumns(columnDescriptions);
    }

    //Query for all aggregation data in the time range for all groups.  Only the
    //interval and discriminator data is used from the keys.
    final Set<K> keys = createAggregationsQueryKeyset(columnGroups, form);
    final BaseAggregationDao<T, K> baseAggregationDao = this.getBaseAggregationDao();
    final Collection<T> aggregations = baseAggregationDao.getAggregations(startDateTime, endDateTime, keys,
            extractGroupsArray(columnGroups));

    //Organize the results by group and sort them chronologically by adding them to the sorted set
    for (final T aggregation : aggregations) {
        final D discriminator = aggregation.getAggregationDiscriminator();
        final SortedSet<T> results = groupedAggregations.get(discriminator);
        results.add(aggregation);
    }

    //Build Map from discriminator column mapping to result iterator to allow putting results into
    //the correct column AND the correct time slot in the column
    Comparator<? super D> comparator = getDiscriminatorComparator();
    final Map<D, PeekingIterator<T>> groupedAggregationIterators = new TreeMap<D, PeekingIterator<T>>(
            (comparator));
    for (final Entry<D, SortedSet<T>> groupedAggregationEntry : groupedAggregations.entrySet()) {
        groupedAggregationIterators.put(groupedAggregationEntry.getKey(),
                Iterators.peekingIterator(groupedAggregationEntry.getValue().iterator()));
    }

    /*
     * populate the data, filling in blank spots. The full list of interval DateTimes is used to create every row in the
     * query range. Then the iterator
     */
    for (final DateTime rowTime : reportTimes) {
        // create the row
        final TableRow row = new TableRow();

        // add the date to the first cell
        final Value dateTimeValue;
        switch (dateTimeColumnType) {
        case DATE: {
            dateTimeValue = new DateValue(rowTime.getYear(), rowTime.getMonthOfYear() - 1,
                    rowTime.getDayOfMonth());
            break;
        }
        case TIMEOFDAY: {
            dateTimeValue = new TimeOfDayValue(rowTime.getHourOfDay(), rowTime.getMinuteOfHour(), 0);
            break;
        }
        default: {
            dateTimeValue = new DateTimeValue(rowTime.getYear(), rowTime.getMonthOfYear() - 1,
                    rowTime.getDayOfMonth(), rowTime.getHourOfDay(), rowTime.getMinuteOfHour(), 0, 0);
            break;
        }
        }
        row.addCell(new TableCell(dateTimeValue));

        for (final PeekingIterator<T> groupedAggregationIteratorEntry : groupedAggregationIterators.values()) {
            List<Value> values = null;

            if (groupedAggregationIteratorEntry.hasNext()) {
                final T aggr = groupedAggregationIteratorEntry.peek();
                if (rowTime.equals(aggr.getDateTime())) {
                    //Data is for the correct time slot, advance the iterator
                    groupedAggregationIteratorEntry.next();

                    values = createRowValues(aggr, form);
                }
            }

            //Gap in the data, fill it in using a null aggregation
            if (values == null) {
                values = createRowValues(null, form);
            }

            //Add the values to the row
            for (final Value value : values) {
                row.addCell(value);
            }
        }

        table.addRow(row);
    }

    return table;
}

From source file:org.apereo.portal.portlets.statistics.StatisticsPortletController.java

License:Apache License

@ResourceMapping("intervalCount")
public ModelAndView getIntervalCount(@RequestParam("interval") AggregationInterval interval,
        @RequestParam("start") DateMidnight start, @RequestParam("end") DateMidnight end)
        throws TypeMismatchException {
    final int intervalsBetween = this.intervalHelper.intervalsBetween(interval, start.toDateTime(),
            end.plusDays(1).toDateTime().minusSeconds(1));
    return new ModelAndView("json", "intervalsBetween", intervalsBetween);
}