List of usage examples for org.joda.time Days daysBetween
public static Days daysBetween(ReadablePartial start, ReadablePartial end)
Days
representing the number of whole days between the two specified partial datetimes. From source file:org.openvpms.archetype.rules.workflow.AppointmentRules.java
License:Open Source License
/** * Returns the number of days to charge boarding for. * * @param startTime the boarding start time * @param endTime the boarding end time * @return the number of days//from w w w . j a v a2s .c o m */ public int getBoardingDays(Date startTime, Date endTime) { DateMidnight end = new DateMidnight(endTime); int days = Days.daysBetween(new DateMidnight(startTime), end).getDays(); if (days < 0) { days = 0; } else if (DateRules.compareTo(endTime, end.toDate()) != 0) { // any time after midnight is another day days++; } return days; }
From source file:org.openvpms.web.component.subscription.SubscriptionHelper.java
License:Open Source License
/** * Formats a subscription./*w w w. j a v a2 s. co m*/ * * @param organisation the organisation name. May be {@code null} * @param name the subscriber name. May be {@code null} * @param expiryDate the subscription expiry date. May be {@code null} * @param now the current date * @return the subscription message */ static String formatSubscription(String organisation, String name, Date expiryDate, Date now) { String result = null; if (organisation != null || name != null) { String user = organisation; if (user == null) { user = name; } user = StringEscapeUtils.escapeHtml(user); if (expiryDate != null) { String date = DateFormatter.getFullDateFormat().format(expiryDate); date = StringEscapeUtils.escapeHtml(date); if (DateRules.compareDates(expiryDate, now) < 0) { result = Messages.format("subscription.summary.expired", user, date); } else if (Days.daysBetween(new DateTime(now), new DateTime(expiryDate)).getDays() <= 21) { result = Messages.format("subscription.summary.expiring", user, date); } else { result = Messages.format("subscription.summary.active", user, date); } } } if (result == null) { result = Messages.get("subscription.summary.nosubscription"); } return result; }
From source file:org.openvpms.web.workspace.admin.calendar.CalendarTableModel.java
License:Open Source License
/** * Returns the no. of columns that an event occupies, from the specified column. * <p>/*from ww w . ja v a 2s.c om*/ * If the event begins prior to the column, the remaining columns will be returned. * * @param event the event * @param column the starting column * @return the no. of columns that the event occupies */ public int getColumns(PropertySet event, int column) { DateTime endTime = new DateTime(event.getDate(ScheduleEvent.ACT_END_TIME)); int last = Days.daysBetween(new DateTime(getStartDate()), endTime).getDays(); return last - column; }
From source file:org.openvpms.web.workspace.workflow.appointment.AbstractMultiDayScheduleGrid.java
License:Open Source License
/** * Returns the slot that a time falls in. * * @param time the time//w w w . j av a 2 s .c o m * @return the slot, or {@code -1} if the time doesn't intersect any slot */ @Override public int getSlot(Date time) { return Days.daysBetween(new DateTime(getStartDate()), new DateTime(time)).getDays(); }
From source file:org.openvpms.web.workspace.workflow.appointment.AbstractMultiDayScheduleGrid.java
License:Open Source License
/** * Returns the no. of slots an event occupies, from the specified slot. * <p>/*from w ww . j a v a 2 s . co m*/ * If the event begins prior to the slot, the remaining slots will be returned. * * @param event the event * @param slot the starting slot * @return the no. of slots that the event occupies */ public int getSlots(PropertySet event, int slot) { DateTime endTime = new DateTime(event.getDate(ScheduleEvent.ACT_END_TIME)); int endSlot = Days.daysBetween(new DateTime(getStartDate()), endTime).getDays(); if (endTime.getHourOfDay() > 0 || endTime.getMinuteOfHour() > 0) { ++endSlot; } return endSlot - slot; }
From source file:org.patientview.radar.service.impl.TransplantManagerImpl.java
License:Open Source License
public void saveTransplant(Transplant transplant) throws InvalidModelException { // validate transplant List<String> errors = new ArrayList<String>(); List<Transplant> transplants = transplantDao.getTransplantsByRadarNumber(transplant.getRadarNumber()); // transplant date must be greater than reccur, failure date, date reject and date biopsy List<Date> datesAfterStart = new ArrayList<Date>(); datesAfterStart.addAll(//ww w . j a va 2 s . co m Arrays.asList(transplant.getDateRecurr(), transplant.getDateFailureRejectData().getFailureDate())); List<Transplant.RejectData> rejectDataList = transplantDao .getRejectDataByTransplantNumber(transplant.getId()); for (Transplant.RejectData rejectData : rejectDataList) { datesAfterStart.add(rejectData.getRejectedDate()); datesAfterStart.add(rejectData.getBiopsyDate()); } for (Date dateAfterStart : datesAfterStart) { if (dateAfterStart != null) { if (transplant.getDate().compareTo(dateAfterStart) >= 0) { errors.add(START_DATE_ERROR); break; } } } // date of failure has to be after reccur, date reject and date biopsy List<Date> datesAfterEndDate = new ArrayList<Date>(); datesAfterEndDate.add(transplant.getDateRecurr()); for (Transplant.RejectData rejectData : rejectDataList) { datesAfterEndDate.add(rejectData.getRejectedDate()); datesAfterEndDate.add(rejectData.getBiopsyDate()); } Date failureDate = transplant.getDateFailureRejectData() != null ? transplant.getDateFailureRejectData().getFailureDate() : null; if (failureDate != null) { for (Date dateAfterEndDate : datesAfterEndDate) { if (dateAfterEndDate != null) { if (failureDate.compareTo(dateAfterEndDate) <= 0) { errors.add(FAILURE_DATE_ERROR); break; } } } } // transplant must be 14 days apart for (Transplant existingTransplant : transplants) { if (existingTransplant.getId().equals(transplant.getId())) { continue; } int daysApart = Math.abs( Days.daysBetween(new DateTime(existingTransplant.getDate()), new DateTime(transplant.getDate())) .getDays()); if (Math.abs(daysApart) <= 14) { errors.add(TRANSPLANTS_INTERVAL_ERROR); break; } } // cannot add new transplant whilst previous transplant has not failed for (Transplant existingTransplant : transplants) { if (existingTransplant.getId().equals(transplant.getId())) { continue; } if (existingTransplant.getDateFailureRejectData() != null) { if (existingTransplant.getDateFailureRejectData().getFailureDate() == null) { errors.add(TreatmentManager.PREVIOUS_TREATMENT_NOT_CLOSED_ERROR); break; } } else { errors.add(TreatmentManager.PREVIOUS_TREATMENT_NOT_CLOSED_ERROR); break; } } // cannot add transplant before another failure date for (Transplant existingTransplant : transplants) { if (existingTransplant.getId().equals(transplant.getId())) { continue; } if (existingTransplant.getDateFailureRejectData() != null) { if (failureDate != null) { if (failureDate.compareTo(transplant.getDate()) > 0) { errors.add(BEFORE_PREVIOUS_FAILURE_DATE); break; } } } } List<Date> datesToCheck = Arrays.asList(transplant.getDate(), transplant.getDateRecurr(), transplant.getDateFailureRejectData() != null ? transplant.getDateFailureRejectData().getFailureDate() : null); // cannot be before date of birth Patient patient = patientManager.getPatientByRadarNumber(transplant.getRadarNumber()); if (patient != null) { Date dob = patient.getDob(); if (dob != null) { for (Date date : datesToCheck) { if (date != null) { if (dob.compareTo(date) > 0) { errors.add(TreatmentManager.BEFORE_DOB_ERROR); break; } } } } } // cannot be after today Date today = new Date(); for (Date date : datesToCheck) { if (date != null) { if (today.compareTo(date) < 0) { errors.add(TreatmentManager.AFTER_TODAY_ERROR); break; } } } if (!errors.isEmpty()) { InvalidModelException exception = new InvalidModelException("Transplant model is not valid"); exception.setErrors(errors); throw exception; } transplantDao.saveTransplant(transplant); }
From source file:org.projectbuendia.client.ui.dialogs.OrderDialogFragment.java
License:Apache License
private void populateFields(Bundle args) { String instructions = args.getString("instructions"); mMedication.setText(Order.getMedication(instructions)); mDosage.setText(Order.getDosage(instructions)); mFrequency.setText(Order.getFrequency(instructions)); DateTime now = Utils.getDateTime(args, "now_millis"); Long stopMillis = Utils.getLong(args, "stop_millis"); if (stopMillis != null) { LocalDate lastDay = new DateTime(stopMillis).toLocalDate(); int days = Days.daysBetween(now.toLocalDate(), lastDay).getDays(); if (days >= 0) { mGiveForDays.setText("" + (days + 1)); // 1 day means stop after today }/*from w w w . j ava2 s. c o m*/ } updateLabels(); }
From source file:org.projectbuendia.client.ui.dialogs.OrderDialogFragment.java
License:Apache License
public void onSubmit(Dialog dialog) { String uuid = getArguments().getString("uuid"); String patientUuid = getArguments().getString("patientUuid"); String medication = mMedication.getText().toString().trim(); String dosage = mDosage.getText().toString().trim(); String frequency = mFrequency.getText().toString().trim(); String instructions = Order.getInstructions(medication, dosage, frequency); String durationStr = mGiveForDays.getText().toString().trim(); Integer durationDays = durationStr.isEmpty() ? null : Integer.valueOf(durationStr); boolean valid = true; if (medication.isEmpty()) { setError(mMedication, R.string.enter_medication); valid = false;// w w w . java 2s . c om } if (durationDays != null && durationDays == 0) { setError(mGiveForDays, R.string.order_give_for_days_cannot_be_zero); valid = false; } Utils.logUserAction("order_submitted", "valid", "" + valid, "uuid", uuid, "medication", medication, "dosage", dosage, "frequency", frequency, "instructions", instructions, "durationDays", "" + durationDays); if (!valid) { return; } dialog.dismiss(); DateTime now = Utils.getDateTime(getArguments(), "now_millis"); DateTime start = Utils.getDateTime(getArguments(), "start_millis"); start = Utils.valueOrDefault(start, now); if (durationDays != null) { // Adjust durationDays to account for a start date in the past. Entering "2" // always means two more days, stopping after tomorrow, regardless of start date. LocalDate firstDay = start.toLocalDate(); LocalDate lastDay = now.toLocalDate().plusDays(durationDays - 1); durationDays = Days.daysBetween(firstDay, lastDay).getDays() + 1; } // Post an event that triggers the PatientChartController to save the order. EventBus.getDefault() .post(new OrderSaveRequestedEvent(uuid, patientUuid, instructions, start, durationDays)); }
From source file:org.projectbuendia.client.utils.date.Dates.java
License:Apache License
/** * Describes a given date as a number of days since a starting date, where the starting date * itself is Day 1. Returns a value <= 0 if the given date is null or in the future. *//* w w w. ja va2s .co m*/ public static int dayNumberSince(@Nullable LocalDate startDate, @Nullable LocalDate date) { if (startDate == null || date == null) { return -1; } return Days.daysBetween(startDate, date).getDays() + 1; }
From source file:org.projectforge.plugins.teamcal.event.TeamCalEventProvider.java
License:Open Source License
/** * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime, org.joda.time.DateTime) *//*from ww w .j a v a 2s . com*/ @Override protected void buildEvents(final DateTime start, final DateTime end) { final TemplateEntry activeTemplateEntry = filter.getActiveTemplateEntry(); if (activeTemplateEntry == null) { // Nothing to build. return; } final Set<Integer> visibleCalendars = activeTemplateEntry.getVisibleCalendarIds(); if (CollectionUtils.isEmpty(visibleCalendars) == true) { // Nothing to build. return; } final TeamEventFilter eventFilter = new TeamEventFilter(); eventFilter.setTeamCals(visibleCalendars); eventFilter.setStartDate(start.toDate()); eventFilter.setEndDate(end.toDate()); eventFilter.setUser(PFUserContext.getUser()); final List<TeamEvent> teamEvents = teamEventDao.getEventList(eventFilter); boolean longFormat = false; days = Days.daysBetween(start, end).getDays(); if (days < 10) { // Week or day view: longFormat = true; } final TeamCalRight right = new TeamCalRight(); final PFUserDO user = PFUserContext.getUser(); final TimeZone timeZone = PFUserContext.getTimeZone(); if (CollectionUtils.isNotEmpty(teamEvents) == true) { for (final TeamEvent teamEvent : teamEvents) { final DateTime startDate = new DateTime(teamEvent.getStartDate(), PFUserContext.getDateTimeZone()); final DateTime endDate = new DateTime(teamEvent.getEndDate(), PFUserContext.getDateTimeZone()); final TeamEventDO eventDO; final TeamCalEventId id = new TeamCalEventId(teamEvent, timeZone); if (teamEvent instanceof TeamEventDO) { eventDO = (TeamEventDO) teamEvent; } else { eventDO = ((TeamRecurrenceEvent) teamEvent).getMaster(); } teamEventMap.put(id.toString(), teamEvent); final MyEvent event = new MyEvent(); event.setClassName( EVENT_CLASS_NAME + " " + EventDroppedCallbackScriptGenerator.NO_CONTEXTMENU_INDICATOR); event.setId("" + id); event.setColor(activeTemplateEntry.getColorCode(eventDO.getCalendarId())); if (eventRight.hasUpdateAccess(PFUserContext.getUser(), eventDO, null)) { event.setEditable(true); } else { event.setEditable(false); } if (teamEvent.isAllDay() == true) { event.setAllDay(true); } event.setStart(startDate); event.setEnd(endDate); event.setTooltip(eventDO.getCalendar().getTitle(), new String[][] { { eventDO.getSubject() }, { eventDO.getLocation(), getString("timesheet.location") }, { eventDO.getNote(), getString("plugins.teamcal.event.note") } }); final String title; String durationString = ""; if (longFormat == true) { // String day = duration.getDays() + ""; final Period period = new Period(startDate, endDate); int hourInt = period.getHours(); if (period.getDays() > 0) { hourInt += period.getDays() * 24; } final String hour = hourInt < 10 ? "0" + hourInt : "" + hourInt; final int minuteInt = period.getMinutes(); final String minute = minuteInt < 10 ? "0" + minuteInt : "" + minuteInt; if (event.isAllDay() == false) { durationString = "\n" + getString("plugins.teamcal.event.duration") + ": " + hour + ":" + minute; } final StringBuffer buf = new StringBuffer(); buf.append(teamEvent.getSubject()); if (StringUtils.isNotBlank(teamEvent.getNote()) == true) { buf.append("\n").append(getString("plugins.teamcal.event.note")).append(": ") .append(teamEvent.getNote()); } buf.append(durationString); title = buf.toString(); } else { title = teamEvent.getSubject(); } if (right.hasMinimalAccess(eventDO.getCalendar(), user.getId()) == true) { // for minimal access event.setTitle(""); event.setEditable(false); } else { event.setTitle(title); } events.put(id + "", event); } } }