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.ideaspymes.arthyweb.ventas.web.controllers.ResumenMetasBean.java
public Integer getDaysBetweenIgnoreWeekends(org.joda.time.LocalDate startDate, org.joda.time.LocalDate endDate) { // If the start date is equal to the closing date, spent 0 days if (startDate.equals(endDate)) { return 0; }/*from w ww. j a va 2s .c om*/ // A number that represents the day for the start date, Monday = 1 , Tuesday = 2 , Wednesday = 3 ... int dayOfWeekStartDateNumber = startDate.getDayOfWeek(); // If the starting date is Saturday or Sunday , pretend to be Monday if (dayOfWeekStartDateNumber == 6 || dayOfWeekStartDateNumber == 7) { int DaysToAdd = 8 - dayOfWeekStartDateNumber; startDate = startDate.plusDays(DaysToAdd); dayOfWeekStartDateNumber = Integer.valueOf(startDate.dayOfWeek().getAsString()); } // How many days have passed counting weekends int days = Days.daysBetween(startDate, endDate).getDays(); // How many weeks have passed int weeks = days / 7; // Excess days left. E.g. one week and three days the excess will be 3 int excess = days % 7; // Excess of days spent for the weekend , then it must be removed two days // the final number of days if (excess + dayOfWeekStartDateNumber >= 6) { // Week count * 5 working days + excess days - the weekend that excess crossed return weeks * 5 + excess - 2; } // Weeks count * 5 working days + excess days return weeks * 5 + excess; }
From source file:com.ikon.servlet.ValidateLicenseServlet.java
private int remainingDays() { DateTimeFormatter formatter = DateTimeFormat.forPattern("d MMM yyyy"); DateTime expiryDate = null;/*from www .j a va 2 s .com*/ try { expiryDate = formatter.parseDateTime(FileUtils.readFileToString(LICENSE_PATH)); } catch (IOException e) { e.printStackTrace(); } return Days.daysBetween(new DateTime(), expiryDate).getDays(); }
From source file:com.inkubator.common.util.DateTimeUtil.java
/** * get total days difference, between two date type * * @return Integer//from w w w . jav a2 s. c o m * @param date1 Date reference * @param date2 Date reference */ public static Integer getTotalDayDifference(Date date1, Date date2) { Days days = Days.daysBetween(new DateMidnight(date1), new DateMidnight(date2)); return days.getDays(); }
From source file:com.its.web.services.DatesService.java
public int getRemainingDays(License license) { Date now = new Date(); Calendar c = Calendar.getInstance(); c.setTime(license.getStartDate());/*from www . j a v a 2 s .co m*/ c.add(Calendar.DATE, license.getTrialPeriod()); Date endTrialDate = c.getTime(); int remainingDays = Days.daysBetween(new DateTime(now), new DateTime(endTrialDate)).getDays(); return remainingDays; }
From source file:com.iucosoft.eavertizare.gui.MainJFrame.java
public void autoRun() { System.out.println("Spring 4 + Quartz 2.2.1 ~"); // SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy"); // Runnable myRunnable = new Runnable() { ///* w w w .j a v a 2s . c o m*/ // @Override // public void run() { DateTime start = new DateTime(); List<Firma> listFirma = firmaDao.findAll(); List<Client> listClients; //*******************Sincronizare************ sincronizare(); //***************** for (Firma firmalocal : listFirma) { listClients = clientsDao.findAllClientsForFirmaLocal(firmalocal); for (Client client : listClients) { // System.out.println("" + sdf.format(client.getDateExpirare())); DateTime end = new DateTime(client.getDateExpirare()); Days days = Days.daysBetween(start, end); if (days.getDays() == -2) { // System.out.println("" + sdf.format(client.getDateExpirare())); System.out.println(" " + client.getDateExpirare()); SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy"); String mesajClient = client.getFirma().getMesajPentruClienti() .replaceFirst("nume", client.getNume()).replaceFirst("prenume", client.getPrenume()) .replaceFirst("data", sdf.format(client.getDateExpirare()).toString()) .replaceFirst("compania", client.getFirma().getNumeFirma()); try { // client.setTrimis(true); smsSender.sendSms(client.getNrTelefon(), mesajClient); mailSender.sendMail(client.getEmail(), "E-avetizare", mesajClient); } catch (Exception ex) { Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex); JOptionPane.showMessageDialog(this, "Verificai conexiunea la internet!\n" + ex, "Error", JOptionPane.ERROR_MESSAGE); } // try { // // this.wait(); // Thread.sleep(5000); // } catch (InterruptedException ex) { // Logger.getLogger(MainJFrame.class.getName()).log(Level.SEVERE, null, ex); // } } // clientsDao.update(client.getFirma(), client); } } this.refreshFrame(); // } // }; // // Thread thread = new Thread(myRunnable); // thread.start(); }
From source file:com.iukonline.amule.android.amuleremote.partfile.PartFileDetailsFragment.java
License:Open Source License
private void refreshView() { View v = getView();//from w ww.j a va 2 s .co m if (mPartFile != null) { mFileNameText.setText(mPartFile.getFileName()); String textCat = getResources().getString(R.string.partfile_details_cat_unknown); int backgroundColorCat = 0; int textColorCat = getResources().getColor(R.color.secondary_text); long cat = mPartFile.getCat(); if (cat == 0) { textCat = getResources().getString(R.string.partfile_details_cat_nocat); } else { ECCategory[] catList = mApp.mECHelper.getCategories(); if (catList != null) { for (int i = 0; i < catList.length; i++) { if (catList[i].getId() == cat) { textCat = catList[i].getTitle(); backgroundColorCat = 0xff000000 | (int) catList[i].getColor(); textColorCat = 0xff000000 | GUIUtils.chooseFontColor((int) catList[i].getColor()); break; } } } } mCategoryText.setText(textCat); ((GradientDrawable) mCategoryText.getBackground()).setColor(backgroundColorCat); mCategoryText.setTextColor(textColorCat); mLinkText.setText(mPartFile.getEd2kLink()); mDoneText.setText(GUIUtils.longToBytesFormatted(mPartFile.getSizeDone())); mSizeText.setText(GUIUtils.longToBytesFormatted(mPartFile.getSizeFull())); mRemainingText.setText(GUIUtils.getETA(getActivity(), mPartFile.getSizeFull() - mPartFile.getSizeDone(), mPartFile.getSpeed())); Date lastSeenComplateDate = mPartFile.getLastSeenComp(); DateTime lastSeenComplateDateTime = new DateTime(lastSeenComplateDate); DateTime now = new DateTime(); if (lastSeenComplateDate == null || lastSeenComplateDate.getTime() == 0L) { mLastSeenText.setText(getResources().getString(R.string.partfile_last_seen_never)); } else { long lastSeenSeconds = (System.currentTimeMillis() - mPartFile.getLastSeenComp().getTime()) / 1000L; if (lastSeenSeconds <= 60L) { mLastSeenText.setText(getResources().getString(R.string.partfile_last_seen_now)); } else if (lastSeenSeconds <= 3600L) { mLastSeenText.setText(getResources().getQuantityString(R.plurals.partfile_last_seen_mins, (int) (lastSeenSeconds / 60L), lastSeenSeconds / 60L)); } else if (lastSeenSeconds <= 86400L) { int lastSeenHours = (int) (lastSeenSeconds / 3600); if (lastSeenHours < 12 || lastSeenComplateDateTime.getDayOfMonth() == now.getDayOfMonth()) { mLastSeenText.setText(getResources().getQuantityString(R.plurals.partfile_last_seen_hours, lastSeenHours, lastSeenHours)); } else { mLastSeenText.setText(getResources().getString(R.string.partfile_last_seen_yesterday)); } } else { int diffDays = Days.daysBetween(lastSeenComplateDateTime, now).getDays(); if (diffDays <= 31) { mLastSeenText.setText(getResources().getQuantityString(R.plurals.partfile_last_seen_days, diffDays, diffDays)); } else if (diffDays <= 180) { int diffMonths = Months.monthsBetween(lastSeenComplateDateTime, now).getMonths(); mLastSeenText.setText(getResources().getQuantityString(R.plurals.partfile_last_seen_months, diffMonths, diffMonths)); } else { mLastSeenText.setText(getResources().getString(R.string.partfile_last_seen_date, lastSeenComplateDateTime.toString(DateTimeFormat.forStyle("L-") .withLocale(getResources().getConfiguration().locale)))); } } } mSourcesAvailableText .setText(Integer.toString(mPartFile.getSourceCount() - mPartFile.getSourceNotCurrent())); mSourcesActiveText.setText(Integer.toString(mPartFile.getSourceXfer())); mSourcesA4AFText.setText(Integer.toString(mPartFile.getSourceA4AF())); mSourcesNotCurrentText.setText(Integer.toString(mPartFile.getSourceNotCurrent())); switch (mPartFile.getPrio()) { case ECPartFile.PR_LOW: mPriorityText.setText(R.string.partfile_prio_low); break; case ECPartFile.PR_NORMAL: mPriorityText.setText(R.string.partfile_prio_normal); break; case ECPartFile.PR_HIGH: mPriorityText.setText(R.string.partfile_prio_high); break; case ECPartFile.PR_AUTO_LOW: mPriorityText.setText(R.string.partfile_prio_auto_low); break; case ECPartFile.PR_AUTO_NORMAL: mPriorityText.setText(R.string.partfile_prio_auto_normal); break; case ECPartFile.PR_AUTO_HIGH: mPriorityText.setText(R.string.partfile_prio_auto_high); break; default: mPriorityText.setText(R.string.partfile_prio_unknown); break; } int statusColor = R.color.progressWaitingMid; switch (mPartFile.getStatus()) { case ECPartFile.PS_ALLOCATING: mStatusText.setText(R.string.partfile_status_allocating); break; case ECPartFile.PS_COMPLETE: mStatusText.setText(R.string.partfile_status_complete); statusColor = R.color.progressRunningMid; break; case ECPartFile.PS_COMPLETING: mStatusText.setText(R.string.partfile_status_completing); statusColor = R.color.progressRunningMid; break; case ECPartFile.PS_EMPTY: mStatusText.setText(R.string.partfile_status_empty); statusColor = R.color.progressBlockedMid; break; case ECPartFile.PS_ERROR: mStatusText.setText(R.string.partfile_status_error); statusColor = R.color.progressBlockedMid; break; case ECPartFile.PS_WAITINGFORHASH: case ECPartFile.PS_HASHING: mStatusText.setText(R.string.partfile_status_hashing); break; case ECPartFile.PS_INSUFFICIENT: mStatusText.setText(R.string.partfile_status_insuffcient); statusColor = R.color.progressBlockedMid; break; case ECPartFile.PS_PAUSED: mStatusText.setText(R.string.partfile_status_paused); break; case ECPartFile.PS_READY: if (mPartFile.getSourceXfer() > 0) { mStatusText.setText(R.string.partfile_status_downloading); mStatusText.append(" " + GUIUtils.longToBytesFormatted(mPartFile.getSpeed()) + "/s"); statusColor = R.color.progressRunningMid; } else { mStatusText.setText(R.string.partfile_status_waiting); statusColor = R.color.progressWaitingMid; } break; case ECPartFile.PS_UNKNOWN: mStatusText.setText(R.string.partfile_status_unknown); statusColor = R.color.progressStoppedMid; break; default: mStatusText.setText("UNKNOWN-" + mPartFile.getStatus()); break; } mStatusText.setTextColor(getResources().getColor(statusColor)); } }
From source file:com.jay.pea.mhealthapp2.model.MedicationManager.java
License:Open Source License
/** * Method to build the first dose map which holds the dose due time and the dose taken time. * If not taken the dose taken time is recorded as epoch 01-01-70. * * @param med// w w w . j ava 2 s . c o m * @param context * @return */ public HashMap<DateTime, DateTime> buildDoseMap1(Medication med, Context context) { //get a db object dbOpenHelper = new MedDBOpenHelper(context); //get final med final Medication medication = med; //hash map to map doses to taken bool HashMap<DateTime, DateTime> doseMap1 = new HashMap(); //get existing hashMap details if exist doseMap1 = dbOpenHelper.getDoseMaps(medication)[0]; //erase all future dose data, retain past data //get inclusive start and end date DateTime startDate = new DateTime(med.getMedStart() * 1000l); DateTime endDate = new DateTime(med.getMedEnd() * 1000l); //set hashStart date as today DateTime hashStart = today; //if medication is in future set hashStart to future date, if med start is in the past, set hashStart to today (for update to HashMap) if (hashStart.isBefore(startDate)) hashStart = startDate; //get alarm times DateTime alert1 = new DateTime(med.getAlert1() * 1000l); DateTime alert2 = new DateTime(med.getAlert2() * 1000l); DateTime alert3 = new DateTime(med.getAlert3() * 1000l); DateTime alert4 = new DateTime(med.getAlert4() * 1000l); DateTime alert5 = new DateTime(med.getAlert5() * 1000l); DateTime alert6 = new DateTime(med.getAlert6() * 1000l); DateTime[] dtArray = new DateTime[] { alert1, alert2, alert3, alert4, alert5, alert6 }; //get the number of days of med prescription int days = Days.daysBetween(hashStart.toLocalDate(), endDate.toLocalDate()).getDays() + 1; //get Frequency for alerts to ignore non required alerts. int freq = med.getFreq(); //build the hashmap for daily dose due dates and bool for taken, if in the past exclude the reminder for (int i = 0; i < days; i++) { DateTime thisDay = hashStart.plusDays(i); //for the freq setup all alerts for (int j = 0; j < freq; j++) { DateTime alertTime = thisDay.withHourOfDay(dtArray[j].getHourOfDay()) .withMinuteOfHour(dtArray[j].getMinuteOfHour()).withSecondOfMinute(0); final DateTime zeroDate = new DateTime(0); doseMap1.put(alertTime, zeroDate); Log.d(TAG, alertTime + " Time" + dtArray[j].getHourOfDay() + " zero date " + zeroDate); } } //get existing hashMap details if exist HashMap<DateTime, DateTime> tempDoseMap1 = dbOpenHelper.getDoseMaps(medication)[0]; //add all past dose data, if (!tempDoseMap1.isEmpty()) { for (DateTime dateTime : tempDoseMap1.keySet()) { if (dateTime.isBefore(today)) { doseMap1.put(dateTime, tempDoseMap1.get(dateTime)); } } } Log.d(TAG, doseMap1.size() + " doseMap1 size"); return doseMap1; }
From source file:com.jay.pea.mhealthapp2.model.MedicationManager.java
License:Open Source License
/** * Method to build the second dose map which holds the dose due time and an int for if an alert * has been set.// w w w .j a v a 2s. c om * * @param med * @param context * @return */ public HashMap<DateTime, Integer> buildDoseMap2(Medication med, Context context) { //get a db object dbOpenHelper = new MedDBOpenHelper(context); //get final med final Medication medication = med; //hash map to map doses to taken bool HashMap<DateTime, Integer> doseMap2 = new HashMap(); //set hashStart date as today DateTime hashStart = today; //get inclusive start and end date DateTime startDate = new DateTime(med.getMedStart() * 1000l); DateTime endDate = new DateTime(med.getMedEnd() * 1000l); //if medication is in future set hashStart to future date, if med start is in the past, set hashStart to today (for update to HashMap) if (hashStart.isBefore(startDate)) hashStart = startDate; //get alarm times DateTime alert1 = new DateTime(med.getAlert1() * 1000l); DateTime alert2 = new DateTime(med.getAlert2() * 1000l); DateTime alert3 = new DateTime(med.getAlert3() * 1000l); DateTime alert4 = new DateTime(med.getAlert4() * 1000l); DateTime alert5 = new DateTime(med.getAlert5() * 1000l); DateTime alert6 = new DateTime(med.getAlert6() * 1000l); DateTime[] dtArray = new DateTime[] { alert1, alert2, alert3, alert4, alert5, alert6 }; Log.d(TAG, Arrays.toString(dtArray)); //get the number of days of med prescription int days = Days.daysBetween(hashStart.toLocalDate(), endDate.toLocalDate()).getDays() + 1; //get Frequency for alerts to ignore non required alerts. int freq = med.getFreq(); Log.d(TAG, freq + " Days =" + days + " " + med.getMedName()); //build the hashmap for daily dose due dates and alertsOn Integer, if in the past exclude the reminder for (int i = 0; i < days; i++) { DateTime thisDay = hashStart.plusDays(i); //for the freq setup all alertsOn for (int j = 0; j < freq; j++) { DateTime alertTime = thisDay.withHourOfDay(dtArray[j].getHourOfDay()) .withMinuteOfHour(dtArray[j].getMinuteOfHour()).withSecondOfMinute(0); if (alertTime.isAfter(today)) doseMap2.put(alertTime, medication.getAlertsOn()); } Log.d(TAG, doseMap2.size() + " doseMap2 size"); } //get existing hashMap details if exist HashMap<DateTime, Integer> tempDoseMap2 = dbOpenHelper.getDoseMaps(medication)[1]; //add all past dose data, if (!tempDoseMap2.isEmpty()) { for (DateTime dateTime : tempDoseMap2.keySet()) { if (dateTime.isBefore(today)) { doseMap2.put(dateTime, tempDoseMap2.get(dateTime)); } } } Log.d(TAG, doseMap2.size() + " doseMap2 size"); return doseMap2; }
From source file:com.jay.pea.mhealthapp2.presenter.CustomCardViewMedFuture.java
License:Open Source License
/** * method to setup each card and its views * * @param fd/*w ww.j av a2 s .co m*/ */ public void setCard(FutureDoses fd) { int noDays = Days.daysBetween(fd.getStartDate().toLocalDate(), fd.getEndDate().toLocalDate()).getDays() + 1; int doseNo = noDays * fd.getFreq(); medicationName.setText(fd.getMedName()); doseNeededTV.setText("Over " + noDays + " days, you require " + doseNo + " Doses (" + fd.getDose() + ") of " + fd.getMedName()); }
From source file:com.jay.pea.mhealthapp2.presenter.FutureMeds.java
License:Open Source License
/** * method to update the listview when the data changes *//* www . j ava 2 s .co m*/ private void updateListView() { dbHelper = new MedDBOpenHelper(this); medList = dbHelper.getAllMeds(); fdal = new ArrayList<>(); DateTime startDate = dtfDate.parseDateTime(startTV.getText().toString()); DateTime endDate = dtfDate.parseDateTime(endTV.getText().toString()); int diffDays = Days.daysBetween(startDate.toLocalDate(), endDate.toLocalDate()).getDays(); if (diffDays < 0) { Snackbar.make(cl, "Please ensure the end date is after the start date", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } else { for (Medication med : medList) { FutureDoses fd = new FutureDoses(med.getDose(), endDate, med.getFreq(), med.getMedName(), startDate); fdal.add(fd); } listViewAdaptorMedFut = new CustomCardViewAdaptorMedFuture(this, fdal); listView.setAdapter(listViewAdaptorMedFut); } }