use of java.time.DateTimeException 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.DateTimeException in project jdk8u_jdk by JetBrains.
the class AbstractDateTimeTest method basicTest_getLong_TemporalField_unsupported.
@Test()
public void basicTest_getLong_TemporalField_unsupported() {
for (TemporalAccessor sample : samples()) {
for (TemporalField field : invalidFields()) {
try {
sample.getLong(field);
fail("Failed on " + sample + " " + field);
} catch (DateTimeException ex) {
// expected
}
}
}
}
use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.
the class TCKHijrahChronology method test_resolve_ymd_strict.
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
if (strict) {
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
assertEquals(date, expected, "Resolved to incorrect date");
assertEquals(fieldValues.size(), 0);
} else {
try {
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
fail("Should have failed, returned: " + date);
} catch (DateTimeException ex) {
// expected
}
}
}
use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.
the class TCKHijrahChronology method test_resolve_ymd_lenient.
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_lenient(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
if (expected != null) {
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
fail("Should have failed, returned: " + date);
} catch (DateTimeException ex) {
// expected
}
}
}
use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_parse_resolve_localizedWoy_strict.
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWoy_strict(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField woyField = week.weekOfYear();
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(woyField).appendLiteral(':').appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(STRICT);
String str = "2012:0:1";
try {
LocalDate date = LocalDate.parse(str, f);
assertEquals(date.getYear(), 2012);
assertEquals(date.get(woyField), 0);
assertEquals(date.get(DAY_OF_WEEK), 1);
} catch (DateTimeException ex) {
// expected
}
}
Aggregations