Search in sources :

Example 11 with WeekFields

use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.

the class TCKLocalizedFieldPrinter method test_print_WeekBasedYear.

@Test(dataProvider = "LocalWeekBasedYearPatterns")
public void test_print_WeekBasedYear(String pattern, String expectedText, LocalDate date) {
    DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern, locale);
    String result = dtf.format(date);
    WeekFields weekDef = WeekFields.of(locale);
    assertEquals(result, expectedText, "Incorrect formatting for " + pattern + ", weekDef: " + weekDef);
}
Also used : WeekFields(java.time.temporal.WeekFields) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 12 with WeekFields

use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.

the class TCKWeekFields method test_parse_resolve_localizedWoy_lenient.

@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWoy_lenient(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 15);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField woyField = week.weekOfYear();
    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(woyField).appendLiteral(':').appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(LENIENT);
        int woy = date.get(woyField);
        int dow = date.get(DAY_OF_WEEK);
        for (int j = woy - 60; j < woy + 60; j++) {
            String str = date.getYear() + ":" + j + ":" + dow;
            LocalDate parsed = LocalDate.parse(str, f);
            assertEquals(parsed, date.plusWeeks(j - woy), " ::" + str + ": :" + i + "::" + j);
        }
        date = date.plusDays(1);
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) WeekFields(java.time.temporal.WeekFields) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 13 with WeekFields

use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.

the class TCKWeekFields method test_parse_resolve_localizedWomDow.

//-----------------------------------------------------------------------
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWomDow(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 15);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField womField = week.weekOfMonth();
    for (int i = 1; i <= 15; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(MONTH_OF_YEAR).appendLiteral(':').appendValue(womField).appendLiteral(':').appendValue(dowField).toFormatter();
        String str = date.getYear() + ":" + date.getMonthValue() + ":" + date.get(womField) + ":" + date.get(dowField);
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, date, " :: " + str + " " + i);
        date = date.plusDays(1);
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) WeekFields(java.time.temporal.WeekFields) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 14 with WeekFields

use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.

the class TCKWeekFields method test_parse_resolve_localizedWoWBY.

//-----------------------------------------------------------------------
@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWoWBY(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();
    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(yowbyField).appendLiteral(':').appendValue(wowbyField).appendLiteral(':').appendValue(DAY_OF_WEEK).toFormatter();
        String str = date.get(yowbyField) + ":" + date.get(wowbyField) + ":" + date.get(DAY_OF_WEEK);
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, date, " :: " + str + " " + i);
        date = date.plusDays(1);
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) WeekFields(java.time.temporal.WeekFields) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 15 with WeekFields

use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.

the class TCKWeekFields method test_equals.

//-----------------------------------------------------------------------
// equals() and hashCode().
//-----------------------------------------------------------------------
@Test
public void test_equals() {
    WeekFields weekDef_iso = WeekFields.ISO;
    WeekFields weekDef_sundayStart = WeekFields.SUNDAY_START;
    assertTrue(weekDef_iso.equals(WeekFields.of(DayOfWeek.MONDAY, 4)));
    assertTrue(weekDef_sundayStart.equals(WeekFields.of(DayOfWeek.SUNDAY, 1)));
    assertEquals(weekDef_iso.hashCode(), WeekFields.of(DayOfWeek.MONDAY, 4).hashCode());
    assertEquals(weekDef_sundayStart.hashCode(), WeekFields.of(DayOfWeek.SUNDAY, 1).hashCode());
    assertFalse(weekDef_iso.equals(weekDef_sundayStart));
    assertNotEquals(weekDef_iso.hashCode(), weekDef_sundayStart.hashCode());
}
Also used : WeekFields(java.time.temporal.WeekFields) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Aggregations

WeekFields (java.time.temporal.WeekFields)33 Test (org.testng.annotations.Test)33 AbstractTCKTest (tck.java.time.AbstractTCKTest)29 LocalDate (java.time.LocalDate)25 TemporalField (java.time.temporal.TemporalField)25 DateTimeFormatter (java.time.format.DateTimeFormatter)18 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)17 DateTimeException (java.time.DateTimeException)3 ValueRange (java.time.temporal.ValueRange)3 ParsePosition (java.text.ParsePosition)2 DayOfWeek (java.time.DayOfWeek)2 TemporalAccessor (java.time.temporal.TemporalAccessor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 GregorianCalendar (java.util.GregorianCalendar)1