Java Code Examples for org.threeten.bp.LocalDate#of()
The following examples show how to use
org.threeten.bp.LocalDate#of() .
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: TestChronoLocalDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test(dataProvider="calendars") public void test_badWithAdjusterChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON); TemporalAdjuster adjuster = new FixedAdjuster(cdt2); if (chrono != chrono2) { try { cdt.with(adjuster); Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: " + cdt2); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoLocalDateTime<?> result = cdt.with(adjuster); assertEquals(result, cdt2, "WithAdjuster failed to replace date"); } } }
Example 2
Source File: ZoneRulesBuilder.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
private LocalDate toLocalDate() { LocalDate date; if (dayOfMonthIndicator < 0) { int monthLen = month.length(IsoChronology.INSTANCE.isLeapYear(year)); date = LocalDate.of(year, month, monthLen + 1 + dayOfMonthIndicator); if (dayOfWeek != null) { date = date.with(previousOrSame(dayOfWeek)); } } else { date = LocalDate.of(year, month, dayOfMonthIndicator); if (dayOfWeek != null) { date = date.with(nextOrSame(dayOfWeek)); } } return date; }
Example 3
Source File: ZoneOffsetTransitionRule.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Creates a transition instance for the specified year. * <p> * Calculations are performed using the ISO-8601 chronology. * * @param year the year to create a transition for, not null * @return the transition instance, not null */ public ZoneOffsetTransition createTransition(int year) { LocalDate date; if (dom < 0) { date = LocalDate.of(year, month, month.length(IsoChronology.INSTANCE.isLeapYear(year)) + 1 + dom); if (dow != null) { date = date.with(previousOrSame(dow)); } } else { date = LocalDate.of(year, month, dom); if (dow != null) { date = date.with(nextOrSame(dow)); } } LocalDateTime localDT = LocalDateTime.of(date.plusDays(adjustDays), time); LocalDateTime transition = timeDefinition.createDateTime(localDT, standardOffset, offsetBefore); return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter); }
Example 4
Source File: TestIsoFields.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@DataProvider(name="week") Object[][] data_week() { return new Object[][] { {LocalDate.of(1969, 12, 29), MONDAY, 1, 1970}, {LocalDate.of(2012, 12, 23), SUNDAY, 51, 2012}, {LocalDate.of(2012, 12, 24), MONDAY, 52, 2012}, {LocalDate.of(2012, 12, 27), THURSDAY, 52, 2012}, {LocalDate.of(2012, 12, 28), FRIDAY, 52, 2012}, {LocalDate.of(2012, 12, 29), SATURDAY, 52, 2012}, {LocalDate.of(2012, 12, 30), SUNDAY, 52, 2012}, {LocalDate.of(2012, 12, 31), MONDAY, 1, 2013}, {LocalDate.of(2013, 1, 1), TUESDAY, 1, 2013}, {LocalDate.of(2013, 1, 2), WEDNESDAY, 1, 2013}, {LocalDate.of(2013, 1, 6), SUNDAY, 1, 2013}, {LocalDate.of(2013, 1, 7), MONDAY, 2, 2013}, }; }
Example 5
Source File: TestChronoZonedDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test(dataProvider="calendars") public void test_badPlusPeriodUnitChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoZonedDateTime czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC); TemporalUnit adjuster = new FixedPeriodUnit(czdt2); if (chrono != chrono2) { try { czdt.plus(1, adjuster); Assert.fail("PeriodUnit.doPlus plus should have thrown a ClassCastException, " + czdt + " can not be cast to " + czdt2); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoZonedDateTime<?> result = czdt.plus(1, adjuster); assertEquals(result, czdt2, "WithAdjuster failed to replace date"); } } }
Example 6
Source File: TestChronoLocalDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test(dataProvider="calendars") public void test_badPlusPeriodUnitChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON); TemporalUnit adjuster = new FixedPeriodUnit(cdt2); if (chrono != chrono2) { try { cdt.plus(1, adjuster); Assert.fail("PeriodUnit.doAdd plus should have thrown a ClassCastException" + cdt + ", can not be cast to " + cdt2); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoLocalDateTime<?> result = cdt.plus(1, adjuster); assertEquals(result, cdt2, "WithAdjuster failed to replace date"); } } }
Example 7
Source File: TestChronoZonedDateTime.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test(dataProvider="calendars") public void test_badMinusPeriodUnitChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoZonedDateTime czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC); TemporalUnit adjuster = new FixedPeriodUnit(czdt2); if (chrono != chrono2) { try { czdt.minus(1, adjuster); Assert.fail("PeriodUnit.doPlus minus should have thrown a ClassCastException, " + czdt.getClass() + " can not be cast to " + czdt2.getClass()); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoZonedDateTime<?> result = czdt.minus(1, adjuster); assertEquals(result, czdt2, "WithAdjuster failed to replace date"); } } }
Example 8
Source File: CalendarPagerAdapter.java From material-calendarview with MIT License | 6 votes |
/** * 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 9
Source File: TestChronoLocalDate.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test(dataProvider="calendars") public void test_badDateTimeFieldChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(1900, 1, 1); ChronoLocalDate date = chrono.date(refDate); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoLocalDate date2 = chrono2.date(refDate); TemporalField adjuster = new FixedDateTimeField(date2); if (chrono != chrono2) { try { date.with(adjuster, 1); Assert.fail("DateTimeField doSet should have thrown a ClassCastException" + date.getClass() + ", can not be cast to " + date2.getClass()); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoLocalDate result = date.with(adjuster, 1); assertEquals(result, date2, "DateTimeField doSet failed to replace date"); } } }
Example 10
Source File: SwappableBasicActivityDecorated.java From material-calendarview with MIT License | 6 votes |
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_basic_modes); ButterKnife.bind(this); widget.setOnDateChangedListener(this); widget.setShowOtherDates(MaterialCalendarView.SHOW_ALL); final LocalDate instance = LocalDate.now(); widget.setSelectedDate(instance); final LocalDate min = LocalDate.of(instance.getYear(), Month.JANUARY, 1); final LocalDate max = LocalDate.of(instance.getYear(), Month.DECEMBER, 31); widget.state().edit().setMinimumDate(min).setMaximumDate(max).commit(); widget.addDecorators( new MySelectorDecorator(this), new HighlightWeekendsDecorator(), oneDayDecorator ); }
Example 11
Source File: DisableDaysActivity.java From material-calendarview with MIT License | 6 votes |
@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(); }
Example 12
Source File: TestIsoChronology.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 6 votes |
@DataProvider(name="samples") Object[][] data_samples() { return new Object[][] { {IsoChronology.INSTANCE.date(1, 7, 8), LocalDate.of(1, 7, 8)}, {IsoChronology.INSTANCE.date(1, 7, 20), LocalDate.of(1, 7, 20)}, {IsoChronology.INSTANCE.date(1, 7, 21), LocalDate.of(1, 7, 21)}, {IsoChronology.INSTANCE.date(2, 7, 8), LocalDate.of(2, 7, 8)}, {IsoChronology.INSTANCE.date(3, 6, 27), LocalDate.of(3, 6, 27)}, {IsoChronology.INSTANCE.date(3, 5, 23), LocalDate.of(3, 5, 23)}, {IsoChronology.INSTANCE.date(4, 6, 16), LocalDate.of(4, 6, 16)}, {IsoChronology.INSTANCE.date(4, 7, 3), LocalDate.of(4, 7, 3)}, {IsoChronology.INSTANCE.date(4, 7, 4), LocalDate.of(4, 7, 4)}, {IsoChronology.INSTANCE.date(5, 1, 1), LocalDate.of(5, 1, 1)}, {IsoChronology.INSTANCE.date(1727, 3, 3), LocalDate.of(1727, 3, 3)}, {IsoChronology.INSTANCE.date(1728, 10, 28), LocalDate.of(1728, 10, 28)}, {IsoChronology.INSTANCE.date(2012, 10, 29), LocalDate.of(2012, 10, 29)}, }; }
Example 13
Source File: TestDateTimeBuilderCombinations.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@DataProvider(name = "combine") Object[][] data_combine() { return new Object[][] { {YEAR, 2012, MONTH_OF_YEAR, 6, DAY_OF_MONTH, 3, null, null, LocalDate.FROM, LocalDate.of(2012, 6, 3)}, {PROLEPTIC_MONTH, 2012 * 12 + 6 - 1, DAY_OF_MONTH, 3, null, null, null, null, LocalDate.FROM, LocalDate.of(2012, 6, 3)}, {YEAR, 2012, ALIGNED_WEEK_OF_YEAR, 6, DAY_OF_WEEK, 3, null, null, LocalDate.FROM, LocalDate.of(2012, 2, 8)}, {YEAR, 2012, DAY_OF_YEAR, 155, null, null, null, null, LocalDate.FROM, LocalDate.of(2012, 6, 3)}, // {ERA, 1, YEAR_OF_ERA, 2012, DAY_OF_YEAR, 155, null, null, LocalDate.FROM, LocalDate.of(2012, 6, 3)}, // {YEAR, 2012, MONTH_OF_YEAR, 6, null, null, null, null, LocalDate.FROM, null}, {EPOCH_DAY, 12, null, null, null, null, null, null, LocalDate.FROM, LocalDate.of(1970, 1, 13)}, }; }
Example 14
Source File: TestYear.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void test_adjustDate() { LocalDate base = LocalDate.of(2007, 2, 12); for (int i = -4; i <= 2104; i++) { Temporal result = Year.of(i).adjustInto(base); assertEquals(result, LocalDate.of(i, 2, 12)); } }
Example 15
Source File: TestYear.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@DataProvider(name="atMonthDay") Object[][] data_atMonthDay() { return new Object[][] { {Year.of(2008), MonthDay.of(6, 30), LocalDate.of(2008, 6, 30)}, {Year.of(2008), MonthDay.of(2, 29), LocalDate.of(2008, 2, 29)}, {Year.of(2009), MonthDay.of(2, 29), LocalDate.of(2009, 2, 28)}, }; }
Example 16
Source File: TestIsoFields.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 5 votes |
@DataProvider(name="quartersBetween") Object[][] data_quartersBetween() { return new Object[][] { {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 1, 1), 0}, {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 1, 2), 0}, {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 2, 1), 0}, {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 3, 1), 0}, {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 3, 31), 0}, {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 4, 1), 1}, {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 4, 2), 1}, {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 6, 30), 1}, {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 7, 1), 2}, {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 10, 1), 3}, {LocalDate.of(2000, 1, 1), LocalDate.of(2000, 12, 31), 3}, {LocalDate.of(2000, 1, 1), LocalDate.of(2001, 1, 1), 4}, {LocalDate.of(2000, 1, 1), LocalDate.of(2002, 1, 1), 8}, {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 12, 31), 0}, {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 10, 2), 0}, {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 10, 1), -1}, {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 7, 2), -1}, {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 7, 1), -2}, {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 4, 2), -2}, {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 4, 1), -3}, {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 1, 2), -3}, {LocalDate.of(2000, 1, 1), LocalDate.of(1999, 1, 1), -4}, {LocalDate.of(2000, 1, 1), LocalDate.of(1998, 12, 31), -4}, {LocalDate.of(2000, 1, 1), LocalDate.of(1998, 10, 2), -4}, {LocalDate.of(2000, 1, 1), LocalDate.of(1998, 10, 1), -5}, }; }
Example 17
Source File: JapaneseChronology.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override // override with covariant return type public JapaneseDate date(int prolepticYear, int month, int dayOfMonth) { return new JapaneseDate(LocalDate.of(prolepticYear, month, dayOfMonth)); }
Example 18
Source File: TestYearMonth.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void test_adjustDate_resolve() { YearMonth test = YearMonth.of(2007, 2); LocalDate date = LocalDate.of(2008, 3, 31); assertEquals(test.adjustInto(date), LocalDate.of(2007, 2, 28)); }
Example 19
Source File: TestYearMonth.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void test_adjustDate_equal() { YearMonth test = YearMonth.of(2008, 6); LocalDate date = LocalDate.of(2008, 6, 30); assertEquals(test.adjustInto(date), date); }
Example 20
Source File: TestYearMonth.java From threetenbp with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void test_adjustDate() { YearMonth test = YearMonth.of(2008, 6); LocalDate date = LocalDate.of(2007, 1, 1); assertEquals(test.adjustInto(date), LocalDate.of(2008, 6, 1)); }