@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_basic); ButterKnife.bind(this); // Add a decorator to disable prime numbered days widget.addDecorator(new PrimeDayDisableDecorator()); // Add a second decorator that explicitly enables days <= 10. This will work because // decorators are applied in order, and the system allows re-enabling widget.addDecorator(new EnableOneToTenDecorator()); final LocalDate calendar = LocalDate.now(); widget.setSelectedDate(calendar); final LocalDate min = LocalDate.of(calendar.getYear(), Month.JANUARY, 1); final LocalDate max = LocalDate.of(calendar.getYear() + 1, Month.OCTOBER, 31); widget.state().edit() .setMinimumDate(min) .setMaximumDate(max) .commit(); }
@Override public String toString() { return "CalendarDay{" + date.getYear() + "-" + date.getMonthValue() + "-" + date.getDayOfMonth() + "}"; }
/** * 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(); }
public StateBuilder() { calendarMode = CalendarMode.MONTHS; firstDayOfWeek = LocalDate.now().with(WeekFields.of(Locale.getDefault()).dayOfWeek(), 1).getDayOfWeek(); }
@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; }
/** * Obtains an instance of {@code LocalDate} from a text string such as {@code 2007-12-23}. * <p> * The string must represent a valid date and is parsed using * {@link org.threeten.bp.format.DateTimeFormatter#ISO_LOCAL_DATE}. * * @param text the text to parse such as "2007-12-23", not null * @return the parsed local date, not null * @throws DateTimeParseException if the text cannot be parsed */ public static LocalDate parse(CharSequence text) { return parse(text, DateTimeFormatter.ISO_LOCAL_DATE); }
@Override public void serialize(LocalDate date, JsonGenerator generator, SerializerProvider provider) throws IOException { if (useTimestamp(provider)) { generator.writeStartArray(); generator.writeNumber(date.getYear()); generator.writeNumber(date.getMonthValue()); generator.writeNumber(date.getDayOfMonth()); generator.writeEndArray(); } else { String str = (_formatter == null) ? date.toString() : date.format(_formatter); generator.writeString(str); } }
@Override public int lengthOfYear() { Calendar jcal = Calendar.getInstance(JapaneseChronology.LOCALE); jcal.set(Calendar.ERA, era.getValue() + JapaneseEra.ERA_OFFSET); jcal.set(yearOfEra, isoDate.getMonthValue() - 1, isoDate.getDayOfMonth()); return jcal.getActualMaximum(Calendar.DAY_OF_YEAR); }
void adjustToFowards(int year) { if (adjustForwards == false && dayOfMonth > 0) { LocalDate adjustedDate = LocalDate.of(year, month, dayOfMonth).minusDays(6); dayOfMonth = adjustedDate.getDayOfMonth(); month = adjustedDate.getMonth(); adjustForwards = true; } } }
@Override public Void visit(ScalarDate value, StringBuilder arg) { arg.append('\'') //this prints the value on ISO-8601, which is the recommended format on PostgreSQL .append(value.getValue().toString()) .append('\''); return null; }
private static int getWeekRange(int wby) { LocalDate date = LocalDate.of(wby, 1, 1); // 53 weeks if standard year starts on Thursday, or Wed in a leap year if (date.getDayOfWeek() == THURSDAY || (date.getDayOfWeek() == WEDNESDAY && date.isLeapYear())) { return 53; } return 52; }
private static int getWeekBasedYear(LocalDate date) { int year = date.getYear(); int doy = date.getDayOfYear(); if (doy <= 3) { int dow = date.getDayOfWeek().ordinal(); if (doy - dow < -2) { year--; } } else if (doy >= 363) { int dow = date.getDayOfWeek().ordinal(); doy = doy - 363 - (date.isLeapYear() ? 1 : 0); if (doy - dow >= 0) { year++; } } return year; } }
/** * @param year new instance's year * @param month new instance's month as defined by {@linkplain java.util.Calendar} * @param day new instance's day of month */ private CalendarDay(final int year, final int month, final int day) { date = LocalDate.of(year, month, day); }
LocalDate today = LocalDate.now(); collapsibleCalendar.addEventTag(today); LocalDate tomorrow = today.plusDays(1); collapsibleCalendar.addEventTag(tomorrow, Color.BLUE); Log.d("Testing date ", collapsibleCalendar.getSelectedDay().toString()); collapsibleCalendar.setCalendarListener(new CollapsibleCalendar.CalendarListener() { @Override
/** * Obtains the current month-day from the specified clock. * <p> * This will query the specified clock to obtain the current month-day. * Using this method allows the use of an alternate clock for testing. * The alternate clock may be introduced using {@link Clock dependency injection}. * * @param clock the clock to use, not null * @return the current month-day, not null */ public static MonthDay now(Clock clock) { final LocalDate now = LocalDate.now(clock); // called once return MonthDay.of(now.getMonth(), now.getDayOfMonth()); }
/** * Get a new instance set to today * * @return CalendarDay set to today's date */ @NonNull public static CalendarDay today() { return from(LocalDate.now()); }
@Override public boolean equals(Object o) { return o instanceof CalendarDay && date.equals(((CalendarDay) o).getDate()); }
/** * Get the year * * @return the year for this day */ public int getYear() { return date.getYear(); }
/** * Obtains the current year from the specified clock. * <p> * This will query the specified clock to obtain the current year. * Using this method allows the use of an alternate clock for testing. * The alternate clock may be introduced using {@link Clock dependency injection}. * * @param clock the clock to use, not null * @return the current year, not null */ public static Year now(Clock clock) { final LocalDate now = LocalDate.now(clock); // called once return Year.of(now.getYear()); }
@Override public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay calendarDay, boolean selected) { LocalDate localDate = calendarDay.getDate(); WeekFields weekFields = WeekFields.of(Locale.getDefault()); calendarBehavior.setWeekOfMonth(localDate.get(weekFields.weekOfMonth())); if (selected) { dayOfWeek = localDate.getDayOfWeek().getValue(); dayOfMonth = localDate.getDayOfMonth(); } } });