Search in sources :

Example 1 with ChronoLocalDate

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);
        }
    }
}
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 ChronoLocalDate

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");
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) TemporalField(java.time.temporal.TemporalField) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 3 with ChronoLocalDate

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);
                }
            }
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) ArrayList(java.util.ArrayList) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) Test(org.testng.annotations.Test)

Example 4 with ChronoLocalDate

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);
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 5 with ChronoLocalDate

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));
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) ChronoLocalDate(java.time.chrono.ChronoLocalDate) Temporal(java.time.temporal.Temporal) Test(org.testng.annotations.Test)

Aggregations

ChronoLocalDate (java.time.chrono.ChronoLocalDate)43 Test (org.testng.annotations.Test)34 Chronology (java.time.chrono.Chronology)28 IsoChronology (java.time.chrono.IsoChronology)19 ThaiBuddhistChronology (java.time.chrono.ThaiBuddhistChronology)18 HijrahChronology (java.time.chrono.HijrahChronology)17 MinguoChronology (java.time.chrono.MinguoChronology)17 JapaneseChronology (java.time.chrono.JapaneseChronology)15 LocalDate (java.time.LocalDate)10 DateTimeException (java.time.DateTimeException)5 ChronoPeriod (java.time.chrono.ChronoPeriod)4 Era (java.time.chrono.Era)4 DateTimeFormatter (java.time.format.DateTimeFormatter)3 TemporalAccessor (java.time.temporal.TemporalAccessor)3 TemporalField (java.time.temporal.TemporalField)3 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)2 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)2 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)2 Temporal (java.time.temporal.Temporal)2 TemporalAmount (java.time.temporal.TemporalAmount)2