use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_dayOfWeekField.
@Test(dataProvider = "weekFields")
public void test_dayOfWeekField(DayOfWeek firstDayOfWeek, int minDays) {
// Known to be ISO Monday
LocalDate day = LocalDate.of(2000, 1, 10);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField f = week.dayOfWeek();
for (int i = 1; i <= 7; i++) {
assertEquals(day.get(f), (7 + day.getDayOfWeek().getValue() - firstDayOfWeek.getValue()) % 7 + 1);
day = day.plusDays(1);
}
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_parse_resolve_localizedWoWBYDow_lenient.
@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);
}
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKHijrahChronology method test_resolve_yearOfEra_yearOfEraOnly_valid.
@Test(dataProvider = "resolve_styles")
public void test_resolve_yearOfEra_yearOfEraOnly_valid(ResolverStyle style) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR_OF_ERA, 1343L);
HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
assertEquals(date, null);
assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (style != ResolverStyle.STRICT) ? null : (Long) 1343L);
assertEquals(fieldValues.get(ChronoField.YEAR), (style == ResolverStyle.STRICT) ? null : (Long) 1343L);
assertEquals(fieldValues.size(), 1);
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKChronoLocalDateTime method test_badTemporalFieldChrono.
@Test(dataProvider = "calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
LocalDate refDate = LocalDate.of(2013, 1, 1);
ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
for (Chronology[] clist : data_of_calendars()) {
Chronology chrono2 = clist[0];
ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
TemporalField adjuster = new FixedTemporalField(cdt2);
if (chrono != chrono2) {
try {
cdt.with(adjuster, 1);
Assert.fail("TemporalField doWith() should have thrown a ClassCastException" + cdt.getClass() + ", can not be cast to " + cdt2.getClass());
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDateTime<?> result = cdt.with(adjuster, 1);
assertEquals(result, cdt2, "TemporalField doWith() failed to replace date");
}
}
}
use of java.time.temporal.TemporalField in project jdk8u_jdk by JetBrains.
the class TCKMinguoChronology method test_resolve_yd_strict.
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_strict(int y, int d, MinguoDate expected, boolean smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
if (strict) {
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
Aggregations