Search in sources :

Example 36 with LocalDate

use of java.time.LocalDate in project jdk8u_jdk by JetBrains.

the class TCKIsoFields method test_loop.

//-----------------------------------------------------------------------
public void test_loop() {
    // loop round at least one 400 year cycle, including before 1970
    // Tuseday of week 1 1960
    LocalDate date = LocalDate.of(1960, 1, 5);
    int year = 1960;
    int wby = 1960;
    int weekLen = 52;
    int week = 1;
    while (date.getYear() < 2400) {
        DayOfWeek loopDow = date.getDayOfWeek();
        if (date.getYear() != year) {
            year = date.getYear();
        }
        if (loopDow == MONDAY) {
            week++;
            if ((week == 53 && weekLen == 52) || week == 54) {
                week = 1;
                LocalDate firstDayOfWeekBasedYear = date.plusDays(14).withDayOfYear(1);
                DayOfWeek firstDay = firstDayOfWeekBasedYear.getDayOfWeek();
                weekLen = (firstDay == THURSDAY || (firstDay == WEDNESDAY && firstDayOfWeekBasedYear.isLeapYear()) ? 53 : 52);
                wby++;
            }
        }
        assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.rangeRefinedBy(date), ValueRange.of(1, weekLen), "Failed on " + date + " " + date.getDayOfWeek());
        assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date), week, "Failed on " + date + " " + date.getDayOfWeek());
        assertEquals(date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR), week, "Failed on " + date + " " + date.getDayOfWeek());
        assertEquals(IsoFields.WEEK_BASED_YEAR.getFrom(date), wby, "Failed on " + date + " " + date.getDayOfWeek());
        assertEquals(date.get(IsoFields.WEEK_BASED_YEAR), wby, "Failed on " + date + " " + date.getDayOfWeek());
        date = date.plusDays(1);
    }
}
Also used : DayOfWeek(java.time.DayOfWeek) LocalDate(java.time.LocalDate)

Example 37 with LocalDate

use of java.time.LocalDate in project jdk8u_jdk by JetBrains.

the class TCKIsoFields method test_parse_parseLenientQuarter_SMART.

@Test(dataProvider = "parseLenientQuarter")
public void test_parse_parseLenientQuarter_SMART(String str, LocalDate expected, boolean smart) {
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':').appendValue(IsoFields.DAY_OF_QUARTER).toFormatter().withResolverStyle(ResolverStyle.SMART);
    if (smart) {
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, expected);
    } else {
        try {
            LocalDate.parse(str, f);
            fail("Should have failed");
        } catch (DateTimeParseException ex) {
        // expected
        }
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test)

Example 38 with LocalDate

use of java.time.LocalDate in project jdk8u_jdk by JetBrains.

the class TestIsoChronoImpl method test_IsoChrono_vsCalendar.

//-----------------------------------------------------------------------
// Verify  ISO Calendar matches java.util.Calendar for range
//-----------------------------------------------------------------------
@Test(dataProvider = "RangeVersusCalendar")
public void test_IsoChrono_vsCalendar(LocalDate isoStartDate, LocalDate isoEndDate) {
    GregorianCalendar cal = new GregorianCalendar();
    assertEquals(cal.getCalendarType(), "gregory", "Unexpected calendar type");
    LocalDate isoDate = IsoChronology.INSTANCE.date(isoStartDate);
    cal.setTimeZone(TimeZone.getTimeZone("GMT+00"));
    cal.set(Calendar.YEAR, isoDate.get(YEAR));
    cal.set(Calendar.MONTH, isoDate.get(MONTH_OF_YEAR) - 1);
    cal.set(Calendar.DAY_OF_MONTH, isoDate.get(DAY_OF_MONTH));
    while (isoDate.isBefore(isoEndDate)) {
        assertEquals(isoDate.get(DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH), "Day mismatch in " + isoDate + ";  cal: " + cal);
        assertEquals(isoDate.get(MONTH_OF_YEAR), cal.get(Calendar.MONTH) + 1, "Month mismatch in " + isoDate);
        assertEquals(isoDate.get(YEAR_OF_ERA), cal.get(Calendar.YEAR), "Year mismatch in " + isoDate);
        isoDate = isoDate.plus(1, ChronoUnit.DAYS);
        cal.add(Calendar.DAY_OF_MONTH, 1);
    }
}
Also used : GregorianCalendar(java.util.GregorianCalendar) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 39 with LocalDate

use of java.time.LocalDate in project jdk8u_jdk by JetBrains.

the class TestChronoLocalDate method test_date_comparator_checkGenerics_LocalDate.

public void test_date_comparator_checkGenerics_LocalDate() {
    List<LocalDate> dates = new ArrayList<>();
    LocalDate date = LocalDate.of(2013, 1, 1);
    // Insert dates in order, no duplicates
    dates.add(date.minus(10, ChronoUnit.YEARS));
    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));
    dates.add(date.plus(10, ChronoUnit.YEARS));
    List<LocalDate> copy = new ArrayList<>(dates);
    Collections.shuffle(copy);
    Collections.sort(copy, ChronoLocalDate.timeLineOrder());
    assertEquals(copy, dates);
    assertTrue(ChronoLocalDate.timeLineOrder().compare(copy.get(0), copy.get(1)) < 0);
}
Also used : ArrayList(java.util.ArrayList) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate)

Example 40 with LocalDate

use of java.time.LocalDate in project jdk8u_jdk by JetBrains.

the class TestUmmAlQuraChronology method test_LocalDate_adjustToHijrahDate.

// Test to get the local date by applying the MIN adjustment with hijrah date
@Test(dataProvider = "samples")
public void test_LocalDate_adjustToHijrahDate(ChronoLocalDate hijrahDate, LocalDate localDate) {
    LocalDate test = LocalDate.MIN.with(hijrahDate);
    assertEquals(test, localDate);
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

LocalDate (java.time.LocalDate)1513 Test (org.junit.Test)472 Test (org.testng.annotations.Test)372 LocalDateTime (java.time.LocalDateTime)155 LocalTime (java.time.LocalTime)126 Date (java.util.Date)99 DateTimeFormatter (java.time.format.DateTimeFormatter)96 Ignore (org.junit.Ignore)94 ArrayList (java.util.ArrayList)87 BigDecimal (java.math.BigDecimal)69 Instant (java.time.Instant)56 ZonedDateTime (java.time.ZonedDateTime)55 Test (org.junit.jupiter.api.Test)54 List (java.util.List)50 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)46 HashMap (java.util.HashMap)44 Member (cz.metacentrum.perun.core.api.Member)41 ZoneId (java.time.ZoneId)40 TemporalField (java.time.temporal.TemporalField)40 Attribute (cz.metacentrum.perun.core.api.Attribute)39