本文整理汇总了Java中java.time.DayOfWeek类的典型用法代码示例。如果您正苦于以下问题:Java DayOfWeek类的具体用法?Java DayOfWeek怎么用?Java DayOfWeek使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DayOfWeek类属于java.time包,在下文中一共展示了DayOfWeek类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canAccept
import java.time.DayOfWeek; //导入依赖的package包/类
@Override
public boolean canAccept(final Class<?> type) {
return LocalDateTime.class.equals(type)
|| OffsetDateTime.class.equals(type)
|| ZonedDateTime.class.equals(type)
|| LocalDate.class.equals(type)
|| LocalTime.class.equals(type)
|| OffsetTime.class.equals(type)
|| Year.class.equals(type)
|| YearMonth.class.equals(type)
|| MonthDay.class.equals(type)
|| Month.class.equals(type)
|| DayOfWeek.class.equals(type)
|| checkEra(type)
|| checkChronoLocalDate(type);
}
示例2: WeekFieldsViewSkin
import java.time.DayOfWeek; //导入依赖的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());
});
}
示例3: test_next
import java.time.DayOfWeek; //导入依赖的package包/类
@Test
public void test_next() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjusters.next(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow, date + " " + test);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff > 0 && dayDiff < 8);
} else {
assertSame(month, Month.DECEMBER);
assertTrue(date.getDayOfMonth() > 24);
assertEquals(test.getYear(), 2008);
assertSame(test.getMonth(), Month.JANUARY);
assertTrue(test.getDayOfMonth() < 8);
}
}
}
}
}
示例4: test_parse_resolve_localizedWomDow_lenient
import java.time.DayOfWeek; //导入依赖的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);
}
}
示例5: test_parse_resolve_localizedWomDow
import java.time.DayOfWeek; //导入依赖的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);
}
}
示例6: ZoneOffsetTransitionRule
import java.time.DayOfWeek; //导入依赖的package包/类
/**
* Creates an instance defining the yearly rule to create transitions between two offsets.
*
* @param month the month of the month-day of the first day of the cutover week, not null
* @param dayOfMonthIndicator the day of the month-day of the cutover week, positive if the week is that
* day or later, negative if the week is that day or earlier, counting from the last day of the month,
* from -28 to 31 excluding 0
* @param dayOfWeek the required day-of-week, null if the month-day should not be changed
* @param time the cutover time in the 'before' offset, not null
* @param timeEndOfDay whether the time is midnight at the end of day
* @param timeDefnition how to interpret the cutover
* @param standardOffset the standard offset in force at the cutover, not null
* @param offsetBefore the offset before the cutover, not null
* @param offsetAfter the offset after the cutover, not null
* @throws IllegalArgumentException if the day of month indicator is invalid
* @throws IllegalArgumentException if the end of day flag is true when the time is not midnight
*/
ZoneOffsetTransitionRule(
Month month,
int dayOfMonthIndicator,
DayOfWeek dayOfWeek,
LocalTime time,
boolean timeEndOfDay,
TimeDefinition timeDefnition,
ZoneOffset standardOffset,
ZoneOffset offsetBefore,
ZoneOffset offsetAfter) {
this.month = month;
this.dom = (byte) dayOfMonthIndicator;
this.dow = dayOfWeek;
this.time = time;
this.timeEndOfDay = timeEndOfDay;
this.timeDefinition = timeDefnition;
this.standardOffset = standardOffset;
this.offsetBefore = offsetBefore;
this.offsetAfter = offsetAfter;
}
示例7: getProfNotifications
import java.time.DayOfWeek; //导入依赖的package包/类
@GetMapping(value = "/prof/noti")
public String getProfNotifications(Model model) {
try {
LocalDate currDate = LocalDate.now();
if (currDate.getDayOfWeek().equals(DayOfWeek.SATURDAY)
|| currDate.getDayOfWeek().equals(DayOfWeek.SUNDAY))
currDate = currDate.plus(3, ChronoUnit.DAYS);
LocalDate startDateOfSchoolWeek = currDate.with(DayOfWeek.MONDAY);
String profEmail = authFacade.getAuthentication().getName();
Professor prof = professorService.getProfessorByEmail(profEmail);
List<BookingSlot> profBookings
= bookingSlotService.getSlotsByProfAndSWeek(prof.getAlias(), startDateOfSchoolWeek);
model.addAttribute("bookings", filterBookingSlots(profBookings));
return "fragments/prof_noti";
} catch (Exception ex) {
ex.printStackTrace();
model.addAttribute("message", ex.toString());
return "error";
}
}
示例8: test_toString_floatingWeekBackwards_last
import java.time.DayOfWeek; //导入依赖的package包/类
@Test
public void test_toString_floatingWeekBackwards_last() {
ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(
Month.MARCH, -1, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL,
OFFSET_0200, OFFSET_0200, OFFSET_0300);
assertEquals(test.toString(), "TransitionRule[Gap +02:00 to +03:00, SUNDAY on or before last day of MARCH at 01:00 WALL, standard offset +02:00]");
}
示例9: chronoDescriptorTest4
import java.time.DayOfWeek; //导入依赖的package包/类
@Test
public void chronoDescriptorTest4() {
ChronoSeries chronoSeries = testChronoSeries();
ISeq<ChronoAllele> alleleSeq = ISeq.of(
new ChronoFrequency(ChronoUnit.YEARS, 0, 1, 1, Instant.now()),
new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.HOURS), 0, 8),
new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.HOURS), 0, 9),
new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.HOURS), 0, 10),
new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.DAYS), 0, DayOfWeek.FRIDAY.getValue()),
new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.WEEKS), 0, 1),
new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.MONTHS), 0, Month.NOVEMBER.getValue()),
new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.YEARS), 0, 2011),
new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.YEARS), 0, 2012),
new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.YEARS), 0, 2013),
new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.YEARS), 0, 2014),
new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.YEARS), 0, 2015)
);
ISeq<ChronoGene> geneSeq = ISeq.of(alleleSeq.map(ChronoGene::new));
Chronosome chronosome = new Chronosome(geneSeq, chronoSeries);
Chronotype chronotype = new Chronotype(chronoSeries, ISeq.of(Collections.singleton(chronosome)));
String description = ChronoDescriptor.describe(chronotype).humanReadable();
assertEquals("Expected equals",
"Once a year from 2011 to 2015 on the first Friday of November between 8AM - 10AM", description);
}
示例10: ZoneOffsetTransitionRule
import java.time.DayOfWeek; //导入依赖的package包/类
/**
* Creates an instance defining the yearly rule to create transitions between two offsets.
*
* @param month the month of the month-day of the first day of the cutover week, not null
* @param dayOfMonthIndicator the day of the month-day of the cutover week, positive if the week is that
* day or later, negative if the week is that day or earlier, counting from the last day of the month,
* from -28 to 31 excluding 0
* @param dayOfWeek the required day-of-week, null if the month-day should not be changed
* @param time the cutover time in the 'before' offset, not null
* @param timeEndOfDay whether the time is midnight at the end of day
* @param timeDefnition how to interpret the cutover
* @param standardOffset the standard offset in force at the cutover, not null
* @param offsetBefore the offset before the cutover, not null
* @param offsetAfter the offset after the cutover, not null
* @throws IllegalArgumentException if the day of month indicator is invalid
* @throws IllegalArgumentException if the end of day flag is true when the time is not midnight
*/
ZoneOffsetTransitionRule(
Month month,
int dayOfMonthIndicator,
DayOfWeek dayOfWeek,
LocalTime time,
boolean timeEndOfDay,
TimeDefinition timeDefnition,
ZoneOffset standardOffset,
ZoneOffset offsetBefore,
ZoneOffset offsetAfter) {
assert time.getNano() == 0;
this.month = month;
this.dom = (byte) dayOfMonthIndicator;
this.dow = dayOfWeek;
this.time = time;
this.timeEndOfDay = timeEndOfDay;
this.timeDefinition = timeDefnition;
this.standardOffset = standardOffset;
this.offsetBefore = offsetBefore;
this.offsetAfter = offsetAfter;
}
示例11: test_parse_resolve_localizedWom
import java.time.DayOfWeek; //导入依赖的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);
}
}
示例12: test_London_getTransitionRules
import java.time.DayOfWeek; //导入依赖的package包/类
public void test_London_getTransitionRules() {
ZoneRules test = europeLondon();
List<ZoneOffsetTransitionRule> rules = test.getTransitionRules();
assertEquals(rules.size(), 2);
ZoneOffsetTransitionRule in = rules.get(0);
assertEquals(in.getMonth(), Month.MARCH);
assertEquals(in.getDayOfMonthIndicator(), 25); // optimized from -1
assertEquals(in.getDayOfWeek(), DayOfWeek.SUNDAY);
assertEquals(in.getLocalTime(), LocalTime.of(1, 0));
assertEquals(in.getTimeDefinition(), TimeDefinition.UTC);
assertEquals(in.getStandardOffset(), OFFSET_ZERO);
assertEquals(in.getOffsetBefore(), OFFSET_ZERO);
assertEquals(in.getOffsetAfter(), OFFSET_PONE);
ZoneOffsetTransitionRule out = rules.get(1);
assertEquals(out.getMonth(), Month.OCTOBER);
assertEquals(out.getDayOfMonthIndicator(), 25); // optimized from -1
assertEquals(out.getDayOfWeek(), DayOfWeek.SUNDAY);
assertEquals(out.getLocalTime(), LocalTime.of(1, 0));
assertEquals(out.getTimeDefinition(), TimeDefinition.UTC);
assertEquals(out.getStandardOffset(), OFFSET_ZERO);
assertEquals(out.getOffsetBefore(), OFFSET_PONE);
assertEquals(out.getOffsetAfter(), OFFSET_ZERO);
}
示例13: test_parse_resolve_localizedWoy
import java.time.DayOfWeek; //导入依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoy(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField woyField = week.weekOfYear();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(woyField).appendLiteral(':')
.appendValue(DAY_OF_WEEK).toFormatter();
String str = date.getYear() + ":" +
date.get(woyField) + ":" + date.get(DAY_OF_WEEK);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " :: " + str + " " + i);
date = date.plusDays(1);
}
}
示例14: test_parse_resolve_localizedWoyDow
import java.time.DayOfWeek; //导入依赖的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);
}
}
示例15: test_previous
import java.time.DayOfWeek; //导入依赖的package包/类
@Test
public void test_previous() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjusters.previous(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow, date + " " + test);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff < 0 && dayDiff > -8, dayDiff + " " + test);
} else {
assertSame(month, Month.JANUARY);
assertTrue(date.getDayOfMonth() < 8);
assertEquals(test.getYear(), 2006);
assertSame(test.getMonth(), Month.DECEMBER);
assertTrue(test.getDayOfMonth() > 24);
}
}
}
}
}