Skip to content

Commit

Permalink
Program.Annual(mon, day)
Browse files Browse the repository at this point in the history
  • Loading branch information
JG1VPP committed Oct 19, 2024
1 parent af9c910 commit 47c233f
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/main/java/qxsl/ruler/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import java.time.LocalDate;
import java.time.Year;
import java.time.ZoneId;

import static java.time.temporal.TemporalAdjusters.dayOfWeekInMonth;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

/**
* コンテストの日程はこのクラスを継承します。
Expand Down Expand Up @@ -212,17 +212,32 @@ public boolean finish(ZoneId zone) {
public abstract boolean conflict(Section[] entries);

/**
* 特定の月の特定の曜日に開催されるコンテストです
* 特定の月の特定の日に開催されるコンテストです
*
*
* @author 無線部開発班
*
* @since 2023/01/21
*/
public static abstract class Annual extends Program {
private final TemporalAdjuster adj;
private final int mon;
private final int nth;
private final DayOfWeek day;

/**
* 開催日時を指定します。
*
*
* @param mon 月
* @param day 日
*
* @since 2024/10/19
*/
public Annual(int mon, int day) {
this.adj = null;
this.mon = mon;
this.nth = day;
}

/**
* 開催日時を指定します。
Expand All @@ -231,11 +246,13 @@ public static abstract class Annual extends Program {
* @param mon 月
* @param nth 週
* @param day 曜
*
* @since 2023/01/21
*/
public Annual(int mon, int nth, DayOfWeek day) {
this.adj = TemporalAdjusters.dayOfWeekInMonth(nth, day);
this.mon = mon;
this.nth = nth;
this.day = day;
}

/**
Expand All @@ -248,8 +265,8 @@ public Annual(int mon, int nth, DayOfWeek day) {
*/
@Override
public final LocalDate getStartDay(int year) {
final var date = LocalDate.of(year, mon, 1);
return date.with(dayOfWeekInMonth(nth, day));
final var date = LocalDate.of(year, mon, nth);
return adj == null? date: date.with(this.adj);
}
}
}

0 comments on commit 47c233f

Please sign in to comment.