Example usage for org.joda.time LocalDate toDate

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

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public Date toDate() 

Source Link

Document

Get the date time as a java.util.Date.

Usage

From source file:$.MessageController.java

License:Apache License

@RequestMapping(value = "/{msgId}/log", method = RequestMethod.GET)
    public String getLogOfMsgByMsgId(@PathVariable("msgId") Long msgId, Model model) {
        Message msg = messageService.findMessageById(msgId);

        model.addAttribute("requestMsgId", msgId);

        if (msg != null) {
            String correlationId = msg.getCorrelationId();

            model.addAttribute("correlationId", correlationId);

            List<String> logLines = new ArrayList<String>();
            try {
                long start = System.currentTimeMillis();
                SortedSet<LocalDate> logDates = getMsgDates(msg);
                logDates.add(new LocalDate()); // adding today just in case

                Log.debug("Starts searching log for correlationId = " + correlationId);

                for (LocalDate logDate : logDates) {
                    logLines.addAll(messageLogParser.getLogLines(correlationId, logDate.toDate()));
                }//  www  .j a v  a  2 s .c  o  m

                Log.debug("Finished searching log in " + (System.currentTimeMillis() - start) + " ms.");

                model.addAttribute("log", StringUtils.join(logLines, "${symbol_escape}n"));
            } catch (IOException ex) {
                model.addAttribute("logErr", "Error occurred during reading log file: " + ex.getMessage());
            }
        }

        return "msgLog";
    }

From source file:at.jclehner.rxdroid.db.Drug.java

License:Open Source License

public void setExpiryDate(LocalDate date) {
    expirationDate = date != null ? date.toDate() : null;
}

From source file:at.jclehner.rxdroid.db.Drug.java

License:Open Source License

public void setScheduleEndDate(LocalDate date) {
    scheduleEndDate = date != null ? date.toDate() : null;
}

From source file:at.jclehner.rxdroid.db.Drug.java

License:Open Source License

public LocalDate getNextScheduledDate(LocalDate reference) {
    if (repeatMode == REPEAT_DAILY)
        return reference;

    final int maxLoopDays;

    if (repeatMode == REPEAT_21_7)
        maxLoopDays = 28;// ww  w .jav  a 2 s.c om
    else if (repeatMode == REPEAT_EVERY_N_DAYS)
        maxLoopDays = (int) repeatArg;
    else if (repeatMode == REPEAT_WEEKDAYS)
        maxLoopDays = 7;
    else
        throw new UnsupportedOperationException("repeatMode=" + repeatMode);

    for (int i = 0; i != maxLoopDays; ++i) {
        final LocalDate date = reference.plusDays(i);
        if (hasDoseOnDate(date.toDate()))
            return date;
    }

    return null;
}

From source file:at.jclehner.rxdroid.DrugEditFragment.java

License:Open Source License

private boolean fixInvalidRepeatOrigin(Drug drug, LocalDate reference) {
    if (reference == null)
        return false;

    final Date invalidRepeatOrigin = drug.getRepeatOrigin();

    for (int i = 0; i != 2; ++i) {
        final LocalDate date = reference.plusDays(i);
        if (drug.hasDoseOnDate(date.toDate())) {
            updateRepeatOrigin(drug, date);
            Log.i(TAG, "Updated invalid repeatOrigin: " + drug.getRepeatOrigin());
            return true;
        }//from w  w w. j a v  a  2  s . co  m
    }

    try {
        Reflect.setFieldValue(Drug.class.getDeclaredField("repeatOrigin"), drug, invalidRepeatOrigin);
    } catch (NoSuchFieldException e) {
        throw new WrappedCheckedException(e);
    }

    return false;
}

From source file:at.jclehner.rxdroid.DrugEditFragment.java

License:Open Source License

private void updateRepeatOrigin(Drug drug, LocalDate repeatOrigin) {
    final Date scheduleBegin = drug.getLastScheduleUpdateDate();
    drug.setRepeatOrigin(repeatOrigin.toDate());
    drug.setLastScheduleUpdateDate(scheduleBegin);

    Database.update(drug);/*  ww  w  .  jav a2s  .c om*/
}

From source file:at.jclehner.rxdroid.ui.DoseLogFragment.java

License:Open Source License

private void gatherEventInfos(int flags) {
    final Timer t;
    if (LOGV)//from  ww  w .  ja v  a  2  s  . co m
        t = new Timer();
    else
        t = null;

    final Drug drug = getDrug();
    final List<EventInfo> infos = new ArrayList<EventInfo>();
    final List<DoseEvent> events = Entries.findDoseEvents(drug, null, null);

    for (DoseEvent event : events) {
        boolean isSkipped = event.getDose().isZero();

        if ((isSkipped && (flags & SHOW_SKIPPED) == 0) || (!isSkipped && (flags & SHOW_TAKEN) == 0)) {
            continue;
        }

        infos.add(EventInfo.newTakenOrIgnoredEvent(event));
    }

    Date date = Settings.getDate(Keys.OLDEST_POSSIBLE_DOSE_EVENT_TIME);

    if (date != null && !events.isEmpty()) {
        Collections.sort(infos, EventInfoByDateComparator.INSTANCE);
        date = DateTime.max(date, Settings.getOldestPossibleHistoryDate(mToday));
        date = DateTime.min(date, events.get(events.size() - 1).getDate());
    } else if (date == null)
        date = Settings.getOldestPossibleHistoryDate(mToday);

    final Date lastScheduleUpdateDate = drug.getLastScheduleUpdateDate();

    if (date == null) {
        if ((date = lastScheduleUpdateDate) == null) {
            Log.w(TAG, "gatherEventInfos(" + flags + "): no date to begin; giving up");
            return;
        }
    }

    //      final Date lastDosesClearedDate = drug.getLastDosesClearedDate();
    //      if(lastDosesClearedDate != null)
    //      {
    //         while(!date.after(lastDosesClearedDate))
    //            date = DateTime.add(date, Calendar.DAY_OF_MONTH, 1);
    //      }

    final DoseTimeInfo dtInfo = Settings.getDoseTimeInfo();

    if ((flags & SHOW_MISSED) != 0) {
        final LocalDate scheduleEnd = drug.getScheduleEndDate();
        final Date lastDate = scheduleEnd != null ? scheduleEnd.toDate() : mToday;

        while (!date.after(lastDate)) {
            if (lastScheduleUpdateDate == null || !date.before(lastScheduleUpdateDate)) {
                if (drug.hasDoseOnDate(date)) {
                    for (int doseTime : Constants.DOSE_TIMES) {
                        if (date.equals(mToday) && doseTime == dtInfo.activeOrNextDoseTime())
                            break;

                        Fraction dose = drug.getDose(doseTime, date);

                        if (!dose.isZero() && !containsDoseEvent(events, date, doseTime)) {
                            //Log.d(TAG, "Creating missed event: date=" + date + ", doseTime=" + doseTime);
                            infos.add(EventInfo.newMissedEvent(date, doseTime, dose));
                        }
                    }
                }
            }

            date = DateTime.add(date, Calendar.DAY_OF_MONTH, 1);
        }
    }

    Collections.sort(infos, EventInfoByDateComparator.INSTANCE);

    mGroupedEvents = new ArrayList<List<EventInfo>>();

    for (int i = 0; i < infos.size();) {
        date = infos.get(i).date;

        List<EventInfo> group = new ArrayList<EventInfo>();

        while (i < infos.size() && date.equals(infos.get(i).date)) {
            //Log.d(TAG, "  CHILD: " + events.get(i));
            group.add(infos.get(i));
            ++i;
        }

        if (!group.isEmpty()) {
            Collections.sort(group, EventInfoByDoseTimeComparator.INSTANCE);
            mGroupedEvents.add(group);
        }

        // if i == infos.size() this is the last entry, in which case it's not
        // neccessary to confuse the user with the lastScheduleUpdateDate message
        // (it only matters if taken doses exist before this date)
        if (date.equals(lastScheduleUpdateDate) && i != infos.size()) {
            group = new ArrayList<EventInfo>();
            group.add(EventInfo.newScheduleUpdatedEvent(date));
            mGroupedEvents.add(group);
        }
    }

    if (LOGV)
        Log.d(TAG, "gatherEvents: " + t);
}

From source file:br.com.objectos.comuns.relational.jdbc.ParamLocalDate.java

License:Apache License

@Override
void setValue(Stmt stmt) {
    LocalDate date = value;
    stmt.setDate(index, date.toDate());
}

From source file:ca.ualberta.physics.cssdp.dao.type.PersistentLocalDate.java

License:Apache License

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    if (value != null) {
        LocalDate localDate = (LocalDate) value;
        Date date = new Date(localDate.toDate().getTime());
        st.setDate(index, date);/*from  www.  j a  va 2s  .c o  m*/
    } else {
        st.setObject(index, null);
    }

}

From source file:candlelight.joda.converters.JodaLocalDateConverter.java

License:Apache License

public Date convertToDatabaseColumn(LocalDate localDate) {
    return localDate.toDate();
}