本文整理汇总了Java中java.time.temporal.WeekFields类的典型用法代码示例。如果您正苦于以下问题:Java WeekFields类的具体用法?Java WeekFields怎么用?Java WeekFields使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WeekFields类属于java.time.temporal包,在下文中一共展示了WeekFields类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WeekFieldsViewSkin
import java.time.temporal.WeekFields; //导入依赖的package包/类
public WeekFieldsViewSkin(final WeekFieldsView view) {
super(view);
dayOfWeekComboBox = new ComboBox<>();
dayOfWeekComboBox.getItems().addAll(DayOfWeek.values());
dayOfWeekComboBox.setValue(view.getFirstDayOfWeek());
minimalDaysInFirstWeekComboBox = new ComboBox<>();
minimalDaysInFirstWeekComboBox.getItems().addAll(1, 2, 3, 4, 5, 6, 7);
minimalDaysInFirstWeekComboBox.setValue(view.getMinimalDaysInFirstWeek());
GridPane pane = new GridPane();
pane.getStyleClass().add("content");
pane.add(new Label("First day:"), 0, 0);
pane.add(new Label("Minimum days:"), 0, 1);
pane.add(dayOfWeekComboBox, 1, 0);
pane.add(minimalDaysInFirstWeekComboBox, 1, 1);
getChildren().add(pane);
// listeners
InvalidationListener updateListener = it -> updateValues();
dayOfWeekComboBox.valueProperty().addListener(updateListener);
minimalDaysInFirstWeekComboBox.valueProperty().addListener(updateListener);
view.weekFieldsProperty().addListener(it -> {
WeekFields fields = view.getWeekFields();
dayOfWeekComboBox.setValue(fields.getFirstDayOfWeek());
minimalDaysInFirstWeekComboBox.setValue(fields.getMinimalDaysInFirstWeek());
});
}
示例2: 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);
}
示例3: 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");
}
}
示例4: 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);
}
}
示例5: test_parse_resolve_localizedWom_lenient
import java.time.temporal.WeekFields; //导入依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWom_lenient(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(LENIENT);
int wom = date.get(womField);
int dow = date.get(DAY_OF_WEEK);
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);
}
}
示例6: test_parse_resolve_localizedWom_strict
import java.time.temporal.WeekFields; //导入依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWom_strict(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField womField = week.weekOfMonth();
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(MONTH_OF_YEAR).appendLiteral(':')
.appendValue(womField).appendLiteral(':')
.appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(STRICT);
String str = "2012:1:0:1";
try {
LocalDate date = LocalDate.parse(str, f);
assertEquals(date.getYear(), 2012);
assertEquals(date.getMonthValue(), 1);
assertEquals(date.get(womField), 0);
assertEquals(date.get(DAY_OF_WEEK), 1);
} catch (DateTimeException ex) {
// expected
}
}
示例7: 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);
}
}
示例8: 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);
}
}
示例9: 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
}
}
示例10: 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);
}
}
示例11: 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);
}
}
示例12: 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);
}
}
示例13: 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);
}
}
示例14: test_parse_resolve_localizedWoWBY_strict
import java.time.temporal.WeekFields; //导入依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBY_strict(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField wowbyField = week.weekOfWeekBasedYear();
TemporalField yowbyField = week.weekBasedYear();
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(yowbyField).appendLiteral(':')
.appendValue(wowbyField).appendLiteral(':')
.appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(STRICT);
String str = "2012:0:1";
try {
LocalDate date = LocalDate.parse(str, f);
assertEquals(date.get(yowbyField), 2012);
assertEquals(date.get(wowbyField), 0);
assertEquals(date.get(DAY_OF_WEEK), 1);
} catch (DateTimeException ex) {
// expected
}
}
示例15: 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);
}
}