本文整理汇总了Java中java.time.temporal.WeekFields.dayOfWeek方法的典型用法代码示例。如果您正苦于以下问题:Java WeekFields.dayOfWeek方法的具体用法?Java WeekFields.dayOfWeek怎么用?Java WeekFields.dayOfWeek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.temporal.WeekFields
的用法示例。
在下文中一共展示了WeekFields.dayOfWeek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_rangeWeekOfWeekBasedYear
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_rangeWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields weekFields = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = weekFields.dayOfWeek();
TemporalField wowByField = weekFields.weekOfWeekBasedYear();
LocalDate day1 = LocalDate.of(2012, 1, weekFields.getMinimalDaysInFirstWeek());
day1 = day1.with(wowByField, 1).with(dowField, 1);
LocalDate day2 = LocalDate.of(2013, 1, weekFields.getMinimalDaysInFirstWeek());
day2 = day2.with(wowByField, 1).with(dowField, 1);
int expectedWeeks = (int)ChronoUnit.DAYS.between(day1, day2) / 7;
ValueRange range = day1.range(wowByField);
assertEquals(range.getMaximum(), expectedWeeks, "Range incorrect");
}
示例2: 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");
}
}
示例3: test_parse_resolve_localizedWomDow_lenient
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@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);
}
}
示例4: test_parse_resolve_localizedWoyDow_lenient
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoyDow_lenient(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(woyField).appendLiteral(':')
.appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
int woy = date.get(woyField);
int dow = date.get(dowField);
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);
}
}
示例5: 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);
}
}
示例6: test_parse_resolve_localizedWomDow
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWomDow(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 <= 15; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(MONTH_OF_YEAR).appendLiteral(':')
.appendValue(womField).appendLiteral(':')
.appendValue(dowField).toFormatter();
String str = date.getYear() + ":" + date.getMonthValue() + ":" +
date.get(womField) + ":" + date.get(dowField);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
date = date.plusDays(1);
}
}
示例7: 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);
}
}
示例8: test_parse_resolve_localizedWoWBYDow
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBYDow(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();
String str = date.get(yowbyField) + ":" + date.get(wowbyField) + ":" +
date.get(dowField);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
date = date.plusDays(1);
}
}
示例9: printerParser
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
/**
* 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);
}
示例10: test_weekOfWeekBasedYearField
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
/**
* Verify that the date can be reconstructed from the DOW, WeekOfWeekBasedYear,
* and WeekBasedYear for every combination of start of week
* and minimal days in week.
* @param firstDayOfWeek the first day of the week
* @param minDays the minimum number of days in the week
*/
@Test(dataProvider="weekFields")
public void test_weekOfWeekBasedYearField(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate day = LocalDate.of(2012, 12, 31); // Known to be ISO Monday
WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = weekDef.dayOfWeek();
TemporalField wowbyField = weekDef.weekOfWeekBasedYear();
TemporalField yowbyField = weekDef.weekBasedYear();
for (int i = 1; i <= 15; i++) {
int actualDOW = day.get(dowField);
int actualWOWBY = day.get(wowbyField);
int actualYOWBY = day.get(yowbyField);
// Verify that the combination of day of week and week of month can be used
// to reconstruct the same date.
LocalDate day1 = LocalDate.of(actualYOWBY, 1, 1);
DayOfWeek isoDOW = day1.getDayOfWeek();
int dow = (7 + isoDOW.getValue() - firstDayOfWeek.getValue()) % 7 + 1;
int weekStart = Math.floorMod(1 - dow, 7);
if (weekStart + 1 > weekDef.getMinimalDaysInFirstWeek()) {
// The previous week has the minimum days in the current month to be a 'week'
weekStart -= 7;
}
weekStart += actualDOW - 1;
weekStart += (actualWOWBY - 1) * 7;
LocalDate result = day1.plusDays(weekStart);
assertEquals(result, day, "Incorrect dayOfWeek or weekOfYear "
+ String.format("%s, ISO Dow: %s, weekStart: %s, actualDOW: %s, actualWOWBY: %s, YearOfWBY: %d, expected day: %s, result: %s%n",
weekDef, day.getDayOfWeek(), weekStart, actualDOW, actualWOWBY, actualYOWBY, day, result));
day = day.plusDays(1);
}
}
示例11: test_weekBasedYears
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@Test(dataProvider="WeekBasedYearData")
public void test_weekBasedYears(WeekFields weekDef, int weekBasedYear,
int weekOfWeekBasedYear, int dayOfWeek, LocalDate date) {
TemporalField dowField = weekDef.dayOfWeek();
TemporalField wowbyField = weekDef.weekOfWeekBasedYear();
TemporalField yowbyField = weekDef.weekBasedYear();
assertEquals(date.get(dowField), dayOfWeek, "DayOfWeek mismatch");
assertEquals(date.get(wowbyField), weekOfWeekBasedYear, "Week of WeekBasedYear mismatch");
assertEquals(date.get(yowbyField), weekBasedYear, "Year of WeekBasedYear mismatch");
}
示例12: 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 'c' :
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);
}
}
示例13: test_weekOfMonthField
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@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);
}
}
示例14: test_WOWBY
import java.time.temporal.WeekFields; //导入方法依赖的package包/类
@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);
}
示例15: 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);
}
}