List of usage examples for org.joda.time Days getDays
public int getDays()
From source file:com.nitdlibrary.EditViewStudent.java
/** * THIS FUNCTION CALCULATES DATA FOR FILTERED RESULTSET AND UPDATES THE LABELS * @param from/*from ww w. jav a2 s . c o m*/ * @param to */ private void calculateFilteredPerformance(LocalDate from, LocalDate to) throws SQLException { issueFilteredResultSet.beforeFirst(); Date returnDate = null, dueDate = null; LocalDate returnDateJoda = null, dueDateJoda = null; int totalIssued = 0, returned = 0, fine = 0, currentIssue = 0; int flag = 0; //incremented when today is > due date and return_date is null. it means that some books are not returned and fine calc is shown wrt today while (issueFilteredResultSet.next()) { totalIssued++; if (issueFilteredResultSet.getString("return_date") != null) returned++; DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); try { dueDate = format.parse(issueFilteredResultSet.getString("due_date")); /** * IF BOOK HAS NOT BEEN RETURNED AND TODAY>DUEDATE .. FINE TO BE PAID IS SHOWN */ if (issueFilteredResultSet.getString("return_date") != null && (issueFilteredResultSet.getString("return_date").compareTo("") != 0)) { returnDate = format.parse(issueFilteredResultSet.getString("return_date")); } else { String tempDate = format.format(new Date()); returnDate = format.parse(tempDate); if (dueDate.before(returnDate)) // i.e due date before today and book is not returned. flag++; } returnDateJoda = new LocalDate(returnDate); dueDateJoda = new LocalDate(dueDate); } catch (ParseException ex) { Logger.getLogger(EditViewStudent.class.getName()).log(Level.SEVERE, null, ex); } if (dueDate.before(returnDate)) { Days d = Days.daysBetween(dueDateJoda, returnDateJoda); fine += d.getDays(); } if (issueFilteredResultSet.getString("return_date") == null || (issueFilteredResultSet.getString("return_date").compareTo("") == 0)) { currentIssue++; } } /** * setting values in Labels */ issuedFiltered.setText("Total Books Issued : " + totalIssued); returnedFiltered.setText("Total Books Returned : " + returned); if (fine < 0) fine = 0; fineFiltered.setText("Total Fine : " + fine); currentFiltered.setText("Currently issued book count : " + currentIssue); if (flag != 0) { //exceedLabel.setText("* "+ flag +" books have exceeded due date and are not returned. Assuming they are retuned today, total fine is being shown."); } }
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 ""; }// w w w .j a v a 2 s . com 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.rapidminer.operator.GenerateDateSeries.java
License:Open Source License
private long calculateNumberOfExample(DateTime startTime, DateTime endTime) { // TODO Auto-generated method stub long valuetoReturn = 0; try {//from w w w . j av a2 s .c o m //getParameterAsString(key) switch (getParameterAsString(PARAMETER_INTERVALTYPE)) { case "YEAR": Years year = Years.yearsBetween(startTime, endTime); valuetoReturn = year.getYears() / getParameterAsInt(INTERVAL); break; case "MONTH": Months month = Months.monthsBetween(startTime, endTime); valuetoReturn = month.getMonths() / getParameterAsInt(INTERVAL); break; case "DAY": Days days = Days.daysBetween(startTime, endTime); valuetoReturn = days.getDays() / getParameterAsInt(INTERVAL); break; case "HOUR": Hours hours = Hours.hoursBetween(startTime, endTime); valuetoReturn = hours.getHours() / getParameterAsInt(INTERVAL); break; case "MINUTE": Minutes minute = Minutes.minutesBetween(startTime, endTime); valuetoReturn = minute.getMinutes() / getParameterAsInt(INTERVAL); break; case "SECOND": Seconds second = Seconds.secondsBetween(startTime, endTime); valuetoReturn = second.getSeconds() / getParameterAsInt(INTERVAL); break; case "MILLISECOND": // Milliseconds millisecond = milli long milli = endTime.getMillis() - startTime.getMillis(); valuetoReturn = milli / getParameterAsInt(INTERVAL); break; default: valuetoReturn = 0; } } catch (Exception e) { valuetoReturn = 0; } return valuetoReturn; }
From source file:com.splicemachine.db.iapi.types.SQLDate.java
License:Apache License
@Override public NumberDataValue minus(DateTimeDataValue leftOperand, DateTimeDataValue rightOperand, NumberDataValue returnValue) throws StandardException { if (returnValue == null) returnValue = new SQLInteger(); if (leftOperand.isNull() || isNull() || rightOperand.isNull()) { returnValue.restoreToNull();//w w w . ja va 2 s. c o m return returnValue; } DateTime thatDate = rightOperand.getDateTime(); Days diff = Days.daysBetween(thatDate, leftOperand.getDateTime()); returnValue.setValue(diff.getDays()); return returnValue; }
From source file:com.splicemachine.db.iapi.types.SQLTimestamp.java
License:Apache License
@Override public NumberDataValue minus(DateTimeDataValue leftOperand, DateTimeDataValue rightOperand, NumberDataValue resultHolder) throws StandardException { if (resultHolder == null) resultHolder = new SQLInteger(); if (leftOperand.isNull() || isNull() || rightOperand.isNull()) { resultHolder.restoreToNull();//w ww . j av a 2 s . c o m return resultHolder; } DateTime thatDate = rightOperand.getDateTime(); Days diff = Days.daysBetween(thatDate, leftOperand.getDateTime()); resultHolder.setValue(diff.getDays()); return resultHolder; }
From source file:com.squid.kraken.v4.api.core.EngineUtils.java
License:Open Source License
/** * Convert the facet value into a date. * If the value start with '=', it is expected to be a Expression, in which case we'll try to resolve it to a Date constant. * @param ctx// ww w. j av a2 s.c om * @param index * @param lower * @param value * @param compareFromInterval * @return * @throws ParseException * @throws ScopeException * @throws ComputingException */ public Date convertToDate(Universe universe, DimensionIndex index, Bound bound, String value, IntervalleObject compareFromInterval) throws ParseException, ScopeException, ComputingException { if (value.equals("")) { return null; } else if (value.startsWith("__")) { // // support hard-coded shortcuts if (value.toUpperCase().startsWith("__COMPARE_TO_")) { // for compareTo if (compareFromInterval == null) { // invalid compare_to selection... return null; } if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_PERIOD")) { LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime()); if (bound == Bound.UPPER) { LocalDate date = localLower.minusDays(1); return date.toDate(); } else { LocalDate localUpper = new LocalDate( ((Date) compareFromInterval.getUpperBound()).getTime()); Days days = Days.daysBetween(localLower, localUpper); LocalDate date = localLower.minusDays(1 + days.getDays()); return date.toDate(); } } if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_MONTH")) { LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime()); LocalDate compareLower = localLower.minusMonths(1); if (bound == Bound.LOWER) { return compareLower.toDate(); } else { LocalDate localUpper = new LocalDate( ((Date) compareFromInterval.getUpperBound()).getTime()); Days days = Days.daysBetween(localLower, localUpper); LocalDate compareUpper = compareLower.plusDays(days.getDays()); return compareUpper.toDate(); } } if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_YEAR")) { LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime()); LocalDate compareLower = localLower.minusYears(1); if (bound == Bound.LOWER) { return compareLower.toDate(); } else { LocalDate localUpper = new LocalDate( ((Date) compareFromInterval.getUpperBound()).getTime()); Days days = Days.daysBetween(localLower, localUpper); LocalDate compareUpper = compareLower.plusDays(days.getDays()); return compareUpper.toDate(); } } } else { // for regular // get MIN, MAX first Intervalle range = null; if (index.getDimension().getType() == Type.CONTINUOUS) { if (index.getStatus() == Status.DONE) { List<DimensionMember> members = index.getMembers(); if (!members.isEmpty()) { DimensionMember member = members.get(0); Object object = member.getID(); if (object instanceof Intervalle) { range = (Intervalle) object; } } } else { try { DomainHierarchy hierarchy = universe .getDomainHierarchy(index.getAxis().getParent().getDomain()); hierarchy.isDone(index, null); } catch (ComputingException | InterruptedException | ExecutionException | TimeoutException e) { throw new ComputingException("failed to retrieve period interval"); } } } if (range == null) { range = IntervalleObject.createInterval(new Date(), new Date()); } if (value.equalsIgnoreCase("__ALL")) { if (index.getDimension().getType() != Type.CONTINUOUS) { return null; } if (bound == Bound.UPPER) { return (Date) range.getUpperBound(); } else { return (Date) range.getLowerBound(); } } if (value.equalsIgnoreCase("__LAST_DAY")) { if (bound == Bound.UPPER) { return (Date) range.getUpperBound(); } else { return (Date) range.getUpperBound(); } } if (value.equalsIgnoreCase("__LAST_7_DAYS")) { if (bound == Bound.UPPER) { return (Date) range.getUpperBound(); } else { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.minusDays(6);// 6+1 return date.toDate(); } } if (value.equalsIgnoreCase("__CURRENT_MONTH")) { if (bound == Bound.UPPER) { return (Date) range.getUpperBound(); } else { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.withDayOfMonth(1); return date.toDate(); } } if (value.equalsIgnoreCase("__CURRENT_YEAR")) { if (bound == Bound.UPPER) { return (Date) range.getUpperBound(); } else { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1); return date.toDate(); } } if (value.equalsIgnoreCase("__PREVIOUS_MONTH")) {// the previous complete month if (bound == Bound.UPPER) { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.withDayOfMonth(1).minusDays(1); return date.toDate(); } else { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.withDayOfMonth(1).minusMonths(1); return date.toDate(); } } if (value.equalsIgnoreCase("__PREVIOUS_YEAR")) {// the previous complete month if (bound == Bound.UPPER) { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1).minusDays(1); return date.toDate(); } else { LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime()); LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1).minusYears(1); return date.toDate(); } } } throw new ScopeException("undefined facet expression alias: " + value); } else if (value.startsWith("=")) { // if the value starts by equal token, this is a formula that can be // evaluated try { String expr = value.substring(1); // check if the index content is available or wait for it DomainHierarchy hierarchy = universe.getDomainHierarchy(index.getAxis().getParent().getDomain(), true); hierarchy.isDone(index, null); // evaluate the expression Object defaultValue = evaluateExpression(universe, index, expr, compareFromInterval); // check we can use it if (defaultValue == null) { //throw new ScopeException("unable to parse the facet expression as a constant: " + expr); // T1769: it's ok to return null return null; } if (!(defaultValue instanceof Date)) { throw new ScopeException("unable to parse the facet expression as a date: " + expr); } // ok, it's a date return (Date) defaultValue; } catch (ComputingException | InterruptedException | ExecutionException | TimeoutException e) { throw new ComputingException("failed to retrieve period interval"); } } else { Date date = ServiceUtils.getInstance().toDate(value); if (bound == Bound.UPPER && !index.getAxis().getDefinitionSafe().getImageDomain().isInstanceOf(IDomain.TIME)) { // clear the timestamp return new LocalDate(date.getTime()).toDate(); } else { return date; } } }
From source file:com.toedter.jcalendar.core.DateChooser.java
License:Open Source License
private void computeDayCellValues() { DateTime firstDayThisMonth = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), 1, 0, 0, 0, 0); DateTime firstDayNextMonth = firstDayThisMonth.plusMonths(1).withDayOfMonth(1); int dayOfWeek = firstDayThisMonth.dayOfWeek().get(); Days d = Days.daysBetween(firstDayThisMonth, firstDayNextMonth); int daysInThisMonth = d.getDays(); System.out.println(daysInThisMonth); int index = 2; for (IDayCell dayCell : dayCells) { if (index <= dayOfWeek || index - dayOfWeek > daysInThisMonth) { ((DayCell) dayCell).dayText = ""; } else {//from ww w . j a v a 2s. c o m ((DayCell) dayCell).dayText = "" + (index - dayOfWeek); } index++; } }
From source file:com.verigreen.collector.jobs.CacheCleanerJob.java
License:Apache License
private boolean isExceedThreashold(Date date) { Days daysBetweenCreationTimeAndNow = Days.daysBetween(new DateTime(date), DateTime.now()); return daysBetweenCreationTimeAndNow.getDays() >= Integer .parseInt(VerigreenNeededLogic.VerigreenMap.get("daysThreashold")); }
From source file:controllers.chqbll.Partials.java
License:Open Source License
/** * Kayit isleminden once form uzerinde bulunan verilerin uygunlugunu kontrol eder * //from www . j av a2s . com * @param filledForm */ private static void checkConstraints(Form<ChqbllPartialList> filledForm) { ChqbllPartialList model = filledForm.get(); if (model.paid.doubleValue() < 1) { filledForm.reject("payment", Messages.get("error.min.strict", 0)); } if (model.remaining.doubleValue() < 0) { filledForm.reject("remain", Messages.get("error.min", 0)); } List<ValidationError> veList = new ArrayList<ValidationError>(); if (model.details != null && model.details.size() > 0) { ChqbllPayrollDetail detail = ChqbllPayrollDetail.findById(model.detailId); DateTime dueDate = new DateTime(detail.dueDate); for (int i = 1; i < model.details.size() + 1; i++) { ChqbllDetailPartial std = model.details.get(i - 1); if (std.amount == null || std.amount <= 0) { veList.add(new ValidationError("partials", Messages.get("cannot.be.zero.table", i))); } if (std.transDate == null) { veList.add(new ValidationError("partials", Messages.get("is.not.null.for.table", i, Messages.get("date.maturity")))); } else { DateTime transDate = new DateTime(std.transDate); Days days = Days.daysBetween(dueDate, transDate); if (days.getDays() < 0) { veList.add( new ValidationError("partials", Messages.get("date.less.from.due.for.table", i))); } } } } else { veList.add(new ValidationError("partials", Messages.get("table.min.row.alert"))); } if (veList.size() > 0) { filledForm.errors().put("partials", veList); } }
From source file:controllers.chqbll.Payrolls.java
License:Open Source License
private static void checkSecondConstraints(Form<ChqbllPayroll> filledForm) { ChqbllPayroll model = filledForm.get(); List<ValidationError> veList = new ArrayList<ValidationError>(); if (model.details != null && model.details.size() > 0) { DateTime transDate = new DateTime(model.transDate); for (int i = 1; i < model.details.size() + 1; i++) { ChqbllPayrollDetail std = model.details.get(i - 1); if (std.amount == null || std.amount <= 0) { veList.add(new ValidationError("chqblls", Messages.get("cannot.be.zero.table", i))); }//from w w w . ja v a 2 s .c o m if (std.dueDate == null) { veList.add(new ValidationError("chqblls", Messages.get("is.not.null.for.table", i, Messages.get("date.maturity")))); } else if (isNormalPayroll(model.right)) { DateTime dueDate = new DateTime(std.dueDate); Days days = Days.daysBetween(transDate, dueDate); if (days.getDays() < 1) { veList.add(new ValidationError("chqblls", Messages.get("duedate.close.for.table", i))); } } } } else { veList.add(new ValidationError("chqblls", Messages.get("table.min.row.alert"))); } if (veList.size() > 0) { filledForm.errors().put("chqblls", veList); } }