List of usage examples for org.joda.time LocalDate toDateTimeAtStartOfDay
public DateTime toDateTimeAtStartOfDay()
From source file:es.collectserv.handler.LocalDateTypeHandler.java
License:Apache License
public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException { LocalDate date = (LocalDate) parameter; if (date != null) { ps.setDate(i, new Date(date.toDateTimeAtStartOfDay().toDate().getTime())); } else {/*from w w w .j av a 2 s. c om*/ ps.setDate(i, null); } }
From source file:es.usc.citius.servando.calendula.activities.CalendarActivity.java
License:Open Source License
private boolean onDaySelected(LocalDate date) { selectedDate = date.toDateTimeAtStartOfDay().toDate(); return showPickupsInfo(date); }
From source file:es.usc.citius.servando.calendula.activities.SummaryCalendarActivity.java
License:Open Source License
private void setupCalendar() { calendar = (CalendarPickerView) findViewById(R.id.calendar_view); calendar.setVerticalScrollBarEnabled(false); RepetitionRule r;// w ww . j a va2s . co m String rule = getIntent().getStringExtra("rule"); String date = getIntent().getStringExtra("start"); int activeDays = getIntent().getIntExtra("active_days", -1); int restDays = getIntent().getIntExtra("rest_days", -1); LocalDate from = date != null ? LocalDate.parse(date, fmt) : LocalDate.now(); LocalDate to = from.plusMonths(6); if (rule != null) { r = new RepetitionRule(rule); List<DateTime> dates = r.occurrencesBetween(from.toDateTimeAtStartOfDay(), to.toDateTimeAtStartOfDay(), from.toDateTimeAtStartOfDay()); Set<Date> hdates = new HashSet<>(); for (DateTime d : dates) hdates.add(d.toDate()); List<CalendarCellDecorator> decorators = new ArrayList<>(); DateValue v = r.iCalRule().getUntil(); Date start = date != null ? from.toDate() : null; Date end = v != null ? new LocalDate(v.year(), v.month(), v.day()).toDate() : null; decorators.add(new HighlightDecorator(new ArrayList<>(hdates), start, end, color)); calendar.setDecorators(decorators); } else if (activeDays > 0 && restDays > 0) { List<Date> hdates = new ArrayList<>(); LocalDate d = from.plusDays(0); // copy while (d.isBefore(to)) { if (ScheduleHelper.cycleEnabledForDate(d, from, activeDays, restDays)) { hdates.add(d.toDate()); } d = d.plusDays(1); } List<CalendarCellDecorator> decorators = new ArrayList<>(); //DateValue v = r.iCalRule().getUntil(); //Date start = date != null ? from.toDate() : null; //Date end = v != null ? new LocalDate(v.year(), v.month(), v.day()).toDate() : null; decorators.add(new HighlightDecorator(hdates, from.toDate(), to.toDate(), color)); calendar.setDecorators(decorators); } calendar.init(from.toDate(), to.toDate()) .setShortWeekdays(getResources().getStringArray(R.array.calendar_weekday_names)); }
From source file:es.usc.citius.servando.calendula.persistence.Schedule.java
License:Open Source License
public boolean enabledForDate(LocalDate date) { if (type == SCHEDULE_TYPE_CYCLE) { return cycleEnabledForDate(date); } else {/*from w ww.j a v a 2 s . com*/ DateTime dt = date.toDateTimeAtStartOfDay(); List<DateTime> occurrences = rrule.occurrencesBetween(dt, dt.plusDays(1), startDateTime()); return occurrences.size() > 0; } }
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); }/*from w w w.j a v a2 s. c om*/ } } 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);// www . ja va 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:es.usc.citius.servando.calendula.scheduling.PickupReminderMgr.java
License:Open Source License
public void setCheckPickupsAlarm(Context ctx, LocalDate date) { DateTime d = date.toDateTimeAtStartOfDay().withHourOfDay(12).withMinuteOfHour(0).withSecondOfMinute(0); PendingIntent calendarReminderPendingIntent = alarmPendingIntent(ctx); // Get the AlarmManager service AlarmManager alarmManager = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE); if (alarmManager != null) { alarmManager.set(AlarmManager.RTC_WAKEUP, d.getMillis(), calendarReminderPendingIntent); Log.d(TAG, "Pickup check alarm scheduled!"); }/*from w w w. j ava2s . c om*/ }
From source file:es.usc.citius.servando.calendula.util.PickupUtils.java
License:Open Source License
public Pair<LocalDate, List<PickupInfo>> getBestDay() { if (this.bestDay != null) { return this.bestDay; }//from www. j av a 2 s . co m HashMap<LocalDate, List<PickupInfo>> bestDays = new HashMap<>(); if (pickups.size() > 0) { LocalDate today = LocalDate.now(); LocalDate first = LocalDate.now(); LocalDate now = LocalDate.now().minusDays(MAX_DAYS); if (now.getDayOfWeek() == DateTimeConstants.SUNDAY) { now = now.plusDays(1); } // get the date of the first med we can take from 10 days ago for (PickupInfo p : pickups) { if (p.from().isAfter(now) && !p.taken()) { first = p.from(); break; } } for (int i = 0; i < 10; i++) { LocalDate d = first.plusDays(i); if (!d.isAfter(today) && d.getDayOfWeek() != DateTimeConstants.SUNDAY) { // only take care of days after today that are not sundays continue; } // compute the number of meds we cant take for each day for (PickupInfo p : pickups) { // get the pickup take secure interval DateTime iStart = p.from().toDateTimeAtStartOfDay(); DateTime iEnd = p.from().plusDays(MAX_DAYS - 1).toDateTimeAtStartOfDay(); Interval interval = new Interval(iStart, iEnd); // add the pickup to the daily list if we can take it if (!p.taken() && interval.contains(d.toDateTimeAtStartOfDay())) { if (!bestDays.containsKey(d)) { bestDays.put(d, new ArrayList<PickupInfo>()); } bestDays.get(d).add(p); } } } // select the day with the highest number of meds int bestDayCount = 0; LocalDate bestOption = null; Set<LocalDate> localDates = bestDays.keySet(); ArrayList<LocalDate> sorted = new ArrayList<>(localDates); Collections.sort(sorted); for (LocalDate day : sorted) { List<PickupInfo> pks = bestDays.get(day); Log.d("PickupUtils", day.toString("dd/MM/YYYY") + ": " + pks.size()); if (pks.size() >= bestDayCount) { bestDayCount = pks.size(); bestOption = day; if (bestOption.getDayOfWeek() == DateTimeConstants.SUNDAY) { bestOption = bestOption.minusDays(1); } } } if (bestOption != null) { this.bestDay = new Pair<>(bestOption, bestDays.get(bestOption)); return this.bestDay; } } return null; }
From source file:es.usc.citius.servando.calendula.util.ScheduleHelper.java
License:Open Source License
public static boolean cycleEnabledForDate(LocalDate date, LocalDate s, int activeDays, int restDays) { DateTime start = s.toDateTimeAtStartOfDay(); DateTime day = date.toDateTimeAtStartOfDay().plusDays(1); if (day.isBefore(start)) return false; int activePeriod = activeDays; int restPeriod = restDays; int cycleLength = activePeriod + restPeriod; int days = (int) new Interval(start, day).toDuration().getStandardDays(); int cyclesUntilNow = days / cycleLength; Log.d("ScheduleHelper", "start: " + start.toString("dd/MM/YYYY") + ", day: " + day.toString("dd/MM/YYYY")); Log.d("ScheduleHelper", "Active: " + activePeriod + ", rest: " + restPeriod + ", cycle: " + cycleLength + ", days: " + days + ", cyclesUntilNow: " + cyclesUntilNow); // get start of current cycle DateTime cycleStart = start.plusDays(cyclesUntilNow * cycleLength); return new Interval(cycleStart, cycleStart.plusDays(activePeriod)).contains(date.toDateTimeAtStartOfDay()); }
From source file:eu.jsan.duvi.commons.conversion.date.joda.LocalDateConverter.java
License:Apache License
@Override public Timestamp convertToDatabaseColumn(LocalDate value) { if (value != null) { return new Timestamp(value.toDateTimeAtStartOfDay().getMillis()); }//from w w w . j a v a 2 s . c o m return null; }