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.carhire.rentals.bookingwizard.BookingWizardAction.java
@Override public void actionPerformed(ActionEvent e) { List<WizardDescriptor.Panel<WizardDescriptor>> panels = new ArrayList<WizardDescriptor.Panel<WizardDescriptor>>(); panels.add(new BookingWizardPanel1()); panels.add(new BookingWizardPanel2()); panels.add(new BookingWizardPanel3()); panels.add(new BookingWizardPanel4()); String[] steps = new String[panels.size()]; for (int i = 0; i < panels.size(); i++) { Component c = panels.get(i).getComponent(); // Default step name to component name of panel. steps[i] = c.getName();/*from w w w . j a v a 2s. c om*/ if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent) c; jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, true); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true); } } WizardDescriptor wiz = new WizardDescriptor(new WizardDescriptor.ArrayIterator<WizardDescriptor>(panels)); // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName() wiz.setTitleFormat(new MessageFormat("{0}")); wiz.setTitle("Make New Booking"); if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) { // do something Customer customer = (Customer) wiz.getProperty("customer"); Vehicle vehicle = (Vehicle) wiz.getProperty("vehicle"); String lossDW = (String) wiz.getProperty("lossDW"); String suppLI = (String) wiz.getProperty("suppLI"); String pAI = (String) wiz.getProperty("pAI"); String thirdPI = (String) wiz.getProperty("thirdPI"); Date dateRented = (Date) wiz.getProperty("daterented"); Date dateToReturn = (Date) wiz.getProperty("dateToReturn"); Branch branch = (Branch) wiz.getProperty("branch"); Staff staff = (Staff) wiz.getProperty("staff"); DateTime drent = new DateTime(dateRented); DateTime dreturn = new DateTime(dateToReturn); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String customername = customer.getFullname(); String customeremail = customer.getEmailaddress(); String vehicledetails = vehicle.getDescription(); String paidon = dateFormat.format(dateRented); int days = Days.daysBetween(drent, dreturn).getDays(); String returndate = dateFormat.format(dateToReturn); StringBuilder insurance = new StringBuilder(); insurance.append("Loss Damage Waiver: " + lossDW + "\n"); insurance.append("Personal Accidental Insurance: " + pAI + "\n"); insurance.append("Supplemental Loss Insuarnce: " + suppLI + "\n"); insurance.append("Third Party Insuarnce: " + thirdPI + "\n"); String concatinsurance = insurance.toString(); double price = 50.0 + 50 * days; sendReceipt(customername, customeremail, vehicledetails, paidon, returndate, concatinsurance, price); Installer.EM.getTransaction().begin(); Booking booking = new Booking(); booking.setCustomer(customer); booking.setVehicle(vehicle); booking.setLossDW(lossDW); booking.setSuppLI(suppLI); booking.setThirdPI(thirdPI); booking.setpAI(pAI); booking.setDateRented(dateRented); booking.setDateToReturn(dateToReturn); booking.setDateCreated(new Date()); booking.setPrice(price); booking.setBranch(branch); booking.setStaff(staff); Installer.EM.persist(booking); Installer.EM.getTransaction().commit(); } }
From source file:org.codeqinvest.codechanges.WeightedCodeChangeProbabilityCalculator.java
License:Open Source License
/** * {@inheritDoc}/*from ww w .j a va2 s .c o m*/ */ @Override protected double computeChangeProbability(int days, Collection<DailyCodeChurn> codeChurns) { if (codeChurns.isEmpty()) { return 0.0; } final double numberOfDays = days + 1; final SortedSet<DailyCodeChurn> sortedCodeChurns = sortDescendingByDay(codeChurns); final LocalDate startDay = sortedCodeChurns.first().getDay(); double changeProbability = 0.0; for (DailyCodeChurn codeChurn : sortedCodeChurns) { final int numberOfCurrentDay = Days.daysBetween(codeChurn.getDay(), startDay).getDays(); for (double churnProportion : codeChurn.getCodeChurnProportions()) { final double weight = ((numberOfDays - numberOfCurrentDay) * Math.exp((days - numberOfCurrentDay) / numberOfDays)) / (numberOfDays * numberOfDays); changeProbability += churnProportion * weight; } } return changeProbability; }
From source file:org.datacleaner.beans.DateAndTimeAnalyzerResult.java
License:Open Source License
protected static Number convertToDaysSinceEpoch(String s) { if (s == null) { return null; }//from w w w . j a va 2 s . com final LocalDate epoch = new LocalDate(1970, 1, 1); final Date date = ConvertToDateTransformer.getInternalInstance().transformValue(s); if (date == null) { logger.warn("Could not parse date string: '{}', returning null metric value.", s); return null; } int days = Days.daysBetween(epoch, new LocalDate(date)).getDays(); return days; }
From source file:org.egov.adtax.service.penalty.AdvertisementPenaltyCalculatorImpl.java
License:Open Source License
private int calculateNumberOfDaysForPenaltyCalculation(final AdvertisementPermitDetail advPermitDetail, final EgDemandDetails demandDtl) { int days = 0; // Eg: Next year installment if (demandDtl.getInstallmentStartDate().after(new Date())) days = Days.daysBetween(new DateTime(demandDtl.getInstallmentStartDate()), new DateTime(new Date())) .getDays();// w w w. ja v a2s. co m else if (demandDtl.getInstallmentStartDate().before(new Date())) if (advPermitDetail.getAdvertisement().getPenaltyCalculationDate() != null && demandDtl.getInstallmentStartDate() .before(advPermitDetail.getAdvertisement().getPenaltyCalculationDate()) && (demandDtl.getInstallmentEndDate() .equals(advPermitDetail.getAdvertisement().getPenaltyCalculationDate()) || demandDtl.getInstallmentEndDate() .after(advPermitDetail.getAdvertisement().getPenaltyCalculationDate()))) days = Days .daysBetween(new DateTime(advPermitDetail.getAdvertisement().getPenaltyCalculationDate()), new DateTime(new Date())) .getDays(); else days = Days.daysBetween(new DateTime(demandDtl.getInstallmentStartDate()), new DateTime(new Date())) .getDays(); return days; }
From source file:org.egov.infra.utils.DateUtils.java
License:Open Source License
public static int daysBetween(LocalDate startDate, LocalDate endDate) { return Days.daysBetween(startDate, endDate).getDays(); }
From source file:org.egov.infra.web.controller.HomeController.java
License:Open Source License
private int daysToExpirePassword(User user) { return Days.daysBetween(new LocalDate(), user.getPwdExpiryDate().toLocalDate()).getDays(); }
From source file:org.egov.mrs.application.service.MarriageFeeCalculatorImpl.java
License:Open Source License
@Override public Double calculateMarriageRegistrationFee(final MarriageRegistration marriageRegistration, final Date dateOfMarriage) { Double fee = null;/*www . j av a 2s . com*/ final AppConfigValues allowValidation = marriageFeeService.getDaysValidationAppConfValue( MarriageConstants.MODULE_NAME, MarriageConstants.MARRIAGEREGISTRATION_DAYS_VALIDATION); final int days = Days.daysBetween(new DateTime(dateOfMarriage), new DateTime(new Date())).getDays(); if (allowValidation != null && !allowValidation.getValue().isEmpty()) if ("NO".equalsIgnoreCase(allowValidation.getValue())) { fee = checkMarriageFeeForCriteria(days); } else if ("YES".equalsIgnoreCase(allowValidation.getValue()) && days <= 90) { fee = checkMarriageFeeForCriteria(days); } return fee; }
From source file:org.egov.ptis.client.util.PropertyTaxUtil.java
License:Open Source License
/** * Returns the number of days between fromDate and toDate * * @param fromDate the date//from ww w . ja v a2s. c o m * @param toDate the date * @return Long the number of days */ public static Long getNumberOfDays(final Date fromDate, final Date toDate) { LOGGER.debug("Entered into getNumberOfDays, fromDate=" + fromDate + ", toDate=" + toDate); final DateTime startDate = new DateTime(fromDate); final DateTime endDate = new DateTime(toDate); Integer days = Days.daysBetween(startDate, endDate).getDays(); days = days < 0 ? 0 : days; return Long.valueOf(days.longValue()); }
From source file:org.encuestame.utils.DateUtil.java
License:Apache License
/** * Get Days Between Dates./* w w w . ja va 2 s.c o m*/ * @param startDate * @return */ public static Integer getDaysBetweenDates(final Date startDate) { final DateTime currentDate = new DateTime(); final DateTime storedDate = new DateTime(startDate); final Days daysBetween = Days.daysBetween(storedDate, currentDate); return daysBetween.getDays(); }
From source file:org.extensiblecatalog.ncip.v2.koha.KohaLookupUserService.java
License:Open Source License
private void updateResponseData(ILSDIvOneOneLookupUserInitiationData initData, ILSDIvOneOneLookupUserResponseData responseData, JSONObject kohaUser, KohaRemoteServiceManager svcMgr) throws ParseException, KohaException { ResponseHeader responseHeader = KohaUtil.reverseInitiationHeader(initData); if (responseHeader != null) responseData.setResponseHeader(responseHeader); UserId userId = KohaUtil.createUserId(initData.getUserId().getUserIdentifierValue(), LocalConfig.getDefaultAgency()); responseData.setUserId(userId);/* ww w .ja va 2s . com*/ UserOptionalFields userOptionalFields = new UserOptionalFields(); if (LocalConfig.useRestApiInsteadOfSvc()) { if (initData.getNameInformationDesired()) { String firstname = (String) kohaUser.get("firstname"); String surname = (String) kohaUser.get("surname"); String title = (String) kohaUser.get("title"); String othernames = (String) kohaUser.get("othernames"); StructuredPersonalUserName structuredPersonalUserName = new StructuredPersonalUserName(); structuredPersonalUserName.setGivenName(firstname); structuredPersonalUserName.setPrefix(title); structuredPersonalUserName.setSurname(surname); structuredPersonalUserName.setSuffix(othernames); PersonalNameInformation personalNameInformation = new PersonalNameInformation(); personalNameInformation.setStructuredPersonalUserName(structuredPersonalUserName); NameInformation nameInformation = new NameInformation(); nameInformation.setPersonalNameInformation(personalNameInformation); userOptionalFields.setNameInformation(nameInformation); } if (initData.getUserAddressInformationDesired()) userOptionalFields.setUserAddressInformations(KohaUtil.parseUserAddressInformations(kohaUser)); if (initData.getUserPrivilegeDesired()) { String branchcode = (String) kohaUser.get("branchcode"); String agencyUserPrivilegeType = (String) kohaUser.get("categorycode"); if (branchcode != null && agencyUserPrivilegeType != null) { List<UserPrivilege> userPrivileges = new ArrayList<UserPrivilege>(); UserPrivilege userPrivilege = new UserPrivilege(); userPrivilege.setAgencyId(new AgencyId(branchcode)); userPrivilege.setAgencyUserPrivilegeType(new AgencyUserPrivilegeType( "http://www.niso.org/ncip/v1_0/imp1/schemes/agencyuserprivilegetype/agencyuserprivilegetype.scm", agencyUserPrivilegeType)); userPrivilege.setValidFromDate( KohaUtil.parseGregorianCalendarFromKohaDate((String) kohaUser.get("dateenrolled"))); userPrivilege.setValidToDate( KohaUtil.parseGregorianCalendarFromKohaDate((String) kohaUser.get("dateexpiry"))); userPrivileges.add(userPrivilege); userOptionalFields.setUserPrivileges(userPrivileges); } } if (initData.getDateOfBirthDesired()) { String dateOfBirth = (String) kohaUser.get("dateofbirth"); userOptionalFields.setDateOfBirth(KohaUtil.parseGregorianCalendarFromKohaDate(dateOfBirth)); } if (initData.getLoanedItemsDesired()) { JSONArray checkouts = (JSONArray) kohaUser.get("checkouts"); if (checkouts != null && checkouts.size() != 0) { List<LoanedItem> loanedItems = new ArrayList<LoanedItem>(); for (int i = 0; i < checkouts.size(); ++i) { JSONObject checkout = (JSONObject) checkouts.get(i); loanedItems.add(KohaUtil.parseLoanedItem(checkout)); } responseData.setLoanedItems(loanedItems); } } if (initData.getRequestedItemsDesired()) { JSONArray holds = (JSONArray) kohaUser.get("holds"); if (holds != null && holds.size() != 0) { List<RequestedItem> requestedItems = new ArrayList<RequestedItem>(); for (int i = 0; i < holds.size(); ++i) { JSONObject hold = (JSONObject) holds.get(i); RequestedItem requestedItem = KohaUtil.parseRequestedItem(hold); if (requestedItem != null) requestedItems.add(requestedItem); } responseData.setRequestedItems(requestedItems); } } if (initData.getBlockOrTrapDesired()) { List<BlockOrTrap> blocks = new ArrayList<BlockOrTrap>(4); // Parse expiration GregorianCalendar expiryDate = KohaUtil .parseGregorianCalendarFromKohaDate((String) kohaUser.get("dateexpiry")); GregorianCalendar warningForExpiryDateGregCal = ((GregorianCalendar) expiryDate.clone()); warningForExpiryDateGregCal.add(GregorianCalendar.DAY_OF_YEAR, -14); Date now = new Date(); if (now.after(expiryDate.getTime())) { BlockOrTrap expired = KohaUtil.createBlockOrTrap("Expired"); blocks.add(expired); } else if (now.after(warningForExpiryDateGregCal.getTime())) { Days days = Days.daysBetween(new DateTime(now), new DateTime(expiryDate)); BlockOrTrap expiresSoon = KohaUtil .createBlockOrTrap("Expires in " + (days.getDays() + 1) + " days"); blocks.add(expiresSoon); } // Parse debarred status String debarredStatus = (String) kohaUser.get("debarred"); if (debarredStatus != null && !debarredStatus.isEmpty()) { String debarredComment = (String) kohaUser.get("debarredcomment"); BlockOrTrap debarred = KohaUtil.createBlockOrTrap( "Debarred" + (debarredComment != null ? ": " + debarredComment : "")); blocks.add(debarred); } if (blocks.size() > 0) userOptionalFields.setBlockOrTraps(blocks); } if (initData.getUserFiscalAccountDesired()) { JSONArray accountLines = (JSONArray) kohaUser.get("accountLines"); if (accountLines != null && accountLines.size() != 0) { List<UserFiscalAccount> userFiscalAccounts = new ArrayList<UserFiscalAccount>(1); UserFiscalAccount userFiscalAccount = new UserFiscalAccount(); List<AccountDetails> accountDetails = new ArrayList<AccountDetails>(); for (int i = 0; i < accountLines.size(); ++i) { JSONObject accountLine = (JSONObject) accountLines.get(i); accountDetails.add(KohaUtil.parseAccountDetails(accountLine)); } BigDecimal amount = null; // Sum all transactions .. for (AccountDetails details : accountDetails) { if (amount == null) amount = details.getFiscalTransactionInformation().getAmount().getMonetaryValue(); else amount = amount .add(details.getFiscalTransactionInformation().getAmount().getMonetaryValue()); } userFiscalAccount.setAccountBalance(KohaUtil.createAccountBalance(amount)); userFiscalAccount.setAccountDetails(accountDetails); userFiscalAccounts.add(userFiscalAccount); // Suppose user has // only one account // .. responseData.setUserFiscalAccounts(userFiscalAccounts); } } if (initData.getHistoryDesired() != null) { LoanedItemsHistory loanedItemsHistory = KohaUtil.parseLoanedItemsHistory(kohaUser, initData); responseData.setLoanedItemsHistory(loanedItemsHistory); } } else { JSONObject userInfo = (JSONObject) kohaUser.get("userInfo"); if (userInfo != null) { if (initData.getNameInformationDesired()) { String firstname = (String) userInfo.get("firstname"); String surname = (String) userInfo.get("surname"); String title = (String) userInfo.get("title"); String othernames = (String) userInfo.get("othernames"); StructuredPersonalUserName structuredPersonalUserName = new StructuredPersonalUserName(); structuredPersonalUserName.setGivenName(firstname); structuredPersonalUserName.setPrefix(title); structuredPersonalUserName.setSurname(surname); structuredPersonalUserName.setSuffix(othernames); PersonalNameInformation personalNameInformation = new PersonalNameInformation(); personalNameInformation.setStructuredPersonalUserName(structuredPersonalUserName); NameInformation nameInformation = new NameInformation(); nameInformation.setPersonalNameInformation(personalNameInformation); userOptionalFields.setNameInformation(nameInformation); } if (initData.getUserAddressInformationDesired()) userOptionalFields.setUserAddressInformations(KohaUtil.parseUserAddressInformations(userInfo)); if (initData.getUserPrivilegeDesired()) { String branchcode = (String) userInfo.get("branchcode"); String agencyUserPrivilegeType = (String) userInfo.get("categorycode"); if (branchcode != null && agencyUserPrivilegeType != null) { List<UserPrivilege> userPrivileges = new ArrayList<UserPrivilege>(); UserPrivilege userPrivilege = new UserPrivilege(); userPrivilege.setAgencyId(new AgencyId(branchcode)); userPrivilege.setAgencyUserPrivilegeType(new AgencyUserPrivilegeType( "http://www.niso.org/ncip/v1_0/imp1/schemes/agencyuserprivilegetype/agencyuserprivilegetype.scm", agencyUserPrivilegeType)); userPrivilege.setValidFromDate( KohaUtil.parseGregorianCalendarFromKohaDate((String) userInfo.get("dateenrolled"))); userPrivilege.setValidToDate( KohaUtil.parseGregorianCalendarFromKohaDate((String) userInfo.get("dateexpiry"))); userPrivileges.add(userPrivilege); userOptionalFields.setUserPrivileges(userPrivileges); } } if (initData.getBlockOrTrapDesired()) { List<BlockOrTrap> blockOrTraps = KohaUtil.parseBlockOrTraps((JSONArray) userInfo.get("blocks")); userOptionalFields.setBlockOrTraps(blockOrTraps); } if (initData.getDateOfBirthDesired()) { String dateOfBirth = (String) userInfo.get("dateofbirth"); userOptionalFields.setDateOfBirth(KohaUtil.parseGregorianCalendarFromKohaDate(dateOfBirth)); } } JSONArray requestedItemsParsed = (JSONArray) kohaUser.get("requestedItems"); if (requestedItemsParsed != null && requestedItemsParsed.size() != 0) { List<RequestedItem> requestedItems = new ArrayList<RequestedItem>(); for (int i = 0; i < requestedItemsParsed.size(); ++i) { JSONObject requestedItemParsed = (JSONObject) requestedItemsParsed.get(i); RequestedItem requestedItem = KohaUtil.parseRequestedItem(requestedItemParsed); if (requestedItem != null) requestedItems.add(requestedItem); } responseData.setRequestedItems(requestedItems); } JSONArray loanedItemsParsed = (JSONArray) kohaUser.get("loanedItems"); if (loanedItemsParsed != null && loanedItemsParsed.size() != 0) { List<LoanedItem> loanedItems = new ArrayList<LoanedItem>(); for (int i = 0; i < loanedItemsParsed.size(); ++i) { JSONObject loanedItem = (JSONObject) loanedItemsParsed.get(i); loanedItems.add(KohaUtil.parseLoanedItem(loanedItem)); } responseData.setLoanedItems(loanedItems); } JSONArray userFiscalAccountParsed = (JSONArray) kohaUser.get("userFiscalAccount"); if (userFiscalAccountParsed != null && userFiscalAccountParsed.size() != 0) { List<UserFiscalAccount> userFiscalAccounts = new ArrayList<UserFiscalAccount>(); UserFiscalAccount userFiscalAccount = new UserFiscalAccount(); List<AccountDetails> accountDetails = new ArrayList<AccountDetails>(); for (int i = 0; i < userFiscalAccountParsed.size(); ++i) { JSONObject accountDetail = (JSONObject) userFiscalAccountParsed.get(i); accountDetails.add(KohaUtil.parseAccountDetails(accountDetail)); } BigDecimal amount = null; // Sum all transactions .. for (AccountDetails details : accountDetails) { if (amount == null) amount = details.getFiscalTransactionInformation().getAmount().getMonetaryValue(); else amount.add(details.getFiscalTransactionInformation().getAmount().getMonetaryValue()); } userFiscalAccount.setAccountBalance(KohaUtil.createAccountBalance(amount)); userFiscalAccount.setAccountDetails(accountDetails); userFiscalAccounts.add(userFiscalAccount); // Suppose user has // only one account // .. responseData.setUserFiscalAccounts(userFiscalAccounts); } } responseData.setUserOptionalFields(userOptionalFields); }