Java Code Examples for org.threeten.bp.LocalDate#plusDays()

The following examples show how to use org.threeten.bp.LocalDate#plusDays() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicActivityDecorated.java    From material-calendarview with MIT License 6 votes vote down vote up
@Override
protected List<CalendarDay> doInBackground(@NonNull Void... voids) {
  try {
    Thread.sleep(2000);
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
  LocalDate temp = LocalDate.now().minusMonths(2);
  final ArrayList<CalendarDay> dates = new ArrayList<>();
  for (int i = 0; i < 30; i++) {
    final CalendarDay day = CalendarDay.from(temp);
    dates.add(day);
    temp = temp.plusDays(5);
  }

  return dates;
}
 
Example 2
Source File: CalendarPagerAdapter.java    From material-calendarview with MIT License 6 votes vote down vote up
/**
 * Clear the previous selection, select the range of days from first to last, and finally
 * invalidate. First day should be before last day, otherwise the selection won't happen.
 *
 * @param first The first day of the range.
 * @param last The last day in the range.
 * @see CalendarPagerAdapter#setDateSelected(CalendarDay, boolean)
 */
public void selectRange(final CalendarDay first, final CalendarDay last) {
  selectedDates.clear();

  // Copy to start from the first day and increment
  LocalDate temp = LocalDate.of(first.getYear(), first.getMonth(), first.getDay());

  // for comparison
  final LocalDate end = last.getDate();

  while( temp.isBefore(end) || temp.equals(end) ) {
    selectedDates.add(CalendarDay.from(temp));
    temp = temp.plusDays(1);
  }

  invalidateSelectedDates();
}
 
Example 3
Source File: IsoFields.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
    if (isSupportedBy(temporal) == false) {
        throw new UnsupportedTemporalTypeException("Unsupported field: WeekBasedYear");
    }
    int newWby = range().checkValidIntValue(newValue, WEEK_BASED_YEAR);  // strict check
    LocalDate date = LocalDate.from(temporal);
    int dow = date.get(DAY_OF_WEEK);
    int week = getWeek(date);
    if (week == 53 && getWeekRange(newWby) == 52) {
        week = 52;
    }
    LocalDate resolved = LocalDate.of(newWby, 1, 4);  // 4th is guaranteed to be in week one
    int days = (dow - resolved.get(DAY_OF_WEEK)) + ((week - 1) * 7);
    resolved = resolved.plusDays(days);
    return (R) temporal.with(resolved);
}
 
Example 4
Source File: CalendarPagerView.java    From material-calendarview with MIT License 5 votes vote down vote up
private void buildWeekDays(LocalDate calendar) {
  LocalDate local = calendar;
  for (int i = 0; i < DEFAULT_DAYS_IN_WEEK; i++) {
    WeekDayView weekDayView = new WeekDayView(getContext(), local.getDayOfWeek());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      weekDayView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    }
    weekDayViews.add(weekDayView);
    addView(weekDayView);
    local = local.plusDays(1);
  }
}
 
Example 5
Source File: CalendarPagerView.java    From material-calendarview with MIT License 5 votes vote down vote up
protected LocalDate resetAndGetWorkingCalendar() {
  final TemporalField firstDayOfWeek = WeekFields.of(this.firstDayOfWeek, 1).dayOfWeek();
  final LocalDate temp = getFirstViewDay().getDate().with(firstDayOfWeek, 1);
  int dow = temp.getDayOfWeek().getValue();
  int delta = getFirstDayOfWeek().getValue() - dow;
  //If the delta is positive, we want to remove a week
  boolean removeRow = showOtherMonths(showOtherDates) ? delta >= 0 : delta > 0;
  if (removeRow) {
    delta -= DEFAULT_DAYS_IN_WEEK;
  }
  return temp.plusDays(delta);
}
 
Example 6
Source File: MonthView.java    From material-calendarview with MIT License 5 votes vote down vote up
@Override protected void buildDayViews(
    final Collection<DayView> dayViews,
    final LocalDate calendar) {
  LocalDate temp = calendar;
  for (int r = 0; r < DEFAULT_MAX_WEEKS; r++) {
    for (int i = 0; i < DEFAULT_DAYS_IN_WEEK; i++) {
      addDayView(dayViews, temp);
      temp = temp.plusDays(1);
    }
  }
}
 
Example 7
Source File: WeekView.java    From material-calendarview with MIT License 5 votes vote down vote up
@Override protected void buildDayViews(
    final Collection<DayView> dayViews,
    final LocalDate calendar) {
  LocalDate temp = calendar;
  for (int i = 0; i < DEFAULT_DAYS_IN_WEEK; i++) {
    addDayView(dayViews, temp);
    temp = temp.plusDays(1);
  }
}
 
Example 8
Source File: TestYear.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_atDay_notLeapYear() {
    Year test = Year.of(2007);
    LocalDate expected = LocalDate.of(2007, 1, 1);
    for (int i = 1; i <= 365; i++) {
        assertEquals(test.atDay(i), expected);
        expected = expected.plusDays(1);
    }
}
 
Example 9
Source File: TestYear.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_atDay_leapYear() {
    Year test = Year.of(2008);
    LocalDate expected = LocalDate.of(2008, 1, 1);
    for (int i = 1; i <= 366; i++) {
        assertEquals(test.atDay(i), expected);
        expected = expected.plusDays(1);
    }
}
 
Example 10
Source File: TestIsoFields.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void test_loop() {
    // loop round at least one 400 year cycle, including before 1970
    LocalDate date = LocalDate.of(1960, 1, 5);  // Tuseday of week 1 1960
    int year = 1960;
    int wby = 1960;
    int weekLen = 52;
    int week = 1;
    while (date.getYear() < 2400) {
        DayOfWeek loopDow = date.getDayOfWeek();
        if (date.getYear() != year) {
            year = date.getYear();
        }
        if (loopDow == MONDAY) {
            week++;
            if ((week == 53 && weekLen == 52) || week == 54) {
                week = 1;
                LocalDate firstDayOfWeekBasedYear = date.plusDays(14).withDayOfYear(1);
                DayOfWeek firstDay = firstDayOfWeekBasedYear.getDayOfWeek();
                weekLen = (firstDay == THURSDAY || (firstDay == WEDNESDAY && firstDayOfWeekBasedYear.isLeapYear()) ? 53 : 52);
                wby++;
            }
        }
        assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.rangeRefinedBy(date), ValueRange.of(1, weekLen), "Failed on " + date + " " + date.getDayOfWeek());
        assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date), week, "Failed on " + date + " " + date.getDayOfWeek());
        assertEquals(date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR), week, "Failed on " + date + " " + date.getDayOfWeek());
        assertEquals(IsoFields.WEEK_BASED_YEAR.getFrom(date), wby, "Failed on " + date + " " + date.getDayOfWeek());
        assertEquals(date.get(IsoFields.WEEK_BASED_YEAR), wby, "Failed on " + date + " " + date.getDayOfWeek());
        date = date.plusDays(1);
    }
}
 
Example 11
Source File: WeekDatePicker.java    From WeekDatePicker with MIT License 4 votes vote down vote up
private void remakeLayout() {

        if (getWidth() > 0)  {

            LocalDate day = getRelativeFirstDay(-1);

            for (int i = 0; i < layouts.length; i++) {

                String dayText = String.valueOf(day.getDayOfMonth());
                if (layouts[i] == null) {
                    layouts[i] = BoringLayout.make(dayText, dayTextPaint, dayWidth,
                            Layout.Alignment.ALIGN_CENTER, 1f, 1f, dayMetrics, false, ellipsize,
                            dayWidth);
                } else {
                    layouts[i].replaceOrMake(dayText, dayTextPaint, dayWidth,
                            Layout.Alignment.ALIGN_CENTER, 1f, 1f, dayMetrics, false, ellipsize,
                            dayWidth);
                }

                day = day.plusDays(1);
            }

            DayOfWeek dayOfWeek = firstDayOfWeek; // first index is 1
            for (int i = 0; i < dayLabelLayouts.length; i++) {

                CharSequence name;
                if (labelNames == null) {
                    name = dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.getDefault());
                } else {
                    int index = dayOfWeek.getValue() - 1;
                    name = labelNames[index];
                }


                if (dayLabelLayouts[i] == null) {
                    dayLabelLayouts[i] = BoringLayout.make(name, dayLabelTextPain, dayWidth,
                            Layout.Alignment.ALIGN_CENTER, 1f, 1f, dayLabelMetrics, false, ellipsize,
                            dayWidth);
                } else {
                    dayLabelLayouts[i].replaceOrMake(name, dayLabelTextPain, dayWidth,
                            Layout.Alignment.ALIGN_CENTER, 1f, 1f, dayLabelMetrics, false, ellipsize,
                            dayWidth);
                }

                dayOfWeek = dayOfWeek.plus(1);

            }

        }

    }