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:com.parleys.server.frontend.web.html5.util.JSFUtil.java
License:Apache License
public static String formatDate(final Date date) { if (date == null) { return ""; }/*from w w w. j a v a2 s .c o m*/ final DateTime start = new DateTime(date.getTime()); final DateTime end = new DateTime(new Date()); final Days daysAgo = Days.daysBetween(start, end); final int days = daysAgo.getDays(); String whileAgoPosted; if (days == 0) { whileAgoPosted = "today"; } else if (days == 1) { whileAgoPosted = "yesterday"; } else if (days < 7) { whileAgoPosted = days + " days ago"; } else if (days < 32) { int week = Math.round(days / 7); whileAgoPosted = week + (week > 1 ? " weeks ago" : " week ago"); } else if (days < 365) { whileAgoPosted = Math.round(days / 30) + " months ago"; } else { int year = Math.round(days / 365); whileAgoPosted = year + ((year > 1) ? " years ago" : " year ago"); } return whileAgoPosted; }
From source file:com.pearson.eidetic.driver.MonitorMethods.java
public int getDaysBetweenNowAndNewestSnapshot(List<Snapshot> sortedCompareList) { if (sortedCompareList == null || sortedCompareList.isEmpty()) { return -1; }/*from ww w . ja v a2 s .c o m*/ DateTime now = new DateTime(); DateTime dt = new DateTime(sortedCompareList.get(sortedCompareList.size() - 1).getStartTime()); return Days.daysBetween(dt, now).getDays(); }
From source file:com.pearson.eidetic.driver.threads.EideticSubThreadMethods.java
@Override public int getDaysBetweenNowAndNewestSnapshot(List<Snapshot> sortedCompareList) { if (sortedCompareList == null || sortedCompareList.isEmpty()) { return -1; }/* w w w .j a v a 2s . co m*/ DateTime now = new DateTime(); DateTime dt = new DateTime(sortedCompareList.get(sortedCompareList.size() - 1).getStartTime()); return Days.daysBetween(dt, now).getDays(); }
From source file:com.pearson.eidetic.driver.threads.EideticSubThreadMethods.java
public int getDaysBetweenNowAndSnapshot(Snapshot snapshot) { DateTime now = new DateTime(); DateTime dt = new DateTime(snapshot.getStartTime()); return Days.daysBetween(dt, now).getDays(); }
From source file:com.pfm.controllers.UpcomingPaymentsRestController.java
private Integer getDaysBetweenDates(Date start, Date end) { Integer days = 0;//from ww w . j av a 2s. c o m DateTime startDate = new DateTime(start); DateTime endDate = new DateTime(end); days = Days.daysBetween(startDate, endDate).getDays(); return days; }
From source file:com.pfm.utils.recuringPayments.RecuringPaymentsOverviewManager.java
public static Integer getPeriodsInInterval(Integer recuringType, Date startDate, Date endDate) { Integer periods = 0;//from ww w . ja va2 s .c o m DateTime start = new DateTime(startDate); DateTime end = new DateTime(endDate); if (Objects.equals(recuringType, RecurringTypes.Daily.getValue())) { periods = Days.daysBetween(start, end).getDays(); } if (Objects.equals(recuringType, RecurringTypes.Weekly.getValue())) { periods = Weeks.weeksBetween(start, end).getWeeks(); } if (Objects.equals(recuringType, RecurringTypes.Monthly.getValue())) { periods = Months.monthsBetween(start, end).getMonths(); } if (Objects.equals(recuringType, RecurringTypes.Yearly.getValue())) { periods = Years.yearsBetween(start, end).getYears(); } return periods; }
From source file:com.popdeem.sdk.uikit.utils.PDUIUtils.java
License:Open Source License
/** * Method to calculate the time until (Needs refactoring) * * @param expiryTimeInSeconds {@link Long} value for expiry time in seconds * @param nonClaimedReward {@link Boolean} * @param isSweepstakes {@link Boolean} * @return {@link String} value for time until *//* ww w . j av a2 s . co m*/ public static String timeUntil(long expiryTimeInSeconds, boolean nonClaimedReward, boolean isSweepstakes) { final DateTime now = DateTime.now(); final DateTime expiry = new DateTime(expiryTimeInSeconds * 1000); // Check if reward has expired if (expiry.isBefore(now)) { return "Reward has expired"; } // Days int days = Days.daysBetween(now, expiry).getDays(); if (days == 1) { if (isSweepstakes) { return "1 day"; } else { return nonClaimedReward ? "1 day remaining" : "Expires in 1 day"; } } if (days > 1) { if (isSweepstakes) { return days + " days"; } else { return nonClaimedReward ? days + " days remaining" : "Expires in " + days + " days"; } } // Hours int hours = Hours.hoursBetween(now, expiry).getHours(); if (hours == 1) { if (isSweepstakes) { return "1 hour"; } else { return nonClaimedReward ? "1 hour remaining" : "Expires in 1 hour"; } } if (hours > 1) { if (isSweepstakes) { return hours + " hours"; } else { return nonClaimedReward ? hours + " hours remaining" : "Expires in " + hours + " hours"; } } // Minutes int minutes = Minutes.minutesBetween(now, expiry).getMinutes(); if (minutes == 1) { if (isSweepstakes) { return "1 minute"; } else { return nonClaimedReward ? "1 minute remaining" : "Expires in 1 minute"; } } if (isSweepstakes) { return minutes + " minutes"; } else return nonClaimedReward ? minutes + " minutes remaining" : "Expires in " + minutes + " minutes"; }
From source file:com.qcadoo.mes.assignmentToShift.print.xls.AssignmentToShiftXlsHelper.java
License:Open Source License
public List<DateTime> getDaysBetweenGivenDates(final Entity entity) { List<DateTime> days = new LinkedList<DateTime>(); DateTime dateFrom = new DateTime((Date) entity.getField(DATE_FROM)); DateTime dateTo = new DateTime((Date) entity.getField(DATE_TO)); DateTime nextDay = dateFrom;//from ww w. java2 s . com int numberOfDays = Days.daysBetween(dateFrom.toDateMidnight(), dateTo.toDateMidnight()).getDays(); days.add(nextDay); int oneDay = 1; while (numberOfDays != 0) { nextDay = nextDay.plusDays(oneDay).toDateTime(); days.add(nextDay); numberOfDays--; } return days; }
From source file:com.qcadoo.mes.assignmentToShift.print.xls.AssignmentToShiftXlsHelper.java
License:Open Source License
public int getNumberOfDaysBetweenGivenDates(final Entity entity) { DateTime dateFrom = new DateTime((Date) entity.getField(DATE_FROM)); DateTime dateTo = new DateTime((Date) entity.getField(DATE_TO)); return Days.daysBetween(dateFrom.toDateMidnight(), dateTo.toDateMidnight()).getDays(); }
From source file:com.qcadoo.mes.avgLaborCostCalcForOrder.AverageCostService.java
License:Open Source License
private List<DateTime> getDaysBetweenGivenDates(final Date start, final Date finish) { List<DateTime> days = new LinkedList<DateTime>(); DateTime startDate = new DateTime(start); DateTime finishDate = new DateTime(finish); DateTime nextDay = startDate;// w ww .j a va 2 s . c o m int numberOfDays = Days.daysBetween(startDate.toDateMidnight(), finishDate.toDateMidnight()).getDays(); days.add(nextDay); int oneDay = 1; while (numberOfDays != 0) { nextDay = nextDay.plusDays(oneDay).toDateTime(); days.add(nextDay); numberOfDays--; } return days; }