Premium Friday started on Friday, February 24th, 2017. The pros and cons of the system are fierce, but it's good to have more holidays anyway. Did you all leave the office at 3:00 pm on your first Premium Friday? __ I couldn't (´ ・ ω ・ `) __ I couldn't even leave the office on time (´ ・ ω ・ `)
So (?) I made a method to calculate Premium Friday. Please use it.
import java.util.Calendar;
public class PremiumFridayUtils {
/**
*Find the Premium Friday day of the specified month. For months without Premium Friday-Returns 1.
* @param year year(1..*)
* @param month month(1..12)
* @return Premium Friday day of the specified month(1..31)
*/
public static int getPremiumFriday(int year, int month) {
//year must be a positive number and month must be between 1 and 12 respectively.
if (year < 1 || month < 1 || month > 12) {
throw new IllegalArgumentException();
}
//Premium Friday will be held after February 2017.
if (year < 2017 || (year == 2017 && month == 1)) {
return -1;
}
//It is judged whether it is Friday one day from the last day of the target month, and the first day judged as Friday is
//Last Friday of the month=It will be Premium Friday.
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.FRIDAY) {
calendar.add(Calendar.DATE, -1);
}
return calendar.get(Calendar.DAY_OF_MONTH);
}
public static void main(String[] args) {
// 2017-Output for 2019 Premium Friday.
for (int year : new int[]{2017, 2018, 2019}) {
for (int month = 1; month <= 12; month++) {
int day = PremiumFridayUtils.getPremiumFriday(year, month);
if (day != -1) {
System.out.printf("%d-%02d-%02d\n", year, month, day);
}
}
}
}
}
/*
2017-02-24
2017-03-31
2017-04-28
2017-05-26
2017-06-30
2017-07-28
2017-08-25
2017-09-29
2017-10-27
2017-11-24
2017-12-29
2018-01-26
2018-02-23
2018-03-30
2018-04-27
2018-05-25
2018-06-29
2018-07-27
2018-08-31
2018-09-28
2018-10-26
2018-11-30
2018-12-28
2019-01-25
2019-02-22
2019-03-29
2019-04-26
2019-05-31
2019-06-28
2019-07-26
2019-08-30
2019-09-27
2019-10-25
2019-11-29
2019-12-27
*/
Recommended Posts