List of usage examples for org.joda.time DateTime plusDays
public DateTime plusDays(int days)
From source file:cron.DayOfWeekField.java
License:Open Source License
public boolean matches(DateTime time) { if (unspecified) return true; final int dayOfWeek = time.getDayOfWeek(); int number = number(dayOfWeek); if (hasLast) { return last.contains(number) && time.getMonthOfYear() != time.plusWeeks(1).getMonthOfYear(); } else if (hasNth) { for (int possibleMatch : nth.get(number)) { DateTime midnight = time.withTimeAtStartOfDay(); DateTime first = midnight.withDayOfMonth(1).withDayOfWeek(dayOfWeek); if (first.getMonthOfYear() != time.getMonthOfYear()) first = first.plusWeeks(1); DateTime tomorrow = midnight.plusDays(1); int weekNumber = 1 + (int) ((tomorrow.getMillis() - first.getMillis()) / MILLISECONDS_PER_WEEK); if (possibleMatch == weekNumber) return true; }// ww w . ja v a2 s .c o m } return contains(number); }
From source file:cz.krtinec.birthday.Utils.java
License:Open Source License
public static long calculateNotifTime(Long nowMillis, int hourToNotify) { DateTime now = new DateTime(nowMillis); DateTime timeToNotify = new DateTime(nowMillis); timeToNotify = timeToNotify.withHourOfDay(hourToNotify); if (timeToNotify.isBefore(now)) { timeToNotify = timeToNotify.plusDays(1); }/*from w ww. jav a2s . c om*/ return timeToNotify.getMillis(); }
From source file:de.azapps.mirakel.helper.DateTimeHelper.java
License:Open Source License
private static CharSequence getRelativeDate(final Context ctx, final DateTime date, final boolean reminder) { final DateTime now = new LocalDate().toDateTimeAtStartOfDay(); if ((Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) || !(now.isBefore(date) && now.plusDays(1).isAfter(date)) || reminder) { return DateUtils.getRelativeTimeSpanString(date.getMillis(), new Date().getTime(), reminder ? DateUtils.MINUTE_IN_MILLIS : DateUtils.DAY_IN_MILLIS); }//from w w w. jav a 2 s .co m return ctx.getString(R.string.today); }
From source file:de.azapps.mirakel.model.list.meta.SpecialListsDueProperty.java
License:Open Source License
@NonNull @Override/* w w w .ja va 2 s .com*/ public MirakelQueryBuilder getWhereQueryBuilder(@NonNull final Context ctx) { MirakelQueryBuilder qb = new MirakelQueryBuilder(ctx).and(Task.DUE, MirakelQueryBuilder.Operation.NOT_EQ, (String) null); DateTime date = new LocalDate().toDateTimeAtStartOfDay().plusDays(1).minusSeconds(10); Log.w(TAG, String.valueOf(date.getMillis())); switch (unit) { case DAY: date = date.plusDays(length); break; case MONTH: date = date.plusMonths(length); break; case YEAR: date = date.plusYears(length); break; } qb = qb.and(Task.DUE, isSet ? Operation.GT : Operation.LT, date.getMillis()); Log.w(TAG, qb.toString(Task.URI)); return qb; }
From source file:de.azapps.mirakel.model.recurring.Recurring.java
License:Open Source License
@NonNull private Optional<DateTime> addRecurring(@NonNull final Optional<DateTime> cal, final boolean onlyOnce) { if (!cal.isPresent()) { return absent(); }// w w w . j a v a2 s.c o m DateTime c = cal.get(); final DateTime now = new DateTime(); if (isExact()) { c = now; } now.withSecondOfMinute(0); now.withMinuteOfHour(0); final List<Integer> weekdays = getWeekdays(); if (weekdays.isEmpty()) { if ((!getStartDate().isPresent() || now.isAfter(getStartDate().get())) && (!getEndDate().isPresent() || now.isBefore(getEndDate().get()))) { do { c = c.plus(recurringInterval); } while (c.isBefore(now) && !onlyOnce); } } else { int diff = 8; if (c.isBefore(now)) { c = now; } c = c.plusDays(1); for (final Integer day : weekdays) { int local_diff = day - c.getDayOfWeek(); if (local_diff < 0) { local_diff += 7; } if (diff > local_diff) { diff = local_diff; } } c = c.plusDays(diff); } return of(c); }
From source file:de.azapps.mirakel.model.semantic.Semantic.java
License:Open Source License
public void apply(@NonNull final Task task) { if (getPriority().isPresent()) { task.setPriority(getPriority().get()); }// w w w .jav a 2s. c om if (getDue().isPresent()) { final DateTime due = getNormalizedCalendar(); due.plusDays(getDue().get()); task.setDue(of(due)); } if (getList().isPresent()) { task.setList(getList().get()); } if (getWeekday().isPresent()) { final DateTime due = getNormalizedCalendar(); int nextWeekday = getWeekday().get() + 1; // Because there are some dudes which means, sunday is the // first day of the week That's obviously wrong! final Calendar cal = due.toGregorianCalendar(); if (nextWeekday == 8) { nextWeekday = 1; } do { cal.add(Calendar.DAY_OF_YEAR, 1); } while (cal.get(Calendar.DAY_OF_WEEK) != nextWeekday); task.setDue(of(new DateTime(cal))); } }
From source file:de.brands4friends.daleq.examples.JdbcOrderDao.java
License:Apache License
@Override public List<Order> findExpensiveOrders(final long customerId, final LocalDate boughtAt, final BigDecimal minimumAmount) { final DateTime dateLower = boughtAt.toDateMidnight().toDateTime(); final DateTime dateUpper = dateLower.plusDays(1); return getJdbcTemplate().query("select o.* from CUSTOMER_ORDER o " + "LEFT JOIN (" + " SELECT o.ID as ORDER_ID,SUM(PRICE) as TOTAL" + " FROM CUSTOMER_ORDER o " + " LEFT JOIN CUSTOMER_ORDER_ITEM oi ON o.ID = oi.ORDER_ID " + " LEFT JOIN PRODUCT p ON oi.PRODUCT_ID = p.ID " + " GROUP BY o.ID" + ") prices ON o.ID = prices.ORDER_ID " + "WHERE o.CUSTOMER_ID = ? " + " AND o.CREATION >= ? " + " AND o.CREATION < ? " + " AND prices.TOTAL >= ? ", ROW_MAPPER, customerId, dateLower.toDate(), dateUpper.toDate(), minimumAmount); }
From source file:de.dbaelz.onofftracker.activities.chart.ChartActivity.java
License:Apache License
private BarData loadData(DateTime startDate, DateTime endDate) { ArrayList<IBarDataSet> sets = new ArrayList<>(); ArrayList<String> days = new ArrayList<>(); ArrayList<BarEntry> entriesScreenOn = new ArrayList<>(); ArrayList<BarEntry> entriesScreenOff = new ArrayList<>(); ArrayList<BarEntry> entriesScreenUnlocked = new ArrayList<>(); DateTime inter = startDate; int index = 0; while (inter.compareTo(endDate) < 0) { days.add(fmt.print(inter));//from w w w . j av a 2s . co m entriesScreenOn .add(new BarEntry(actionHelper.countActionsForDate(inter, Action.ActionType.SCREENON), index)); entriesScreenOff .add(new BarEntry(actionHelper.countActionsForDate(inter, Action.ActionType.SCREENOFF), index)); entriesScreenUnlocked .add(new BarEntry(actionHelper.countActionsForDate(inter, Action.ActionType.UNLOCKED), index)); inter = inter.plusDays(1); index++; } BarDataSet screenOn = new BarDataSet(entriesScreenOn, getString(R.string.chart_action_on)); screenOn.setColor(ContextCompat.getColor(this, R.color.primary)); BarDataSet screenOff = new BarDataSet(entriesScreenOff, getString(R.string.chart_action_off)); screenOff.setColor(ContextCompat.getColor(this, R.color.primary_light)); BarDataSet unlocked = new BarDataSet(entriesScreenUnlocked, getString(R.string.chart_action_unlocked)); unlocked.setColor(ContextCompat.getColor(this, R.color.primary_text)); sets.add(screenOn); sets.add(screenOff); sets.add(unlocked); BarData barData = new BarData(days, sets); barData.setValueFormatter(new LargeValueFormatter()); return barData; }
From source file:de.maklerpoint.office.Gui.Schaden.SchaedenDialog.java
License:Open Source License
private void setUp() { loadCombos();/*from www . jav a2 s . c o m*/ this.ffield_schadenhoehe.setValue(0.00); DateTime dt = new DateTime(); dt.plusDays(14); this.date_wiedervorlage.setDate(dt.toDate()); this.date_schadenTime.setDate(new Date()); this.date_vuWeiterleitungTime.setDate(new Date()); this.date_vuStatusDatum.setDate(new Date()); this.spinnerSchadenNr.setEnabled(true); this.combo_kunde.setEnabled(true); this.combo_vertrag.setEnabled(true); if (this.schaden == null) { this.setTitle("Neuer Schadensfall"); } else { this.setTitle("Schadensfall " + schaden.getSchadenNr() + " (" + KundenRegistry.getKunde(schaden.getKundenNr()).toString() + ")"); } loadSchaden(); }
From source file:de.raion.xmppbot.schedule.ScheduledCommandExecutor.java
License:Apache License
/** * calculates the initial delay out of the given parameters * * @param currentTimeInMillis time in ms to use for the calculation * @param time LocalTime representing Hour and Minute only * @return the initial delay calculated in ms *//*from w w w.java 2s. c o m*/ protected Long calculateInitialDelay(Long currentTimeInMillis, LocalTime time) { DateTime currentTime = new DateTime(currentTimeInMillis); Long initialDelay = 0L; int currentHour = currentTime.getHourOfDay(); DateTime initialTime = new DateTime(currentTimeInMillis).withHourOfDay(time.getHourOfDay()) .withMinuteOfHour(time.getMinuteOfHour()).withSecondOfMinute(0); // next day if (currentHour > time.getHourOfDay()) { initialTime = initialTime.plusDays(1); } initialDelay = initialTime.getMillis() - currentTime.getMillis(); return initialDelay; }