use of java.time.temporal.WeekFields 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.WeekFields 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.WeekFields in project jdk8u_jdk by JetBrains.
the class TCKLocalizedFieldParser method test_parse_WeekBasedYear.
@Test(dataProvider = "LocalWeekBasedYearPatterns")
public void test_parse_WeekBasedYear(String pattern, String text, int pos, int expectedPos, LocalDate expectedValue) {
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 {
WeekFields weekDef = WeekFields.of(locale);
assertEquals(ppos.getIndex(), expectedPos, "Incorrect ending parse position");
assertEquals(parsed.isSupported(weekDef.dayOfWeek()), pattern.indexOf('e') >= 0);
assertEquals(parsed.isSupported(weekDef.weekOfWeekBasedYear()), pattern.indexOf('w') >= 0);
assertEquals(parsed.isSupported(weekDef.weekBasedYear()), pattern.indexOf('Y') >= 0);
// ensure combination resolves into a date
LocalDate result = LocalDate.parse(text, dtf);
assertEquals(result, expectedValue, "LocalDate incorrect for " + pattern + ", weekDef: " + weekDef);
}
}
use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.
the class TCKLocalizedFieldParser method test_parse_textField.
@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);
}
}
use of java.time.temporal.WeekFields in project jdk8u_jdk by JetBrains.
the class TCKWeekFieldsSerialization method test_serializable_singleton.
//-----------------------------------------------------------------------
@Test(dataProvider = "weekFields")
public void test_serializable_singleton(DayOfWeek firstDayOfWeek, int minDays) throws IOException, ClassNotFoundException {
WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
// spec state singleton
assertSerializableSame(weekDef);
}
Aggregations