Java Code Examples for java.time.temporal.WeekFields#of()

The following examples show how to use java.time.temporal.WeekFields#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKWeekFields.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoy(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();
        String str = date.getYear() + ":" +
                date.get(woyField) + ":" + date.get(DAY_OF_WEEK);
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, date, " :: " + str + " " + i);

        date = date.plusDays(1);
    }
}
 
Example 2
Source File: TCKWeekFields.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example 3
Source File: DefaultDateFunctions.java    From jackcess with Apache License 2.0 6 votes vote down vote up
static WeekFields weekFields(int firstDay, int firstWeekType) {

    int minDays = 1;
    switch(firstWeekType) {
    case 1:
      // vbUseSystem 0
      // vbFirstJan1 1 (default)
      break;
    case 2:
      // vbFirstFourDays 2
      minDays = 4;
      break;
    case 3:
      // vbFirstFullWeek 3
      minDays = 7;
      break;
    default:
      throw new EvalException("Invalid first week of year type " +
                              firstWeekType);
    }

    return WeekFields.of(dayOfWeek(firstDay), minDays);
  }
 
Example 4
Source File: TCKWeekFields.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBYDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    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(dowField).toFormatter().withResolverStyle(LENIENT);
        int wowby = date.get(wowbyField);
        int dow = date.get(dowField);
        for (int j = wowby - 60; j < wowby + 60; j++) {
            String str = date.get(yowbyField) + ":" + j + ":" + dow;
            LocalDate parsed = LocalDate.parse(str, f);
            assertEquals(parsed, date.plusWeeks(j - wowby), " ::" + str + ": :" + i + "::" + j);
        }

        date = date.plusDays(1);
    }
}
 
Example 5
Source File: TCKWeekFields.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@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
    }
}
 
Example 6
Source File: TCKWeekFields.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoyDow(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 15);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField woyField = week.weekOfYear();

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(YEAR).appendLiteral(':')
                .appendValue(MONTH_OF_YEAR).appendLiteral(':')
                .appendValue(woyField).appendLiteral(':')
                .appendValue(dowField).toFormatter();
        String str = date.getYear() + ":" + date.getMonthValue() + ":" +
                date.get(woyField) + ":" + date.get(dowField);
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, date, " :: " + str + " " + i);

        date = date.plusDays(1);
    }
}
 
Example 7
Source File: TCKWeekFields.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example 8
Source File: TCKWeekFields.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_fieldRanges(DayOfWeek firstDayOfWeek, int minDays) {
    WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField womField = weekDef.weekOfMonth();
    TemporalField woyField = weekDef.weekOfYear();

    LocalDate day = LocalDate.of(2012, 11, 30);
    LocalDate endDay = LocalDate.of(2013, 1, 2);
    while (day.isBefore(endDay)) {
        LocalDate last = day.with(DAY_OF_MONTH, day.lengthOfMonth());
        int lastWOM = last.get(womField);
        LocalDate first = day.with(DAY_OF_MONTH, 1);
        int firstWOM = first.get(womField);
        ValueRange rangeWOM = day.range(womField);
        assertEquals(rangeWOM.getMinimum(), firstWOM,
                "Range min should be same as WeekOfMonth for first day of month: "
                + first + ", " + weekDef);
        assertEquals(rangeWOM.getMaximum(), lastWOM,
                "Range max should be same as WeekOfMonth for last day of month: "
                + last + ", " + weekDef);

        last = day.with(DAY_OF_YEAR, day.lengthOfYear());
        int lastWOY = last.get(woyField);
        first = day.with(DAY_OF_YEAR, 1);
        int firstWOY = first.get(woyField);
        ValueRange rangeWOY = day.range(woyField);
        assertEquals(rangeWOY.getMinimum(), firstWOY,
                "Range min should be same as WeekOfYear for first day of Year: "
                + day + ", " + weekDef);
        assertEquals(rangeWOY.getMaximum(), lastWOY,
                "Range max should be same as WeekOfYear for last day of Year: "
                + day + ", " + weekDef);

        day = day.plusDays(1);
    }
}
 
Example 9
Source File: TCKWeekFields.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("data_weekFields")
public void test_withWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    int dowExpected = (day.get(dowField) - 1) % 7 + 1;
    LocalDate dowDate = day.with(dowField, dowExpected);
    int dowResult = dowDate.get(dowField);
    assertEquals("Localized DayOfWeek not correct; " + day + " -->" + dowDate, dowResult, dowExpected);

    int weekExpected = day.get(wowbyField) + 1;
    ValueRange range = day.range(wowbyField);
    weekExpected = ((weekExpected - 1) % (int)range.getMaximum()) + 1;
    LocalDate weekDate = day.with(wowbyField, weekExpected);
    int weekResult = weekDate.get(wowbyField);
    assertEquals("Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate, weekResult, weekExpected);

    int yearExpected = day.get(yowbyField) + 1;

    LocalDate yearDate = day.with(yowbyField, yearExpected);
    int yearResult = yearDate.get(yowbyField);
    assertEquals("Localized WeekBasedYear not correct; " + day  + " --> " + yearDate, yearResult, yearExpected);

    range = yearDate.range(wowbyField);
    weekExpected = Math.min(day.get(wowbyField), (int)range.getMaximum());

    int weekActual = yearDate.get(wowbyField);
    assertEquals("Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected, weekActual, weekExpected);
}
 
Example 10
Source File: TCKLocalizedFieldParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="FieldPatterns")
public void test_parse_textField(String pattern, String text, int pos, int expectedPos, long expectedValue) {
    WeekFields weekDef = WeekFields.of(locale);
    TemporalField field = null;
    switch(pattern.charAt(0)) {
        case 'e' :
            field = weekDef.dayOfWeek();
            break;
        case 'w':
            field = weekDef.weekOfWeekBasedYear();
            break;
        case 'W':
            field = weekDef.weekOfMonth();
            break;
        case 'Y':
            field = weekDef.weekBasedYear();
            break;
        default:
            throw new IllegalStateException("bad format letter from pattern");
    }
    ParsePosition ppos = new ParsePosition(pos);
    DateTimeFormatterBuilder b
            = new DateTimeFormatterBuilder().appendPattern(pattern);
    DateTimeFormatter dtf = b.toFormatter(locale);
    TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), expectedPos);
    } else {
        assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position");
        long value = parsed.getLong(field);
        assertEquals(value, expectedValue, "Value incorrect for " + field);
    }
}
 
Example 11
Source File: DateTimeFormatterBuilder.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the printerParser to use based on the field and the locale.
 *
 * @param locale  the locale to use, not null
 * @return the formatter, not null
 * @throws IllegalArgumentException if the formatter cannot be found
 */
private DateTimePrinterParser printerParser(Locale locale) {
    WeekFields weekDef = WeekFields.of(locale);
    TemporalField field = null;
    switch (chr) {
        case 'Y':
            field = weekDef.weekBasedYear();
            if (count == 2) {
                return new ReducedPrinterParser(field, 2, 2, 0, ReducedPrinterParser.BASE_DATE, 0);
            } else {
                return new NumberPrinterParser(field, count, 19,
                        (count < 4) ? SignStyle.NORMAL : SignStyle.EXCEEDS_PAD, -1);
            }
        case 'e':
        case 'c':
            field = weekDef.dayOfWeek();
            break;
        case 'w':
            field = weekDef.weekOfWeekBasedYear();
            break;
        case 'W':
            field = weekDef.weekOfMonth();
            break;
        default:
            throw new IllegalStateException("unreachable");
    }
    return new NumberPrinterParser(field, (count == 2 ? 2 : 1), 2, SignStyle.NOT_NEGATIVE);
}
 
Example 12
Source File: TCKWeekFields.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_fieldRanges(DayOfWeek firstDayOfWeek, int minDays) {
    WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField womField = weekDef.weekOfMonth();
    TemporalField woyField = weekDef.weekOfYear();

    LocalDate day = LocalDate.of(2012, 11, 30);
    LocalDate endDay = LocalDate.of(2013, 1, 2);
    while (day.isBefore(endDay)) {
        LocalDate last = day.with(DAY_OF_MONTH, day.lengthOfMonth());
        int lastWOM = last.get(womField);
        LocalDate first = day.with(DAY_OF_MONTH, 1);
        int firstWOM = first.get(womField);
        ValueRange rangeWOM = day.range(womField);
        assertEquals(rangeWOM.getMinimum(), firstWOM,
                "Range min should be same as WeekOfMonth for first day of month: "
                + first + ", " + weekDef);
        assertEquals(rangeWOM.getMaximum(), lastWOM,
                "Range max should be same as WeekOfMonth for last day of month: "
                + last + ", " + weekDef);

        last = day.with(DAY_OF_YEAR, day.lengthOfYear());
        int lastWOY = last.get(woyField);
        first = day.with(DAY_OF_YEAR, 1);
        int firstWOY = first.get(woyField);
        ValueRange rangeWOY = day.range(woyField);
        assertEquals(rangeWOY.getMinimum(), firstWOY,
                "Range min should be same as WeekOfYear for first day of Year: "
                + day + ", " + weekDef);
        assertEquals(rangeWOY.getMaximum(), lastWOY,
                "Range max should be same as WeekOfYear for last day of Year: "
                + day + ", " + weekDef);

        day = day.plusDays(1);
    }
}
 
Example 13
Source File: TCKLocalizedFieldParser.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="FieldPatterns")
public void test_parse_textField(String pattern, String text, int pos, int expectedPos, long expectedValue) {
    WeekFields weekDef = WeekFields.of(locale);
    TemporalField field = null;
    switch(pattern.charAt(0)) {
        case 'e' :
            field = weekDef.dayOfWeek();
            break;
        case 'w':
            field = weekDef.weekOfWeekBasedYear();
            break;
        case 'W':
            field = weekDef.weekOfMonth();
            break;
        case 'Y':
            field = weekDef.weekBasedYear();
            break;
        default:
            throw new IllegalStateException("bad format letter from pattern");
    }
    ParsePosition ppos = new ParsePosition(pos);
    DateTimeFormatterBuilder b
            = new DateTimeFormatterBuilder().appendPattern(pattern);
    DateTimeFormatter dtf = b.toFormatter(locale);
    TemporalAccessor parsed = dtf.parseUnresolved(text, ppos);
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), expectedPos);
    } else {
        assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position");
        long value = parsed.getLong(field);
        assertEquals(value, expectedValue, "Value incorrect for " + field);
    }
}
 
Example 14
Source File: TCKWeekFields.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_weekOfMonthField(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);  // Known to be ISO Monday
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField womField = week.weekOfMonth();

    for (int i = 1; i <= 15; i++) {
        int actualDOW = day.get(dowField);
        int actualWOM = day.get(womField);

        // Verify that the combination of day of week and week of month can be used
        // to reconstruct the same date.
        LocalDate day1 = day.withDayOfMonth(1);
        int offset = - (day1.get(dowField) - 1);

        int week1 = day1.get(womField);
        if (week1 == 0) {
            // week of the 1st is partial; start with first full week
            offset += 7;
        }

        offset += actualDOW - 1;
        offset += (actualWOM - 1) * 7;
        LocalDate result = day1.plusDays(offset);

        assertEquals(result, day, "Incorrect dayOfWeek or weekOfMonth: "
                + String.format("%s, ISO Dow: %s, offset: %s, actualDOW: %s, actualWOM: %s, expected: %s, result: %s%n",
                week, day.getDayOfWeek(), offset, actualDOW, actualWOM, day, result));
        day = day.plusDays(1);
    }
}
 
Example 15
Source File: TCKWeekFields.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_weekOfMonthField(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);  // Known to be ISO Monday
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField womField = week.weekOfMonth();

    for (int i = 1; i <= 15; i++) {
        int actualDOW = day.get(dowField);
        int actualWOM = day.get(womField);

        // Verify that the combination of day of week and week of month can be used
        // to reconstruct the same date.
        LocalDate day1 = day.withDayOfMonth(1);
        int offset = - (day1.get(dowField) - 1);

        int week1 = day1.get(womField);
        if (week1 == 0) {
            // week of the 1st is partial; start with first full week
            offset += 7;
        }

        offset += actualDOW - 1;
        offset += (actualWOM - 1) * 7;
        LocalDate result = day1.plusDays(offset);

        assertEquals(result, day, "Incorrect dayOfWeek or weekOfMonth: "
                + String.format("%s, ISO Dow: %s, offset: %s, actualDOW: %s, actualWOM: %s, expected: %s, result: %s%n",
                week, day.getDayOfWeek(), offset, actualDOW, actualWOM, day, result));
        day = day.plusDays(1);
    }
}
 
Example 16
Source File: TCKWeekFields.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_weekOfMonthField(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);  // Known to be ISO Monday
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField womField = week.weekOfMonth();

    for (int i = 1; i <= 15; i++) {
        int actualDOW = day.get(dowField);
        int actualWOM = day.get(womField);

        // Verify that the combination of day of week and week of month can be used
        // to reconstruct the same date.
        LocalDate day1 = day.withDayOfMonth(1);
        int offset = - (day1.get(dowField) - 1);

        int week1 = day1.get(womField);
        if (week1 == 0) {
            // week of the 1st is partial; start with first full week
            offset += 7;
        }

        offset += actualDOW - 1;
        offset += (actualWOM - 1) * 7;
        LocalDate result = day1.plusDays(offset);

        assertEquals(result, day, "Incorrect dayOfWeek or weekOfMonth: "
                + String.format("%s, ISO Dow: %s, offset: %s, actualDOW: %s, actualWOM: %s, expected: %s, result: %s%n",
                week, day.getDayOfWeek(), offset, actualDOW, actualWOM, day, result));
        day = day.plusDays(1);
    }
}
 
Example 17
Source File: TCKWeekFields.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_weekOfYearField(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);  // Known to be ISO Monday
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField woyField = week.weekOfYear();

    for (int i = 1; i <= 15; i++) {
        int actualDOW = day.get(dowField);
        int actualWOY = day.get(woyField);

        // Verify that the combination of day of week and week of month can be used
        // to reconstruct the same date.
        LocalDate day1 = day.withDayOfYear(1);
        int offset = - (day1.get(dowField) - 1);
        int week1 = day1.get(woyField);
        if (week1 == 0) {
            // week of the 1st is partial; start with first full week
            offset += 7;
        }
        offset += actualDOW - 1;
        offset += (actualWOY - 1) * 7;
        LocalDate result = day1.plusDays(offset);

        assertEquals(result, day, "Incorrect dayOfWeek or weekOfYear "
                + String.format("%s, ISO Dow: %s, offset: %s, actualDOW: %s, actualWOM: %s, expected: %s, result: %s%n",
                week, day.getDayOfWeek(), offset, actualDOW, actualWOY, day, result));
        day = day.plusDays(1);
    }
}
 
Example 18
Source File: TestIsoChronoImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "RangeVersusCalendar")
public void test_DayOfWeek_IsoChronology_vsCalendar(LocalDate isoStartDate, LocalDate isoEndDate) {
    GregorianCalendar cal = new GregorianCalendar();
    assertEquals(cal.getCalendarType(), "gregory", "Unexpected calendar type");
    LocalDate isoDate = IsoChronology.INSTANCE.date(isoStartDate);

    for (DayOfWeek firstDayOfWeek : DayOfWeek.values()) {
        for (int minDays = 1; minDays <= 7; minDays++) {
            WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
            cal.setFirstDayOfWeek(Math.floorMod(firstDayOfWeek.getValue(), 7) + 1);
            cal.setMinimalDaysInFirstWeek(minDays);

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

            // For every date in the range
            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);

                int jdow = Math.floorMod(cal.get(Calendar.DAY_OF_WEEK) - 2, 7) + 1;
                int dow = isoDate.get(weekDef.dayOfWeek());
                assertEquals(jdow, dow, "Calendar DayOfWeek does not match ISO DayOfWeek");

                int jweekOfMonth = cal.get(Calendar.WEEK_OF_MONTH);
                int isoWeekOfMonth = isoDate.get(weekDef.weekOfMonth());
                assertEquals(jweekOfMonth, isoWeekOfMonth, "Calendar WeekOfMonth does not match ISO WeekOfMonth");

                int jweekOfYear = cal.get(Calendar.WEEK_OF_YEAR);
                int weekOfYear = isoDate.get(weekDef.weekOfWeekBasedYear());
                assertEquals(jweekOfYear, weekOfYear,  "GregorianCalendar WeekOfYear does not match WeekOfWeekBasedYear");

                int jWeekYear = cal.getWeekYear();
                int weekBasedYear = isoDate.get(weekDef.weekBasedYear());
                assertEquals(jWeekYear, weekBasedYear,  "GregorianCalendar getWeekYear does not match YearOfWeekBasedYear");

                int jweeksInWeekyear = cal.getWeeksInWeekYear();
                int weeksInWeekBasedYear = (int)isoDate.range(weekDef.weekOfWeekBasedYear()).getMaximum();
                assertEquals(jweeksInWeekyear, weeksInWeekBasedYear, "length of weekBasedYear");

                isoDate = isoDate.plus(1, ChronoUnit.DAYS);
                cal.add(Calendar.DAY_OF_MONTH, 1);
            }
        }
    }
}
 
Example 19
Source File: TCKWeekFieldsSerialization.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_serializable_singleton(DayOfWeek firstDayOfWeek, int minDays) throws IOException, ClassNotFoundException {
    WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
    assertSerializableSame(weekDef);  // spec state singleton
}
 
Example 20
Source File: TCKWeekFieldsSerialization.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="weekFields")
public void test_serializable_singleton(DayOfWeek firstDayOfWeek, int minDays) throws IOException, ClassNotFoundException {
    WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
    assertSerializableSame(weekDef);  // spec state singleton
}