List of usage examples for org.joda.time LocalDate minusDays
public LocalDate minusDays(int days)
From source file:edu.harvard.med.iccbl.screensaver.io.users.UserAgreementExpirationUpdater.java
License:Open Source License
private void notifyAhead(final Integer daysToNotify, final int ageInDays) throws MessagingException { LocalDate expireDate = new LocalDate().plusDays(daysToNotify); LocalDate maxPerformedDate = expireDate.minusDays(ageInDays); List<Pair<ScreeningRoomUser, ChecklistItemEvent>> pairList = _userAgreementUpdater .findUsersWithOldUserAgreements(maxPerformedDate, false, _screenType); if (pairList.isEmpty()) { String subject = getMessages().getMessage( "admin.users.userAgreementExpiration.warningNotification.noaction.subject", _screenType); String msg = "No " + _screenType + " Users have agreements (that haven't already been notified) dated earlier than the specified cutoff date: " + maxPerformedDate + ", or (now - ageInDaysToExpire + daysToNotify): (" + new LocalDate() + " - " + ageInDays + "D + " + daysToNotify + "D)."; sendAdminEmails(subject, msg);//from ww w . j a v a2 s. c om } else { // send Admin summary email String subject = getMessages().getMessage( "admin.users.userAgreementExpiration.warningNotification.subject", pairList.size(), _screenType, daysToNotify); StringBuilder msg = new StringBuilder(getMessages().getMessage( "admin.users.userAgreementExpiration.warningNotification.messageBoilerplate", pairList.size(), _screenType, daysToNotify, _screenType.getValue())); if (isAdminEmailOnly()) msg.append("\n----NOTE: sending email only to data sharing level admins ---"); if (isCommandLineFlagSet(TEST_ONLY[SHORT_OPTION_INDEX])) { subject = "[TEST ONLY, no commits] " + subject; msg.append("\n----TEST Only: no database changes committed.-------"); } msg.append("\nUsers: \n"); msg.append(printUserHeader() + "| Checklist Item Date\n"); for (Pair<ScreeningRoomUser, ChecklistItemEvent> pair : pairList) { msg.append(printUser(pair.getFirst()) + "| " + pair.getSecond().getDatePerformed() + "\n"); } Pair<String, String> notificationSubjectAndMessage = getExpireNotificationSubjectMessage(); String exampleMessage = MessageFormat.format(notificationSubjectAndMessage.getSecond(), _screenType.getValue(), EXPIRE_DATE_FORMATTER.print(expireDate), "[user's primary data sharing level]"); msg.append("\n\n[example email]\n"); msg.append("\nSubject: " + notificationSubjectAndMessage.getFirst() + "\n\n"); msg.append(exampleMessage); sendAdminEmails(subject, msg.toString(), _userAgreementUpdater.findUserAgreementAdmins()); if (isAdminEmailOnly() || (isCommandLineFlagSet(TEST_ONLY[SHORT_OPTION_INDEX]) && !isCommandLineFlagSet(TEST_EMAIL_ONLY[SHORT_OPTION_INDEX]))) { for (Pair<ScreeningRoomUser, ChecklistItemEvent> pair : pairList) { // set the flag so that we don't notify for this CIE again. _userAgreementUpdater.setLastNotifiedUserAgreementChecklistItemEvent(pair.getFirst(), pair.getSecond(), _screenType); } } else { // send user an email for (Pair<ScreeningRoomUser, ChecklistItemEvent> pair : pairList) { String roleName = "default"; ScreensaverUserRole role = DataSharingLevelMapper .getPrimaryDataSharingLevelRoleForUser(_screenType, pair.getFirst()); if (role != null) { roleName = role.getDisplayableRoleName(); } String message = MessageFormat.format(notificationSubjectAndMessage.getSecond(), _screenType, EXPIRE_DATE_FORMATTER.print(expireDate), roleName); if (sendEmail(notificationSubjectAndMessage.getFirst().replace("{0}", _screenType.getValue()), message, pair.getFirst())) { _userAgreementUpdater.setLastNotifiedUserAgreementChecklistItemEvent(pair.getFirst(), pair.getSecond(), _screenType); } } } } }
From source file:edu.uic.apk.APKBuilder.java
License:Open Source License
protected static double getDateDifference(LocalDate c1, LocalDate c2) { //like c1 - c2 in years assert c2 != null; if (c1 == null) { c1 = getSimulationDate();/* w w w . j a v a 2 s . co m*/ } LocalDate dt = c1.minusDays(c2.getDayOfYear()).minusYears(c2.getYear()); return dt.getYear() + (dt.getDayOfYear() / 365.0); //year is 365 ticks throughout }
From source file:energy.usef.agr.pbcfeederimpl.PbcFeederService.java
License:Apache License
/** * This method creates and adds two UDI's to every connection. The UDI is a PV, with the PVForecast values from the * stubinputdatasheet./*from w ww .ja v a 2 s.c om*/ * * @param date * @param connections * @param ptuDuration * @return connectionDtos with UDI's for Photo-voltaic forecast. */ public List<ConnectionPortfolioDto> retrieveUDIListWithPvLoadAveragePower(LocalDate date, List<ConnectionPortfolioDto> connections, int ptuDuration) { //minus one because we need the previous one as well. int startPtuIndex = PtuUtil.getPtuIndex(DateTimeUtil.getCurrentDateTime(), ptuDuration) - 1; int ptusPerDay = PtuUtil.getNumberOfPtusPerDay(date, ptuDuration); LocalDate startDate = date; if (startPtuIndex <= 0) { startDate = startDate.minusDays(1); startPtuIndex = PtuUtil.getNumberOfPtusPerDay(startDate, ptuDuration); } List<PbcStubDataDto> pbcStubDataDtoList = pbcFeederClient.getPbcStubDataList(date, 1, ptusPerDay); final int finalStartPtuIndex = startPtuIndex; for (ConnectionPortfolioDto connectionDto : connections) { // connectionDto.getUdis().stream().filter(udiDto -> udiDto.getEndpoint() != null) .forEach(udiDto -> fillDtusForUdi(udiDto, pbcStubDataDtoList, ptuDuration, udiDto.getDtuSize(), finalStartPtuIndex)); } return connections; }
From source file:energy.usef.core.service.business.CorePlanboardBusinessService.java
License:Apache License
/** * This will update the phase of all the {@link PtuContainer} entities with the given period and given ptu index. The new phase * will be {@link PtuContainerState#Operate} for the specified {@link PtuContainer}. The previous {@link PtuContainer} will be * set to {@link PtuContainerState#PendingSettlement}. * * @param period {@link LocalDate} date of change. * @param ptuIndex {@link Integer} index of the PTU. *//* www .ja v a2 s . co m*/ public void processMoveToOperateEvent(LocalDate period, Integer ptuIndex) { ptuContainerRepository.updatePtuContainersState(PtuContainerState.Operate, period, ptuIndex); ptuContainerRepository.updatePtuContainersPhase(PhaseType.Operate, period, ptuIndex); LocalDate pendingSettlementDate = ptuIndex == 1 ? period.minusDays(1) : period; Integer pendingSettlementPtuIndex = ptuIndex == 1 ? PtuUtil.getNumberOfPtusPerDay(pendingSettlementDate, config.getIntegerProperty(ConfigParam.PTU_DURATION)) : ptuIndex - 1; LOGGER.info("PTU Container with period={} and ptu index={} will move to Pending_Settlement.", pendingSettlementDate, pendingSettlementPtuIndex); ptuContainerRepository.updatePtuContainersState(PtuContainerState.PendingSettlement, pendingSettlementDate, pendingSettlementPtuIndex); ptuContainerRepository.updatePtuContainersPhase(PhaseType.Settlement, pendingSettlementDate, pendingSettlementPtuIndex); }
From source file:es.usc.citius.servando.calendula.activities.CalendarActivity.java
License:Open Source License
private void onActivateReminder(final LocalDate best) { AlertDialog alertDialog = new AlertDialog.Builder(this) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss();// ww w .j av a 2s .co m } }).setTitle(R.string.best_date_reminder) .setSingleChoiceItems(getResources().getStringArray(R.array.calendar_pickup_reminder_values), -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { PickupReminderMgr.instance().setCheckPickupsAlarm(CalendarActivity.this, best.minusDays(which + 1)); Toast.makeText(CalendarActivity.this, "Recordatorio activado!", Toast.LENGTH_SHORT) .show(); dialog.dismiss(); } }) .create(); alertDialog.show(); }
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 ww w . ja va 2 s. c o 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:gg.db.datamodel.Period.java
License:Open Source License
/** * Is the specified period valid?/*from w ww .j a v a2 s . c o m*/ * @param startDate Start date of the period * @param endDate End date of the period * @param periodType Type of the period * @return <B>true</B> if the period is valid (or if startDate=endDate=periodType=null), <B>false</B> otherwise<BR/> * To be valid, a period has to be a "full" period: * <UL> * <LI> For each type of period: Start date > End date</LI> * <LI> For DAY period: number of days between Start date and End date = 0<BR/> * Example: <I>From 12/30/2005 to 12/30/2005</I></LI> * <LI> For WEEK period: number of days between Start date and End date = 6<BR/> * The period has to start on MONDAY<BR/> * The period has to end on SUNDAY<BR/> * Example: <I>From 12/01/2005 to 12/18/2005</I></LI> * <LI> For MONTH period: number of month between Start date and End date = 0<BR/> * The period has to start on the first day of the month (05/01/2006)<BR/> * The period has to end on the last day of the month (05/31/2006)<BR/> * Number of months between Start date - 1 day and End date = 1<BR/> * Number of months between Start date and End date + 1 day = 1<BR/> * Example: <I>From 03/01/2005 to 03/31/2005</I></LI> * <LI> For YEAR period: number of years between Start date and End date = 0<BR/> * The period has to start on the first day of the first month (01/01/2006)<BR/> * The period has to end in December<BR/> * The period has to end on the last day of the last month (12/31/2006)<BR/> * Number of years between Start date - 1 day and End date = 1<BR/> * Number of years between Start date and End date + 1 day = 1<BR/> * Example: <I>From 01/01/2006 to 12/31/2006</I></LI> * </UL> */ private boolean isPeriodValid(LocalDate startDate, LocalDate endDate, PeriodType periodType) { boolean periodValid = true; // Is the period valid // Check if Start date < End date if (startDate != null && endDate != null && startDate.compareTo(endDate) > 0) { periodValid = false; } // Check if the period is a "full" period if (periodValid && startDate != null && endDate != null && periodType != null) { switch (periodType) { case DAY: // i.e. a DAY period: from 05/12/2006 to 05/12/2006 if ((getNumberOfDays(startDate.minusDays(1), endDate) != 1) || // 12-11 = 1 (Nb of days = 1) (getNumberOfDays(startDate, endDate) != 0) || // // 12-12 = 0 (Nb of days = 0) (getNumberOfDays(startDate, endDate.plusDays(1)) != 1)) { // 13-12 = 1 (Nb of days = 1) periodValid = false; } break; case WEEK: // i.e. a WEEK period: from 05/12/2006 to 05/18/2006 if ((startDate.toDateTimeAtStartOfDay().getDayOfWeek() != DateTimeConstants.MONDAY) || // the week has to begin on MONDAY (getNumberOfWeeks(startDate.minusDays(1), endDate) != 1) || // 18-11 = 7 (Nb of weeks = 1) (getNumberOfWeeks(startDate, endDate) != 0) || // 18-12 = 6 (Nb of weeks = 0) (getNumberOfWeeks(startDate, endDate.plusDays(1)) != 1)) { // 19-12 = 7 (Nb of weeks = 1) periodValid = false; } break; case MONTH: // i.e. a MONTH period: from 05/01/2006 to 05/30/2006 if ((startDate.getDayOfMonth() != 1) || // the first day of the period has to be the first day of the month (getNumberOfMonths(startDate.minusDays(1), endDate) != 1) || // 5-4 = 1 (Nb of months = 1) (getNumberOfMonths(startDate, endDate) != 0) || // 5-5 = 0 (Nb of months = 0) (getNumberOfMonths(startDate, endDate.plusDays(1)) != 1)) { // 6-5 = 1 (Nb of months = 1) periodValid = false; } break; case YEAR: // i.e. a YEAR period: from 01/01/2006 to 12/31/2006 if ((startDate.getMonthOfYear() != 1 || startDate.getDayOfMonth() != 1) || // the first day of the period has to be the first day of the first month (endDate.getMonthOfYear() != 12) || // the month of the end date of the period has to be December (getNumberOfYears(startDate.minusDays(1), endDate) != 1) || // 2006-2005 = 1 (Nb of years = 1) (getNumberOfYears(startDate, endDate) != 0) || // 2006-2006 = 0 (Nb of years = 0) (getNumberOfYears(startDate, endDate.plusDays(1)) != 1)) { // 2007-2006 = 1 (Nb of years = 1) periodValid = false; } break; case FREE: // There is no constraint on the number of units for FREE type of period break; default: // Should never happen throw new AssertionError("The PeriodType is unknown"); } } return periodValid; }
From source file:hudson.plugins.codecover.portlet.CodeCoverLoadData.java
License:Open Source License
/** * Get CodeCover coverage results of all jobs and store into a sorted * HashMap by date./*from w w w . j av a 2s . co m*/ * * @param jobs * jobs of Dashboard view * @param daysNumber * number of days * @return Map The sorted summaries */ public static Map<LocalDate, CodeCoverCoverageResultSummary> loadChartDataWithinRange(List<Job> jobs, int daysNumber) { Map<LocalDate, CodeCoverCoverageResultSummary> summaries = new HashMap<LocalDate, CodeCoverCoverageResultSummary>(); // Get the last build (last date) of the all jobs LocalDate lastDate = Utils.getLastDate(jobs); // No builds if (lastDate == null) { return null; } // Get the first date from last build date minus number of days LocalDate firstDate = lastDate.minusDays(daysNumber); // For each job, get CodeCover coverage results according with // date range (last build date minus number of days) for (Job job : jobs) { Run run = job.getLastBuild(); if (null != run) { LocalDate runDate = new LocalDate(run.getTimestamp()); while (runDate.isAfter(firstDate)) { summarize(summaries, run, runDate, job); run = run.getPreviousBuild(); if (null == run) { break; } runDate = new LocalDate(run.getTimestamp()); } } } // Sorting by date, ascending order Map<LocalDate, CodeCoverCoverageResultSummary> sortedSummaries = new TreeMap(summaries); return sortedSummaries; }
From source file:hudson.plugins.emma.portlet.EmmaLoadData.java
License:Open Source License
/** * Get Emma coverage results of all jobs and store into a sorted * HashMap by date.//from w w w . j a v a 2 s. c o m * * @param jobs * jobs of Dashboard view * @param daysNumber * number of days * @return Map The sorted summaries */ public static Map<LocalDate, EmmaCoverageResultSummary> loadChartDataWithinRange(List<Job> jobs, int daysNumber) { Map<LocalDate, EmmaCoverageResultSummary> summaries = new HashMap<LocalDate, EmmaCoverageResultSummary>(); // Get the last build (last date) of the all jobs LocalDate lastDate = Utils.getLastDate(jobs); // No builds if (lastDate == null) { return null; } // Get the first date from last build date minus number of days LocalDate firstDate = lastDate.minusDays(daysNumber); // For each job, get Emma coverage results according with // date range (last build date minus number of days) for (Job job : jobs) { Run run = job.getLastBuild(); if (null != run) { LocalDate runDate = new LocalDate(run.getTimestamp()); while (runDate.isAfter(firstDate)) { summarize(summaries, run, runDate, job); run = run.getPreviousBuild(); if (null == run) { break; } runDate = new LocalDate(run.getTimestamp()); } } } // Sorting by date, ascending order Map<LocalDate, EmmaCoverageResultSummary> sortedSummaries = new TreeMap(summaries); return sortedSummaries; }
From source file:hudson.plugins.jacoco.portlet.JacocoLoadData.java
License:Open Source License
/** * Get JaCoCo coverage results of all jobs and store into a sorted * HashMap by date.//from ww w.j a v a2 s . co m * * @param jobs * jobs of Dashboard view * @param daysNumber * number of days * @return Map The sorted summaries */ public static Map<LocalDate, JacocoCoverageResultSummary> loadChartDataWithinRange(List<Job> jobs, int daysNumber) { Map<LocalDate, JacocoCoverageResultSummary> summaries = new HashMap<LocalDate, JacocoCoverageResultSummary>(); // Get the last build (last date) of the all jobs LocalDate lastDate = Utils.getLastDate(jobs); // No builds if (lastDate == null) { return null; } // Get the first date from last build date minus number of days LocalDate firstDate = lastDate.minusDays(daysNumber); // For each job, get JaCoCo coverage results according with // date range (last build date minus number of days) for (Job job : jobs) { Run run = job.getLastBuild(); if (null != run) { LocalDate runDate = new LocalDate(run.getTimestamp()); while (runDate.isAfter(firstDate)) { summarize(summaries, run, runDate, job); run = run.getPreviousBuild(); if (null == run) { break; } runDate = new LocalDate(run.getTimestamp()); } } } // Sorting by date, ascending order Map<LocalDate, JacocoCoverageResultSummary> sortedSummaries = new TreeMap<LocalDate, JacocoCoverageResultSummary>( summaries); return sortedSummaries; }