Search in sources :

Example 6 with WeekFields

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

the class TCKWeekFields method test_basics.

//-----------------------------------------------------------------------
@Test(dataProvider = "weekFields")
public void test_basics(DayOfWeek firstDayOfWeek, int minDays) {
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    assertEquals(week.dayOfWeek().isDateBased(), true);
    assertEquals(week.dayOfWeek().isTimeBased(), false);
    assertEquals(week.weekOfMonth().isDateBased(), true);
    assertEquals(week.weekOfMonth().isTimeBased(), false);
    assertEquals(week.weekOfYear().isDateBased(), true);
    assertEquals(week.weekOfYear().isTimeBased(), false);
    assertEquals(week.weekOfWeekBasedYear().isDateBased(), true);
    assertEquals(week.weekOfWeekBasedYear().isTimeBased(), false);
    assertEquals(week.weekBasedYear().isDateBased(), true);
    assertEquals(week.weekBasedYear().isTimeBased(), false);
}
Also used : WeekFields(java.time.temporal.WeekFields) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 7 with WeekFields

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

the class TCKWeekFields method test_fieldRanges.

@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);
    }
}
Also used : ValueRange(java.time.temporal.ValueRange) TemporalField(java.time.temporal.TemporalField) WeekFields(java.time.temporal.WeekFields) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 8 with WeekFields

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

the class TCKWeekFields method test_parse_resolve_localizedWomDow_lenient.

@Test(dataProvider = "weekFields")
public void test_parse_resolve_localizedWomDow_lenient(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 <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(YEAR).appendLiteral(':').appendValue(MONTH_OF_YEAR).appendLiteral(':').appendValue(womField).appendLiteral(':').appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
        int wom = date.get(womField);
        int dow = date.get(dowField);
        for (int j = wom - 10; j < wom + 10; j++) {
            String str = date.getYear() + ":" + date.getMonthValue() + ":" + j + ":" + dow;
            LocalDate parsed = LocalDate.parse(str, f);
            assertEquals(parsed, date.plusWeeks(j - wom), " ::" + 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 9 with WeekFields

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

the class TCKWeekFields method test_WOWBY.

//-----------------------------------------------------------------------
// WEEK_OF_WEEK_BASED_YEAR
// Validate with the same data used by IsoFields.
//-----------------------------------------------------------------------
@Test(dataProvider = "IsoWeekData")
public void test_WOWBY(LocalDate date, DayOfWeek dow, int week, int wby) {
    WeekFields weekDef = WeekFields.ISO;
    TemporalField dowField = weekDef.dayOfWeek();
    TemporalField wowbyField = weekDef.weekOfWeekBasedYear();
    TemporalField yowbyField = weekDef.weekBasedYear();
    assertEquals(date.get(dowField), dow.getValue());
    assertEquals(date.get(wowbyField), week);
    assertEquals(date.get(yowbyField), wby);
}
Also used : TemporalField(java.time.temporal.TemporalField) WeekFields(java.time.temporal.WeekFields) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 10 with WeekFields

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

the class TCKWeekFields method test_of_DayOfWeek_int_singleton.

@Test(dataProvider = "weekFields")
public void test_of_DayOfWeek_int_singleton(DayOfWeek firstDayOfWeek, int minDays) {
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    assertEquals(week.getFirstDayOfWeek(), firstDayOfWeek, "Incorrect firstDayOfWeek");
    assertEquals(week.getMinimalDaysInFirstWeek(), minDays, "Incorrect MinimalDaysInFirstWeek");
    assertSame(WeekFields.of(firstDayOfWeek, minDays), week);
}
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