Search in sources :

Example 1 with DateTimeException

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);
        }
    }
}
Also used : Locale(java.util.Locale) ChronoLocalDate(java.time.chrono.ChronoLocalDate) DateTimeException(java.time.DateTimeException) YearMonth(java.time.YearMonth) Chronology(java.time.chrono.Chronology) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate)

Example 2 with DateTimeException

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
            }
        }
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) Test(org.testng.annotations.Test)

Example 3 with DateTimeException

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
        }
    }
}
Also used : HijrahDate(java.time.chrono.HijrahDate) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 4 with DateTimeException

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
        }
    }
}
Also used : HijrahDate(java.time.chrono.HijrahDate) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 5 with DateTimeException

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
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) WeekFields(java.time.temporal.WeekFields) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Aggregations

DateTimeException (java.time.DateTimeException)75 Test (org.testng.annotations.Test)58 TemporalField (java.time.temporal.TemporalField)48 HashMap (java.util.HashMap)34 LocalDate (java.time.LocalDate)18 TemporalAccessor (java.time.temporal.TemporalAccessor)13 DateTimeFormatter (java.time.format.DateTimeFormatter)11 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)10 MinguoDate (java.time.chrono.MinguoDate)7 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)7 MockFieldValue (test.java.time.temporal.MockFieldValue)7 HijrahDate (java.time.chrono.HijrahDate)6 ChronoLocalDate (java.time.chrono.ChronoLocalDate)5 JapaneseDate (java.time.chrono.JapaneseDate)5 Chronology (java.time.chrono.Chronology)4 IOException (java.io.IOException)3 WeekFields (java.time.temporal.WeekFields)3 AbstractTCKTest (tck.java.time.AbstractTCKTest)3 ResolverStyle (java.time.format.ResolverStyle)2 TemporalQuery (java.time.temporal.TemporalQuery)2