-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
毎年日付が変わる祝日の実績の日付が実際の日付とずれるのを修正
- Loading branch information
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
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
26 changes: 26 additions & 0 deletions
26
src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.unchama.seichiassist.achievement | ||
|
||
import java.time.{LocalDate, Month} | ||
|
||
import enumeratum._ | ||
|
||
import scala.math.floor | ||
|
||
/** | ||
* 年によって日付が変わってしまうので、各年ごとに計算が必要な日の列挙 | ||
*/ | ||
sealed abstract class NamedHoliday(val name: String) extends EnumEntry { | ||
def dateOn(year: Int): LocalDate | ||
} | ||
|
||
case object NamedHoliday extends Enum[NamedHoliday] { | ||
val values: IndexedSeq[NamedHoliday] = findValues | ||
|
||
case object SpringEquinoxDay extends NamedHoliday("春分の日") { | ||
override def dateOn(year: Int): LocalDate = { | ||
val dayOfMonth = floor(20.8431 + 0.242194 * (year - 1980) - (year - 1980) / 4).toInt | ||
|
||
LocalDate.of(year, Month.MARCH, dayOfMonth) | ||
} | ||
} | ||
} |
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