use of java.time.chrono.ChronoLocalDate in project JFoenix by jfoenixadmin.
the class JFXDatePickerContent method updateDayCells.
void updateDayCells() {
Locale locale = getLocale();
Chronology chrono = getPrimaryChronology();
// get the index of the first day of the month
int firstDayOfWeek = WeekFields.of(getLocale()).getFirstDayOfWeek().getValue();
int firstOfMonthIndex = selectedYearMonth.get().atDay(1).getDayOfWeek().getValue() - firstDayOfWeek;
firstOfMonthIndex += firstOfMonthIndex < 0 ? daysPerWeek : 0;
YearMonth currentYearMonth = selectedYearMonth.get();
int daysInCurMonth = -1;
for (int i = 0; i < 6 * daysPerWeek; i++) {
DateCell dayCell = dayCells.get(i);
dayCell.getStyleClass().setAll("cell", "date-cell", "day-cell");
dayCell.setPrefSize(40, 42);
dayCell.setDisable(false);
dayCell.setStyle(null);
dayCell.setGraphic(null);
dayCell.setTooltip(null);
dayCell.setTextFill(Color.valueOf("#313131"));
dayCell.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
try {
if (daysInCurMonth == -1)
daysInCurMonth = currentYearMonth.lengthOfMonth();
YearMonth month = currentYearMonth;
int dayIndex = i - firstOfMonthIndex + 1;
LocalDate date = month.atDay(dayIndex);
dayCellDates[i] = date;
// if it's today
if (date.equals(LocalDate.now())) {
dayCell.setTextFill(this.datePicker.getDefaultColor());
dayCell.getStyleClass().add("today");
}
// if it's the current selected value
if (date.equals(datePicker.getValue())) {
dayCell.getStyleClass().add("selected");
dayCell.setTextFill(Color.WHITE);
dayCell.setBackground(new Background(new BackgroundFill(this.datePicker.getDefaultColor(), new CornerRadii(40), Insets.EMPTY)));
}
ChronoLocalDate cDate = chrono.date(date);
String cellText = dayCellFormatter.withLocale(locale).withChronology(chrono).withDecimalStyle(DecimalStyle.of(locale)).format(cDate);
dayCell.setText(cellText);
if (i < firstOfMonthIndex) {
dayCell.getStyleClass().add("previous-month");
dayCell.setText("");
} else if (i >= firstOfMonthIndex + daysInCurMonth) {
dayCell.getStyleClass().add("next-month");
dayCell.setText("");
}
// update cell item
dayCell.updateItem(date, false);
} catch (DateTimeException ex) {
// Disable day cell if its date is out of range
dayCell.setText("");
dayCell.setDisable(true);
}
}
}
use of java.time.chrono.ChronoLocalDate in project jdk8u_jdk by JetBrains.
the class TCKChronoLocalDate method test_badTemporalFieldChrono.
@Test(dataProvider = "calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 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 FixedTemporalField(date2);
if (chrono != chrono2) {
try {
date.with(adjuster, 1);
Assert.fail("TemporalField 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, "TemporalField doSet failed to replace date");
}
}
}
use of java.time.chrono.ChronoLocalDate in project jdk8u_jdk by JetBrains.
the class TCKChronoLocalDate method test_date_comparisons.
//-----------------------------------------------------------------------
// isBefore, isAfter, isEqual, DATE_COMPARATOR
//-----------------------------------------------------------------------
@Test(dataProvider = "calendars")
public void test_date_comparisons(Chronology chrono) {
List<ChronoLocalDate> dates = new ArrayList<>();
ChronoLocalDate date = chrono.date(LocalDate.of(2013, 1, 1));
// Insert dates in order, no duplicates
dates.add(date.minus(1, ChronoUnit.YEARS));
dates.add(date.minus(1, ChronoUnit.MONTHS));
dates.add(date.minus(1, ChronoUnit.WEEKS));
dates.add(date.minus(1, ChronoUnit.DAYS));
dates.add(date);
dates.add(date.plus(1, ChronoUnit.DAYS));
dates.add(date.plus(1, ChronoUnit.WEEKS));
dates.add(date.plus(1, ChronoUnit.MONTHS));
dates.add(date.plus(1, ChronoUnit.YEARS));
// Check these dates against the corresponding dates for every calendar
for (Chronology[] clist : data_of_calendars()) {
List<ChronoLocalDate> otherDates = new ArrayList<>();
Chronology chrono2 = clist[0];
for (ChronoLocalDate d : dates) {
otherDates.add(chrono2.date(d));
}
// Now compare the sequence of original dates with the sequence of converted dates
for (int i = 0; i < dates.size(); i++) {
ChronoLocalDate a = dates.get(i);
for (int j = 0; j < otherDates.size(); j++) {
ChronoLocalDate b = otherDates.get(j);
int cmp = ChronoLocalDate.timeLineOrder().compare(a, b);
if (i < j) {
assertTrue(cmp < 0, a + " compare " + b);
assertEquals(a.isBefore(b), true, a + " isBefore " + b);
assertEquals(a.isAfter(b), false, a + " isAfter " + b);
assertEquals(a.isEqual(b), false, a + " isEqual " + b);
} else if (i > j) {
assertTrue(cmp > 0, a + " compare " + b);
assertEquals(a.isBefore(b), false, a + " isBefore " + b);
assertEquals(a.isAfter(b), true, a + " isAfter " + b);
assertEquals(a.isEqual(b), false, a + " isEqual " + b);
} else {
assertTrue(cmp == 0, a + " compare " + b);
assertEquals(a.isBefore(b), false, a + " isBefore " + b);
assertEquals(a.isAfter(b), false, a + " isAfter " + b);
assertEquals(a.isEqual(b), true, a + " isEqual " + b);
}
}
}
}
}
use of java.time.chrono.ChronoLocalDate in project jdk8u_jdk by JetBrains.
the class TCKChronoLocalDate method test_from_TemporalAccessor.
//-----------------------------------------------------------------------
@Test(dataProvider = "calendars")
public void test_from_TemporalAccessor(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDate date = chrono.date(refDate);
ChronoLocalDate test1 = ChronoLocalDate.from(date);
assertEquals(test1, date);
ChronoLocalDate test2 = ChronoLocalDate.from(date.atTime(LocalTime.of(12, 30)));
assertEquals(test2, date);
ChronoLocalDate test3 = ChronoLocalDate.from(date.atTime(LocalTime.of(12, 30)).atZone(ZoneOffset.UTC));
assertEquals(test3, date);
}
use of java.time.chrono.ChronoLocalDate in project jdk8u_jdk by JetBrains.
the class TCKChronoPeriod method test_addTo.
//-----------------------------------------------------------------------
@Test(dataProvider = "calendars")
public void test_addTo(Chronology chrono) {
ChronoPeriod period = chrono.period(1, 2, 3);
ChronoLocalDate date = chrono.dateNow();
Temporal result = period.addTo(date);
assertEquals(result, date.plus(14, MONTHS).plus(3, DAYS));
}
Aggregations