List of usage examples for org.joda.time Duration withDurationAdded
public Duration withDurationAdded(ReadableDuration durationToAdd, int scalar)
From source file:com.myMinistry.util.TimeUtils.java
License:Open Source License
public static String getTimeLength(Cursor cursor, String h, String m, boolean showMinutes) { SimpleDateFormat saveDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()); Calendar start = Calendar.getInstance(Locale.getDefault()); Calendar end = Calendar.getInstance(Locale.getDefault()); Duration dur = new Duration(null, null); Duration durchange = new Duration(null, null); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { try {/* w ww . ja v a 2 s. c om*/ start.setTime( saveDateFormat.parse(cursor.getString(cursor.getColumnIndex(UnionsNameAsRef.DATE_START)))); } catch (Exception e) { start = Calendar.getInstance(Locale.getDefault()); } try { end.setTime( saveDateFormat.parse(cursor.getString(cursor.getColumnIndex(UnionsNameAsRef.DATE_END)))); } catch (Exception e) { end = Calendar.getInstance(Locale.getDefault()); } durchange = new Duration(new DateTime(start), new DateTime(end)); dur = dur.withDurationAdded(durchange, 1); } cursor.close(); PeriodFormatter retVal; if (showMinutes) { retVal = new PeriodFormatterBuilder().printZeroRarelyFirst().appendHours().appendSuffix(h) .appendSeparator(" ").appendMinutes().appendSuffix(m).toFormatter(); } else { retVal = new PeriodFormatterBuilder().printZeroAlways().appendHours().appendSuffix(h).toFormatter(); } return retVal.print(dur.toPeriod()); }
From source file:org.cook_e.data.Recipe.java
License:Open Source License
/** * Returns the total estimated time of all the recipe's mSteps */// w w w . ja v a2s.co m @NonNull public Duration getTotalTime() { Duration time = Duration.ZERO; for (Step s : mSteps) { time = time.withDurationAdded(s.getTime(), 1); } return time; }