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.ojbc.bundles.adapters.staticmock.samplegen.AbstractSampleGenerator.java
License:RPL License
/** * Generates a random, uniformly distributed date between the two specified dates. * /*from w ww. j a va2 s .co m*/ * @param d1 * the first date * @param d2 * the second date * @return a random date between the two */ protected final DateTime generateUniformRandomDateBetween(DateTime d1, DateTime d2) { DateTime start = d1; DateTime end = d2; if (d1.isAfter(d2)) { start = d2; end = d1; } int daysBetween = Days.daysBetween(start, end).getDays(); int r = randomGenerator.nextInt(0, daysBetween); return start.plusDays(r); }
From source file:org.ojbc.intermediaries.sn.dao.SubscriptionSearchQueryDAO.java
License:RPL License
/** * Search for subscriptions for the subjects using the Notification Request which contains specified identifiers, and that are/were active on the specified event date. * This is essentially how you determine the applicable subscriptions for a specified event, so that you can then notify about that event. This method will filter out * any subscriptions that are passed the validation due date. * @param notificationRequest notification request containing all notification message components mapped to POJO * @return the list of subscriptions to be notified of the event *///from w w w .j a v a 2 s . c om public List<Subscription> searchForSubscriptionsMatchingNotificationRequest( NotificationRequest notificationRequest) { //Retrieve fields from notification request DateTime eventDate = notificationRequest.getNotificationEventDate(); Map<String, String> subjectIdentifiers = notificationRequest.getSubjectIdentifiers(); //log.debug("baseNotificationsOnEventDate=" + baseNotificationsOnEventDate); DateTime notificationCompareDate = baseNotificationsOnEventDate ? eventDate : new DateTime(); String notificationCompareDateString = DATE_FORMATTER_YYYY_MM_DD.print(notificationCompareDate); //log.debug("notificationCompareDateString=" + notificationCompareDateString); //log.debug("event Date=" + DATE_FORMATTER_YYYY_MM_DD.print(eventDate)); Object[] criteriaArray = new Object[] { DATE_FORMATTER_YYYY_MM_DD.print(eventDate), notificationCompareDateString, notificationCompareDateString, notificationCompareDateString, notificationRequest.getTopic() }; String queryString = BASE_QUERY_STRING + " and s.startDate <=? and ((s.startDate <=? and s.endDate >?) or (s.startDate <=? and s.endDate is null)) and s.topic=? and active=1 and "; queryString += (" (" + buildCriteriaSql(subjectIdentifiers.size()) + " or s.id in (select subscriptionId from subscription_subject_identifier where identifierValue='*')) "); Object[] subjectIdArray = buildCriteriaArray(subjectIdentifiers); criteriaArray = ArrayUtils.addAll(criteriaArray, subjectIdArray); List<Subscription> subscriptions = this.jdbcTemplate.query(queryString, criteriaArray, resultSetExtractor); log.debug("Found " + subscriptions.size() + " subscriptions:" + subscriptions); List<Subscription> wildcardFilteredSubscriptions = new ArrayList<Subscription>(); for (Subscription s : subscriptions) { Map<String, String> subscriptionSubjectIdentifiers = s.getSubscriptionSubjectIdentifiers(); if (subscriptionSubjectIdentifiers.values().contains("*")) { if (subscriptionSubjectIdentifiers.size() > 1) { boolean keep = true; for (String identifierName : subscriptionSubjectIdentifiers.keySet()) { if (!("*".equals(subscriptionSubjectIdentifiers.get(identifierName)))) { keep = keep && subscriptionSubjectIdentifiers.get(identifierName) .equals(subjectIdentifiers.get(identifierName)); } } if (keep) { wildcardFilteredSubscriptions.add(s); } } else { wildcardFilteredSubscriptions.add(s); } } else { wildcardFilteredSubscriptions.add(s); } } subscriptions = wildcardFilteredSubscriptions; List<Subscription> subscriptionToFilter = new ArrayList<Subscription>(); //Check Validation Due Date Period Here for (Subscription subscription : subscriptions) { DateTime validationDueDate = subscription.getValidationDueDate(); //log.debug("validationDueDate=" + validationDueDate); //No validation due date, continue if (validationDueDate == null) { continue; } //Check the current date against the validation due date. If the current date is past the validation due date, filter the subscription. if (Days.daysBetween(notificationCompareDate, validationDueDate).getDays() < 0) { //Add to list for Removing subscriptions subscriptionToFilter.add(subscription); //log.debug("Filtering sub=" + subscription); } } log.debug("Here are the " + subscriptionToFilter.size() + " subscriptions to filter: " + subscriptionToFilter.toString()); subscriptions.removeAll(subscriptionToFilter); return subscriptions; }
From source file:org.ojbc.intermediaries.sn.notification.filter.EventDateBasedNotificationFilterStrategy.java
License:RPL License
@Override public boolean shouldMessageBeFiltered(NotificationRequest notificationRequest) { try {//from ww w . j av a2s .co m DateTime currentDate = new DateTime(); DateTime notificationDate = notificationRequest.getNotificationEventDate(); if (notificationDate == null) { log.info("unable to determine notification date. Will not filter"); return false; } if (Days.daysBetween(notificationDate, currentDate) .getDays() > filterNotificationsWithEventDatesOlderThanThisManyDays) { log.info("Notification date of " + notificationDate.toString() + " is older than " + filterNotificationsWithEventDatesOlderThanThisManyDays + ". Notification IS filtered."); return true; } } catch (Exception ex) { log.error("EventDateBasedNotificationFilterStrategy threw an error. Will not filter message"); } return false; }
From source file:org.ojbc.util.camel.processor.FileAndDirectoryVerificationProcessor.java
License:RPL License
public boolean doesDirectoryWithFilesExist() { File directory = new File(directoryPath); File[] files = directory.listFiles(); DateTime today = new DateTime(); boolean areThereFilesFromToday = false; if (files != null) { for (File file : files) { long timesteamp = file.lastModified(); DateTime fileTimeStamp = new DateTime(timesteamp); if (Days.daysBetween(today, fileTimeStamp).getDays() == 0) { areThereFilesFromToday = true; break; }/* w ww . j a v a 2 s . c o m*/ } } return areThereFilesFromToday; }
From source file:org.opencommercesearch.Utils.java
License:Apache License
private static int daysBetween(String from, String to) throws ParseException { DateMathParser dmp = new DateMathParser(); Date fromDate = parseDate(from, dmp); Date toDate = parseDate(to, dmp); return Days.daysBetween(new DateTime(fromDate), new DateTime(toDate)).getDays(); }
From source file:org.openepics.discs.calib.util.DevicePlus.java
License:Open Source License
private String nameStatus() { String stat = "NotDueSoon"; Date curDate = new Date(); DateTime curDt = new DateTime(curDate); DateTime dueDt = new DateTime(nextDueDate); if (nextDueDate == null) { return stat; }//from w ww . j a v a 2 s. c o m if (dueDt.isBefore(curDt)) { stat = PAST_DUE; } else { int dueDays = Days.daysBetween(curDt, dueDt).getDays(); if (dueDays < DUE_SOON_PERIOD) { stat = DUE_SOON; } } return stat; }
From source file:org.openmainframe.ade.ext.stats.MessageRateStats.java
License:Open Source License
/** * Output the overallStats to logger// ww w.jav a 2 s. c o m * @throws AdeException */ private void generateReportIfNeeded(long inputTime) throws AdeException { final DateTime inputDateTimeStartOfDay = new DateTime(inputTime).withZone(s_outTimeZone) .withTimeAtStartOfDay(); final int daysSinceLastReported = Days.daysBetween(m_lastReportDateTimeBegin, inputDateTimeStartOfDay) .getDays(); if (daysSinceLastReported < 1) { /* Do not need report if the days is less than 1 day */ return; } boolean createReport = false; boolean resetData = false; switch (m_reportFrequency) { case MONTHLY: { final boolean monthChangedSinceLastReported = m_lastReportDateTimeBegin .getMonthOfYear() != inputDateTimeStartOfDay.getMonthOfYear() || m_lastReportDateTimeBegin.getYear() != inputDateTimeStartOfDay.getYear(); if (monthChangedSinceLastReported) { createReport = true; resetData = true; } else { resetData = false; /* If this processing is within the same month as processing start, * output every day */ final boolean monthChangedSinceProcessingStarted = m_processingStartDateTime .getMonthOfYear() != inputDateTimeStartOfDay.getMonthOfYear() || m_processingStartDateTime.getYear() != inputDateTimeStartOfDay.getYear(); if (!monthChangedSinceProcessingStarted) { createReport = true; } } break; } case DAYS: { if (daysSinceLastReported >= m_reportFrequency.getDays()) { createReport = true; resetData = true; } else { resetData = false; /* If this processing just started less than or equal to 10 days, output every day */ final int daysSinceStarted = Days.daysBetween(m_processingStartDateTime, inputDateTimeStartOfDay) .getDays(); if (daysSinceStarted <= m_reportFrequency.getDays()) { createReport = true; } } break; } default: break; } /* Write out the report */ if (createReport) { generateReport(getYesterdayEndOfDay(inputDateTimeStartOfDay)); m_lastReportDateTimeBegin = inputDateTimeStartOfDay; /* Reset all the data */ if (resetData) { initOverallStatsForAllIntervals(); } } }
From source file:org.openmrs.mobile.utilities.DateUtils.java
License:Open Source License
public static String calculateAge(String dateOfBirth) { int ageInYears; int ageInMonths; int ageInDays; DateTime birthDate;/*from ww w . j a v a2s . c om*/ DateTime currentTime; try { birthDate = new DateTime(SIMPLE_DATE_FORMAT.parse(dateOfBirth)); currentTime = new DateTime(); if (birthDate.isAfter(currentTime)) { OpenMRS.getInstance().getLogger().w(TAG, "Can't be born in the future"); return ApplicationConstants.EMPTY_STRING; } ageInYears = Years.yearsBetween(birthDate.toLocalDate(), currentTime.toLocalDate()).getYears(); ageInMonths = Months.monthsBetween(birthDate.toLocalDate(), currentTime.toLocalDate()).getMonths(); ageInDays = Days.daysBetween(birthDate.toLocalDate(), currentTime.toLocalDate()).getDays(); } catch (ParseException e) { OpenMRS.getInstance().getLogger().e(TAG, "Error parsing date: " + dateOfBirth, e); return ApplicationConstants.EMPTY_STRING; } if (ageInYears > 0) { return String.valueOf(ageInYears); } else if (ageInMonths == 1) { return ageInMonths + " month"; } else if (ageInMonths > 1) { return ageInMonths + " months"; } else if (ageInDays == 1) { return ageInDays + " day"; } else return ageInDays + " days"; }
From source file:org.openmrs.module.emrapi.patient.PatientDomainWrapper.java
License:Open Source License
public Integer getAgeInDays() { if (patient.getBirthdate() == null) { return null; }//from w w w .j a v a2 s . c om Date endDate = patient.isDead() ? patient.getDeathDate() : new Date(); return Days.daysBetween(new DateTime(patient.getBirthdate()), new DateTime(endDate)).getDays(); }
From source file:org.openmrs.module.isanteplus.api.impl.IsantePlusServiceImpl.java
License:Open Source License
@Override public Integer getPatientAgeInDays(Patient patient) { if (patient.getBirthdate() == null) { return null; }/*from w w w . ja va 2s .c om*/ Date endDate = patient.getDead() ? patient.getDeathDate() : new Date(); return Days.daysBetween(new DateTime(patient.getBirthdate()), new DateTime(endDate)).getDays(); }