Example usage for org.joda.time DateTime toLocalTime

List of usage examples for org.joda.time DateTime toLocalTime

Introduction

In this page you can find the example usage for org.joda.time DateTime toLocalTime.

Prototype

public LocalTime toLocalTime() 

Source Link

Document

Converts this object to a LocalTime with the same time and chronology.

Usage

From source file:dk.teachus.backend.domain.impl.PeriodImpl.java

License:Apache License

public boolean isTimeValid(DateTime dateTime) {
    return isTimeValid(dateTime.toLocalTime());
}

From source file:dk.teachus.backend.domain.impl.PeriodImpl.java

License:Apache License

public boolean mayBook(DateTime dateTime) {
    return mayBook(dateTime.toLocalTime());
}

From source file:dk.teachus.frontend.components.calendar.PeriodsCalendarPanel.java

License:Apache License

@Override
protected IModel<List<TimeSlot<PeriodBookingTimeSlotPayload>>> getTimeSlotModel(final DateMidnight date) {
    return new AbstractReadOnlyModel<List<TimeSlot<PeriodBookingTimeSlotPayload>>>() {
        private static final long serialVersionUID = 1L;

        @Override/* ww w  .j av a  2s.  c om*/
        public List<TimeSlot<PeriodBookingTimeSlotPayload>> getObject() {
            List<TimeSlot<PeriodBookingTimeSlotPayload>> timeSlots = new ArrayList<TimeSlot<PeriodBookingTimeSlotPayload>>();
            List<DatePeriod> periods = datePeriodsModel.getObject();
            DatePeriod currentDatePeriod = null;
            for (DatePeriod datePeriod : periods) {
                if (datePeriod.getDate().equals(date)) {
                    currentDatePeriod = datePeriod;
                    break;
                }
            }

            if (currentDatePeriod != null) {
                List<Period> periodsList = currentDatePeriod.getPeriods();
                for (Period period : periodsList) {
                    DateTime startTime = period.getStartTime().toDateTime(date);
                    DateTime endTime = period.getEndTime().toDateTime(date);

                    DateTime time = startTime;
                    while (time.isBefore(endTime)) {
                        /*
                         * Booking
                         */
                        Bookings bookings = bookingsModel.getObject();
                        Booking booking = bookings.getBooking(period, time);

                        PeriodBookingTimeSlotPayload payload = new PeriodBookingTimeSlotPayload();
                        payload.setPeriod(period);
                        payload.setBooking(booking);

                        timeSlots.add(new TimeSlot<PeriodBookingTimeSlotPayload>(time.toLocalTime(),
                                time.toLocalTime().plusMinutes(period.getLessonDuration()), payload));

                        time = time.plusMinutes(period.getIntervalBetweenLessonStart());
                    }
                }
            }

            return timeSlots;
        }

        @Override
        public void detach() {
            datePeriodsModel.detach();
            bookingsModel.detach();
        }
    };
}

From source file:es.usc.citius.servando.calendula.activities.ConfirmSchedulesActivity.java

License:Open Source License

public void createSchedule(final Schedule s, List<ScheduleItem> items, Medicine m) {

    // save schedule
    s.setMedicine(m);//from w ww.  j a va  2  s  .com
    s.setPatient(patient);
    s.setScanned(true);
    s.save();
    Log.d(TAG, "Saving schedule..." + s.toString());

    if (!s.repeatsHourly()) {
        for (ScheduleItem item : items) {
            item.setSchedule(s);
            item.save();
            Log.d(TAG, "Saving item..." + item.getId());
            // add to daily schedule
            DailyAgenda.instance().addItem(patient, item, false);
        }
    } else {
        for (DateTime time : s.hourlyItemsToday()) {
            LocalTime timeToday = time.toLocalTime();
            DailyAgenda.instance().addItem(patient, s, timeToday);
        }
    }
    // save and fire event
    DB.schedules().saveAndFireEvent(s);
    AlarmScheduler.instance().onCreateOrUpdateSchedule(s, ConfirmSchedulesActivity.this);
}

From source file:es.usc.citius.servando.calendula.activities.ConfirmSchedulesActivity.java

License:Open Source License

public void updateSchedule(final Schedule s, final Schedule current, List<ScheduleItem> items) {

    s.setType(current.type());/*from   w w w .  j  a v  a  2  s.  c o m*/
    s.setDays(current.days());
    s.setDose(current.dose());
    s.setStart(current.start());
    s.setRepetition(current.rule());
    s.setCycle(current.getCycleDays(), current.getCycleRest());
    s.setStartTime(current.startTime());

    List<Long> routinesTaken = new ArrayList<Long>();

    if (!s.repeatsHourly()) {
        for (ScheduleItem item : s.items()) {
            DailyScheduleItem d = DailyScheduleItem.findByScheduleItem(item);
            // if taken today, add to the list
            if (d != null && d.takenToday()) {
                routinesTaken.add(item.routine().getId());
            }
            item.deleteCascade();
        }

        // save new items
        for (ScheduleItem i : items) {
            ScheduleItem item = new ScheduleItem();
            item.setDose(i.dose());
            item.setRoutine(i.routine());
            item.setSchedule(s);
            item.save();
            // add to daily schedule
            DailyScheduleItem dsi = new DailyScheduleItem(item);
            dsi.setPatient(patient);
            if (routinesTaken.contains(item.routine().getId())) {
                dsi.setTakenToday(true);
            }
            dsi.save();
        }
    } else {
        DB.dailyScheduleItems().removeAllFrom(s);
        for (DateTime time : s.hourlyItemsToday()) {
            LocalTime timeToday = time.toLocalTime();
            DailyScheduleItem dsi = new DailyScheduleItem(s, timeToday);
            dsi.setPatient(patient);
            dsi.save();
            Log.d(TAG, "Saving daily schedule item..." + dsi.getId() + " timeToday: "
                    + timeToday.toString("kk:mm"));
        }
    }
    // save and fire event
    DB.schedules().saveAndFireEvent(s);
    AlarmScheduler.instance().onCreateOrUpdateSchedule(s, ConfirmSchedulesActivity.this);
}

From source file:es.usc.citius.servando.calendula.activities.ScheduleCreationActivity.java

License:Open Source License

public void createSchedule() {
    try {//  ww w.j  a  va2 s  .  c  o  m

        final Schedule s = ScheduleHelper.instance().getSchedule();

        TransactionManager.callInTransaction(DB.helper().getConnectionSource(), new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                // save schedule
                final Patient patient = DB.patients().getActive(getBaseContext());
                s.setMedicine(ScheduleHelper.instance().getSelectedMed());
                s.setPatient(patient);
                s.save();

                Log.d(TAG, "Saving schedule..." + s.toString());

                if (!s.repeatsHourly()) {
                    for (ScheduleItem item : ScheduleHelper.instance().getScheduleItems()) {
                        item.setSchedule(s);
                        item.save();
                        Log.d(TAG, "Saving item..." + item.getId());
                        // add to daily schedule
                        DailyAgenda.instance().addItem(patient, item, false);
                    }
                } else {
                    for (DateTime time : s.hourlyItemsToday()) {
                        LocalTime timeToday = time.toLocalTime();
                        DailyAgenda.instance().addItem(patient, s, timeToday);
                    }
                }
                // save and fire event
                DB.schedules().saveAndFireEvent(s);
                return null;
            }
        });

        ScheduleHelper.instance().clear();
        AlarmScheduler.instance().onCreateOrUpdateSchedule(s, ScheduleCreationActivity.this);
        Log.d(TAG, "Schedule saved successfully!");
        Snack.show(R.string.schedule_created_message, this);
        CalendulaApp.eventBus().post(PersistenceEvents.SCHEDULE_EVENT);
        finish();
    } catch (Exception e) {
        Snack.show("Error creating schedule", this);
        e.printStackTrace();
    }
}

From source file:es.usc.citius.servando.calendula.activities.ScheduleCreationActivity.java

License:Open Source License

public void updateSchedule() {
    try {/*  ww w  . jav  a 2  s . com*/
        final Schedule s = mSchedule;

        TransactionManager.callInTransaction(DB.helper().getConnectionSource(), new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                // save schedule

                s.setMedicine(ScheduleHelper.instance().getSelectedMed());
                final Patient patient = s.patient();

                List<Long> routinesTaken = new ArrayList<Long>();

                if (!s.repeatsHourly()) {
                    // remove days if changed
                    boolean[] days = s.days();
                    for (DailyScheduleItem dsi : DB.dailyScheduleItems().findBySchedule(s)) {
                        if (days[dsi.date().getDayOfWeek() - 1]) {
                            DB.dailyScheduleItems().remove(dsi);
                        }
                    }

                    for (ScheduleItem item : s.items()) {
                        DailyScheduleItem d = DailyScheduleItem.findByScheduleItem(item);
                        // if taken today, add to the list
                        if (d != null && d.takenToday()) {
                            routinesTaken.add(item.routine().getId());
                        }
                        item.deleteCascade();
                    }

                    // save new items
                    for (ScheduleItem i : ScheduleHelper.instance().getScheduleItems()) {

                        ScheduleItem item = new ScheduleItem();
                        item.setDose(i.dose());
                        item.setRoutine(i.routine());
                        item.setSchedule(s);
                        item.save();
                        // add to daily schedule
                        DailyAgenda.instance().addItem(patient, item,
                                routinesTaken.contains(item.routine().getId()));
                    }
                } else {
                    DB.dailyScheduleItems().removeAllFrom(s);
                    for (DateTime time : s.hourlyItemsToday()) {
                        LocalTime timeToday = time.toLocalTime();
                        DailyAgenda.instance().addItem(patient, s, timeToday);
                    }
                }

                // save and fire event
                DB.schedules().saveAndFireEvent(s);
                return null;
            }
        });

        ScheduleHelper.instance().clear();
        AlarmScheduler.instance().onCreateOrUpdateSchedule(s, ScheduleCreationActivity.this);
        Log.d(TAG, "Schedule saved successfully!");
        Toast.makeText(this, R.string.schedule_created_message, Toast.LENGTH_SHORT).show();
        finish();
    } catch (Exception e) {
        Toast.makeText(this, "Error creating schedule!", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
}

From source file:es.usc.citius.servando.calendula.scheduling.AlarmScheduler.java

License:Open Source License

private void setAlarmsIfNeeded(Schedule schedule, LocalDate date, Context ctx) {
    if (!schedule.repeatsHourly()) {
        for (ScheduleItem scheduleItem : schedule.items()) {
            if (scheduleItem.routine() != null
                    && canBeScheduled(scheduleItem.routine().time().toDateTimeToday(), ctx)) {
                setFirstAlarm(scheduleItem.routine(), date, ctx);
            }// ww w  .  j  ava 2s. c o  m
        }
    } else {
        List<DateTime> times = schedule.hourlyItemsAt(date.toDateTimeAtStartOfDay());
        for (DateTime time : times) {
            if (canBeScheduled(time, ctx)) {
                setFirstAlarm(schedule, time.toLocalTime(), date, ctx);
            }
        }
    }
}

From source file:es.usc.citius.servando.calendula.scheduling.DailyAgenda.java

License:Open Source License

public void createScheduleForDate(LocalDate date) {

    Log.d(TAG, "Adding DailyScheduleItem to daily schedule for date: " + date.toString("dd/MM"));
    int items = 0;
    // create a list with all day doses for schedules bound to routines
    for (Routine r : Routine.findAll()) {
        for (ScheduleItem s : r.scheduleItems()) {
            if (s.schedule().enabledForDate(date)) {
                // create a dailyScheduleItem and save it
                DailyScheduleItem dsi = new DailyScheduleItem(s);
                dsi.setPatient(s.schedule().patient());
                dsi.setDate(date);//from w  w  w . j  ava 2 s  . c o m
                dsi.save();
                items++;
            }
        }
    }
    // Do the same for hourly schedules
    for (Schedule s : DB.schedules().findHourly()) {
        // create an schedule item for each repetition today
        for (DateTime time : s.hourlyItemsAt(date.toDateTimeAtStartOfDay())) {
            LocalTime timeToday = time.toLocalTime();
            DailyScheduleItem dsi = new DailyScheduleItem(s, timeToday);
            dsi.setPatient(s.patient());
            dsi.setDate(date);
            dsi.save();
        }
    }
    Log.d(TAG, items + " items added to daily schedule");
}

From source file:name.martingeisse.wicket.panel.simple.DateTimeTextFieldPanel.java

License:Open Source License

@Override
protected void onBeforeRender() {
    final Class<?> modelType = getType();
    final Object modelObject = getDefaultModelObject();
    if (modelType == DateTime.class) {
        final DateTime modelDateTime = (DateTime) modelObject;
        originalChronology = modelDateTime.getChronology();
        localizedChronology = originalChronology.withZone(MyWicketSession.get().getTimeZone());
        final DateTime localizedModelDateTime = modelDateTime.withChronology(localizedChronology);
        date = localizedModelDateTime.toLocalDate();
        time = localizedModelDateTime.toLocalTime();
    } else if (modelType == LocalDateTime.class) {
        final LocalDateTime modelDateTime = (LocalDateTime) modelObject;
        originalChronology = modelDateTime.getChronology();
        localizedChronology = originalChronology;
        date = modelDateTime.toLocalDate();
        time = modelDateTime.toLocalTime();
    } else {//w  w  w  .  j  a v a2  s.c  o m
        throw new IllegalStateException("unsupported model type for DateTimeTextFieldPanel: " + modelType);
    }
    super.onBeforeRender();
}