Last active
August 29, 2015 14:18
-
-
Save akaneko3/949efdd1737ffd4b41d2 to your computer and use it in GitHub Desktop.
指定した日が休日(土・日)かどうか Java Time API で調べる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.stream.IntStream; | |
import java.util.List; | |
import java.time.MonthDay; | |
import java.time.Year; | |
import java.time.DayOfWeek; | |
import java.time.LocalDate; | |
import static java.util.Arrays.asList; | |
import static java.time.Month.APRIL; | |
import static java.time.DayOfWeek.SATURDAY; | |
import static java.time.DayOfWeek.SUNDAY; | |
class AprilFool { | |
public static void main(String... args) { | |
// 指定日(エイプリルフール) | |
MonthDay aprilFool = MonthDay.of(APRIL, 1); | |
// 今年 | |
int thisYear = 2015; | |
// 土曜日と日曜日は休日の設定 | |
List<DayOfWeek> dayOff = asList(SATURDAY, SUNDAY); | |
// 今後 30 年間について調べる | |
IntStream.range(0, 30) | |
.mapToObj(i -> Year.of(thisYear + i)) | |
// 指定日が休日かどうか | |
.map(year -> year.atMonthDay(aprilFool)) | |
.filter(day -> dayOff.contains(day.getDayOfWeek())) | |
.map(LocalDate::getYear) | |
.forEach(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment