本文整理汇总了Java中java.time.temporal.WeekFields.of方法的典型用法代码示例。如果您正苦于以下问题:Java WeekFields.of方法的具体用法?Java WeekFields.of怎么用?Java WeekFields.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.temporal.WeekFields
的用法示例。
在下文中一共展示了WeekFields.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_parse_resolve_localizedWoWBY
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@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);
}
}
示例2: test_parse_WeekBasedYear
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@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);
}
}
示例3: test_parse_resolve_localizedWoy_strict
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@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
}
}
示例4: test_parse_resolve_localizedWoWBYDow_lenient
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@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);
}
}
示例5: test_parse_resolve_localizedWoyDow
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@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);
}
}
示例6: test_parse_resolve_localizedWom
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWom(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
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(DAY_OF_WEEK).toFormatter().withResolverStyle(SMART);
String str = date.getYear() + ":" + date.getMonthValue() + ":" +
date.get(womField) + ":" + date.get(DAY_OF_WEEK);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " ::" + str + "::" + i);
date = date.plusDays(1);
}
}
示例7: test_parse_resolve_localizedWoWBY_lenient
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBY_lenient(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().withResolverStyle(LENIENT);
int wowby = date.get(wowbyField);
int dow = date.get(DAY_OF_WEEK);
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);
}
}
示例8: test_withDayOfWeek
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_withDayOfWeek(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate day = LocalDate.of(2012, 12, 15); // Safely in the middle of a month
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField womField = week.weekOfMonth();
TemporalField woyField = week.weekOfYear();
int wom = day.get(womField);
int woy = day.get(woyField);
for (int dow = 1; dow <= 7; dow++) {
LocalDate result = day.with(dowField, dow);
assertEquals(result.get(dowField), dow, String.format("Incorrect new Day of week: %s", result));
assertEquals(result.get(womField), wom, "Week of Month should not change");
assertEquals(result.get(woyField), woy, "Week of Year should not change");
}
}
示例9: test_basics
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@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);
}
示例10: test_weekOfYearField
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@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);
}
}
示例11: test_of_DayOfWeek_int_singleton
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@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);
}
示例12: test_dayOfWeekField
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_dayOfWeekField(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate day = LocalDate.of(2000, 1, 10); // Known to be ISO Monday
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);
}
}
示例13: test_parse_textField
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@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);
}
}
示例14: provider_WeekBasedYearData
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@DataProvider(name="WeekBasedYearData")
Object[][] provider_WeekBasedYearData() {
return new Object[][] {
{WeekFields.of(DayOfWeek.SUNDAY, 1), 2008, 52, 7, LocalDate.of(2008, 12, 27)},
{WeekFields.of(DayOfWeek.SUNDAY, 1), 2009, 1, 1, LocalDate.of(2008, 12, 28)},
{WeekFields.of(DayOfWeek.SUNDAY, 1), 2009, 1, 2, LocalDate.of(2008, 12, 29)},
{WeekFields.of(DayOfWeek.SUNDAY, 1), 2009, 1, 3, LocalDate.of(2008, 12, 30)},
{WeekFields.of(DayOfWeek.SUNDAY, 1), 2009, 1, 4, LocalDate.of(2008, 12, 31)},
{WeekFields.of(DayOfWeek.SUNDAY, 1), 2009, 1, 5, LocalDate.of(2009, 1, 1)},
{WeekFields.of(DayOfWeek.SUNDAY, 1), 2009, 2, 1, LocalDate.of(2009, 1, 4)},
{WeekFields.of(DayOfWeek.SUNDAY, 1), 2009, 2, 2, LocalDate.of(2009, 1, 5)},
{WeekFields.of(DayOfWeek.SUNDAY, 1), 2009, 2, 3, LocalDate.of(2009, 1, 6)},
};
}
示例15: test_withWeekOfWeekBasedYear
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="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(dowResult, dowExpected, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);
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(weekResult, weekExpected, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);
int yearExpected = day.get(yowbyField) + 1;
LocalDate yearDate = day.with(yowbyField, yearExpected);
int yearResult = yearDate.get(yowbyField);
assertEquals(yearResult, yearExpected, "Localized WeekBasedYear not correct; " + day + " --> " + yearDate);
range = yearDate.range(wowbyField);
weekExpected = Math.min(day.get(wowbyField), (int)range.getMaximum());
int weekActual = yearDate.get(wowbyField);
assertEquals(weekActual, weekExpected, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
}