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.jobscheduler.dashboard.web.rest.SchedulerHistoryResource.java
License:Apache License
/** * Build series with long running jobs//from www . ja v a 2 s .co m * * @param startTime * @param endTime * @param model * @return */ @RequestMapping("/longRunningJobsBetween2Date") @ApiOperation(value = "Build series with the most long running jobs between startDate and endDate") public @ResponseBody List<SerieDTO> longRunningJobsBetween2Date( @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy/MM/dd") DateTime startChartDT, @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy/MM/dd") DateTime endChartDT, Model model) { if ((startChartDT == null) || (endChartDT == null)) return null; Days days = Days.daysBetween(startChartDT, endChartDT); if (days.getDays() < 0) return new ArrayList<SerieDTO>(0); // 1 serie by day List<SerieDTO> series = new ArrayList<SerieDTO>(days.getDays()); for (int i = 0; i < days.getDays() + 1; i++) { // 1 serie contains the most long running jobs SerieDTO serie = new SerieDTO(); serie.setKey("Serie " + i + " in seconds"); List<PointDTO> points = new ArrayList<PointDTO>(); serie.setValues(points); series.add(serie); } for (int i = 0; i < days.getDays() + 1; i++) { List<SchedulerHistory> schedulerHistories = schedulerHistoryRepository .findByStartTimeBetweenAndDuringTime(new Timestamp(startChartDT.getMillis()), new Timestamp(startChartDT.plusDays(i).getMillis()), new PageRequest(0, days.getDays() + 1)); SerieDTO serie = series.get(days.getDays() - i); for (int j = 0; j < schedulerHistories.size(); j++) { List<PointDTO> points = (List<PointDTO>) serie.getValues(); PointDTO point = new PointDTO(); point.setX(startChartDT.plusDays(j).getMillis()); if (schedulerHistories.get(j).getEndTime() != null && schedulerHistories.get(j).getStartTime() != null) { long elapsedTime = schedulerHistories.get(j).getEndTime().getTime() - schedulerHistories.get(j).getStartTime().getTime(); point.setY(elapsedTime); } else point.setY(0L); points.add(point); } } return series; }
From source file:org.jpmml.evaluator.DaysSinceDate.java
License:Open Source License
public DaysSinceDate(LocalDate epoch, LocalDate date) { setEpoch(epoch); setDays(Days.daysBetween(epoch, date)); }
From source file:org.jraf.irondad.handler.countdown.CountDownHandler.java
License:Open Source License
private String getReply(String eventDateStr) { DateTime eventDateTime = DateTime.parse(eventDateStr); DateTime nowDateTime = DateTime.now(); String res = null;/*from w ww.j a v a2s. c o m*/ int nbDays = Days.daysBetween(nowDateTime.toLocalDateTime().toDateTime().withTimeAtStartOfDay(), eventDateTime.toLocalDateTime().toDateTime().withTimeAtStartOfDay()).getDays(); if (nbDays > 2) { res = "Dans " + nbDays + " jours !"; } else if (nbDays == 2) { res = "APRS-DEMAIN !!!"; } else if (nbDays == 1) { res = "DEMAIN !!!!!!"; } else if (nbDays == 0) { int nbHours = Hours.hoursBetween(nowDateTime, eventDateTime).getHours(); if (nbHours > 0) { if (nbHours == 1) res = "Dans " + nbHours + " heure (et quelques) !!"; else res = "Dans " + nbHours + " heures (et quelques) !"; } else if (nbHours < 0) { res = "C'est en ce moment."; } else { int nbMinutes = Minutes.minutesBetween(nowDateTime, eventDateTime).getMinutes(); if (nbMinutes > 0) { if (nbMinutes == 1) res = "Dans 1 minute !!!"; else res = "Dans " + nbMinutes + " minutes !!"; } else if (nbMinutes < 0) { res = "C'est en ce moment mme !!!!!"; } else { int nbSeconds = Seconds.secondsBetween(nowDateTime, eventDateTime).getSeconds(); if (nbSeconds > 0) res = "Dans " + nbSeconds + " secondes !!!!"; else if (nbSeconds < 0) res = "a commence !!!!!"; else res = "C'est commenc !!!!!"; } } } else if (nbDays == -1) { res = "C'est en ce moment..."; } else { res = "C'est fini :("; } return res; }
From source file:org.key2gym.client.highlighters.ExpirationDateHighlighter.java
License:Apache License
/** * Updates the component's highlight.// w w w . j a v a2 s .c o m */ @Override protected ColorScheme getHighlightModelFor(String text) { DateMidnight value; try { value = DateMidnight.parse(text, DateTimeFormat.forPattern("dd-MM-yyyy")); } catch (IllegalArgumentException ex) { value = null; } if (value == null) { return NULL_SCHEME; } int daysTillExpiration = Days.daysBetween(DateMidnight.now(), value).getDays(); if (daysTillExpiration > 2) { return NOT_SOON_SCHEME; } else if (daysTillExpiration > 0) { return SOON_SCHEME; } else { return PASSED_SCHEME; } }
From source file:org.killbill.billing.invoice.generator.InvoiceDateUtils.java
License:Apache License
public static BigDecimal calculateProrationBetweenDates(final LocalDate startDate, final LocalDate endDate, int daysBetween) { if (daysBetween <= 0) { return BigDecimal.ZERO; }/* w w w .jav a2s. com*/ final BigDecimal daysInPeriod = new BigDecimal(daysBetween); final BigDecimal days = new BigDecimal(Days.daysBetween(startDate, endDate).getDays()); return days.divide(daysInPeriod, KillBillMoney.MAX_SCALE, KillBillMoney.ROUNDING_METHOD); }
From source file:org.killbill.billing.invoice.tree.Item.java
License:Apache License
public InvoiceItem toProratedInvoiceItem(final LocalDate newStartDate, final LocalDate newEndDate) { int nbTotalDays = Days.daysBetween(startDate, endDate).getDays(); final boolean prorated = !(newStartDate.compareTo(startDate) == 0 && newEndDate.compareTo(endDate) == 0); // Pro-ration is built by using the startDate, endDate and amount of this item instead of using the rate and a potential full period. final BigDecimal positiveAmount = prorated ? InvoiceDateUtils .calculateProrationBetweenDates(newStartDate, newEndDate, nbTotalDays).multiply(amount) : amount; if (action == ItemAction.ADD) { return new RecurringInvoiceItem(id, createdDate, invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, newStartDate, newEndDate, KillBillMoney.of(positiveAmount, currency), rate, currency);/* w w w . j av a2 s .c o m*/ } else { // We first compute the maximum amount after adjustment and that sets the amount limit of how much can be repaired. final BigDecimal maxAvailableAmountAfterAdj = amount.subtract(adjustedAmount); final BigDecimal maxAvailableAmountForRepair = maxAvailableAmountAfterAdj .subtract(currentRepairedAmount); final BigDecimal positiveAmountForRepair = positiveAmount.compareTo(maxAvailableAmountForRepair) <= 0 ? positiveAmount : maxAvailableAmountForRepair; return positiveAmountForRepair.compareTo(BigDecimal.ZERO) > 0 ? new RepairAdjInvoiceItem(targetInvoiceId, accountId, newStartDate, newEndDate, KillBillMoney.of(positiveAmountForRepair.negate(), currency), currency, linkedId) : null; } }
From source file:org.killbill.billing.junction.plumbing.billing.BlockingStateService.java
License:Apache License
private void addDisabledDuration(final BlockingState firstBlockingState, @Nullable final DateTime disableDurationEndDate) { if (disableDurationEndDate == null || Days.daysBetween(firstBlockingState.getEffectiveDate(), disableDurationEndDate).getDays() >= 1) { // Don't disable for periods less than a day (see https://github.com/killbill/killbill/issues/267) result.add(new DisabledDuration(firstBlockingState.getEffectiveDate(), disableDurationEndDate)); }// www . j a va 2 s. c o m }
From source file:org.killbill.billing.util.timezone.DateAndTimeZoneContext.java
License:Apache License
static int computeOffsetFromUtc(final DateTime effectiveDateTime, final DateTimeZone accountTimeZone) { final LocalDate localDateInAccountTimeZone = new LocalDate(effectiveDateTime, accountTimeZone); final LocalDate localDateInUTC = new LocalDate(effectiveDateTime, DateTimeZone.UTC); return Days.daysBetween(localDateInUTC, localDateInAccountTimeZone).getDays(); }
From source file:org.kuali.coeus.propdev.impl.budget.ProposalBudgetNumberOfMonthsServiceImpl.java
License:Open Source License
@Override public double getNumberOfMonth(Date startDate, Date endDate) { if (startDate == null || endDate == null || startDate.after(endDate)) { return 0.00; }//from w w w . j a va 2s .c o m final DateTime start = new DateTime(startDate); final DateTime end = new DateTime(endDate).plusDays(1); final int daysInMonthForEndDate = end.dayOfMonth().getMaximumValue(); final int wholeMonths = Months.monthsBetween(start, end).getMonths(); final int daysRemaining = Days.daysBetween(start.plusMonths(wholeMonths), end).getDays(); //casting to ensure we don't loose precision final double numberOfMonths = wholeMonths + ((double) daysRemaining / (double) daysInMonthForEndDate); return new ScaleTwoDecimal(numberOfMonths).doubleValue(); }
From source file:org.kuali.kpme.tklm.utils.TkTestUtils.java
License:Educational Community License
public static Map<DateTime, BigDecimal> getDateToHoursMap(TimeBlock timeBlock, TimeHourDetail timeHourDetail) { Map<DateTime, BigDecimal> dateToHoursMap = new HashMap<DateTime, BigDecimal>(); DateTime beginTime = timeBlock.getBeginDateTime(); DateTime endTime = timeBlock.getEndDateTime(); Days d = Days.daysBetween(beginTime, endTime); int numberOfDays = d.getDays(); if (numberOfDays < 1) { dateToHoursMap.put(timeBlock.getBeginDateTime(), timeHourDetail.getHours()); return dateToHoursMap; }// w ww . j a v a 2s.c o m DateTime currentTime = beginTime; for (int i = 0; i < numberOfDays; i++) { DateTime nextDayAtMidnight = currentTime.plusDays(1); nextDayAtMidnight = nextDayAtMidnight.hourOfDay().setCopy(12); nextDayAtMidnight = nextDayAtMidnight.minuteOfDay().setCopy(0); nextDayAtMidnight = nextDayAtMidnight.secondOfDay().setCopy(0); nextDayAtMidnight = nextDayAtMidnight.millisOfSecond().setCopy(0); Duration dur = new Duration(currentTime, nextDayAtMidnight); long duration = dur.getStandardSeconds(); BigDecimal hrs = new BigDecimal(duration / 3600, HrConstants.MATH_CONTEXT); dateToHoursMap.put(currentTime, hrs); currentTime = nextDayAtMidnight; } Duration dur = new Duration(currentTime, endTime); long duration = dur.getStandardSeconds(); BigDecimal hrs = new BigDecimal(duration / 3600, HrConstants.MATH_CONTEXT); dateToHoursMap.put(currentTime, hrs); return dateToHoursMap; }