Skip to content

Commit 83fb96f

Browse files
committed
start of oktoberfest
1 parent 12c2193 commit 83fb96f

3 files changed

Lines changed: 82 additions & 1 deletion

File tree

‎src/main/kotlin/dartzee/theme/ThemeUtils.kt‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import dartzee.screen.ScreenCache
55
import dartzee.utils.InjectedThings
66
import dartzee.utils.ResourceCache
77
import java.awt.Font
8+
import java.time.DayOfWeek
89
import java.time.LocalDate
910
import java.time.Month
1011
import javax.swing.ImageIcon
@@ -16,21 +17,40 @@ fun autoApplyTheme() {
1617

1718
fun pickThemeForDate(now: LocalDate): Theme? {
1819
if (DartsClient.devMode) {
19-
return Themes.EASTER
20+
return Themes.OKTOBERFEST
2021
}
2122

2223
val easterSunday = findEasterSunday(now.year)
2324
if (now.isBefore(easterSunday.plusDays(1)) && now.isAfter(easterSunday.minusDays(9))) {
2425
return Themes.EASTER
2526
}
2627

28+
val (oktoberfestStart, oktoberfestEnd) = findOktoberfest(now.year)
29+
if (now.isBefore(oktoberfestEnd.plusDays(1)) && now.isAfter(oktoberfestStart.minusDays(1))) {
30+
return Themes.OKTOBERFEST
31+
}
32+
2733
if (now.month == Month.OCTOBER && now.dayOfMonth >= 24) {
2834
return Themes.HALLOWEEN
2935
}
3036

3137
return null
3238
}
3339

40+
fun findOktoberfest(year: Int): Pair<LocalDate, LocalDate> {
41+
val germanUnityDay = LocalDate.of(year, Month.OCTOBER, 3)
42+
val firstSunday =
43+
(1..7)
44+
.map { LocalDate.of(year, Month.OCTOBER, it) }
45+
.first { it.getDayOfWeek() == DayOfWeek.SUNDAY }
46+
47+
val endDate = if (firstSunday.isBefore(germanUnityDay)) germanUnityDay else firstSunday
48+
val daysAdded = maxOf(0, germanUnityDay.dayOfMonth - firstSunday.dayOfMonth)
49+
50+
val startDate = endDate.minusDays(15L + daysAdded)
51+
return startDate to endDate
52+
}
53+
3454
/** https://en.wikipedia.org/wiki/Date_of_Easter#Gauss's_Easter_algorithm */
3555
@Suppress("VariableNaming")
3656
fun findEasterSunday(year: Int): LocalDate {

‎src/main/kotlin/dartzee/theme/Themes.kt‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ private val easterDartboardColours =
3434
pastelGreen.darker(),
3535
)
3636

37+
private val oktoberfestDartboardColours =
38+
ColourWrapper(
39+
Color.YELLOW,
40+
Color.RED,
41+
Color.RED,
42+
Color.RED,
43+
Color.YELLOW,
44+
Color.YELLOW,
45+
Color.RED,
46+
Color.YELLOW,
47+
)
48+
3749
object Themes {
3850
val HALLOWEEN =
3951
Theme(
@@ -58,4 +70,16 @@ object Themes {
5870
fontColor = Color.DARK_GRAY,
5971
dartboardColours = easterDartboardColours,
6072
)
73+
74+
val OKTOBERFEST =
75+
Theme(
76+
"oktoberfest",
77+
Color.decode("#c1f0fb"),
78+
Color.decode("#8aadd3"),
79+
Color.decode("#e0cdff"),
80+
Color.decode("#f9ceee"),
81+
linkColour = Color.BLUE,
82+
fontColor = Color.DARK_GRAY,
83+
dartboardColours = oktoberfestDartboardColours,
84+
)
6185
}

‎src/test/kotlin/dartzee/theme/ThemeUtilsTest.kt‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,28 @@ class ThemeUtilsTest : AbstractTest() {
6767
pickThemeForDate(LocalDate.of(2026, Month.APRIL, 6)) shouldBe null
6868
}
6969

70+
@Test
71+
fun `Should pick oktoberfest for the relevant dates`() {
72+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 18)) shouldBe null
73+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 19)) shouldBe Themes.OKTOBERFEST
74+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 20)) shouldBe Themes.OKTOBERFEST
75+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 21)) shouldBe Themes.OKTOBERFEST
76+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 22)) shouldBe Themes.OKTOBERFEST
77+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 23)) shouldBe Themes.OKTOBERFEST
78+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 24)) shouldBe Themes.OKTOBERFEST
79+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 25)) shouldBe Themes.OKTOBERFEST
80+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 26)) shouldBe Themes.OKTOBERFEST
81+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 27)) shouldBe Themes.OKTOBERFEST
82+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 28)) shouldBe Themes.OKTOBERFEST
83+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 29)) shouldBe Themes.OKTOBERFEST
84+
pickThemeForDate(LocalDate.of(2026, Month.SEPTEMBER, 30)) shouldBe Themes.OKTOBERFEST
85+
pickThemeForDate(LocalDate.of(2026, Month.OCTOBER, 1)) shouldBe Themes.OKTOBERFEST
86+
pickThemeForDate(LocalDate.of(2026, Month.OCTOBER, 2)) shouldBe Themes.OKTOBERFEST
87+
pickThemeForDate(LocalDate.of(2026, Month.OCTOBER, 3)) shouldBe Themes.OKTOBERFEST
88+
pickThemeForDate(LocalDate.of(2026, Month.OCTOBER, 4)) shouldBe Themes.OKTOBERFEST
89+
pickThemeForDate(LocalDate.of(2026, Month.OCTOBER, 5)) shouldBe null
90+
}
91+
7092
@Test
7193
fun `Should find the right date for easter sunday`() {
7294
findEasterSunday(2027) shouldBe LocalDate.of(2027, Month.MARCH, 28)
@@ -75,4 +97,19 @@ class ThemeUtilsTest : AbstractTest() {
7597
findEasterSunday(2024) shouldBe LocalDate.of(2024, Month.MARCH, 31)
7698
findEasterSunday(2023) shouldBe LocalDate.of(2023, Month.APRIL, 9)
7799
}
100+
101+
@Test
102+
fun `Should find the right dates for Oktoberfest`() {
103+
findOktoberfest(2026) shouldBe
104+
(LocalDate.of(2026, Month.SEPTEMBER, 19) to LocalDate.of(2026, Month.OCTOBER, 4))
105+
106+
findOktoberfest(2025) shouldBe
107+
(LocalDate.of(2025, Month.SEPTEMBER, 20) to LocalDate.of(2025, Month.OCTOBER, 5))
108+
109+
findOktoberfest(2024) shouldBe
110+
(LocalDate.of(2024, Month.SEPTEMBER, 21) to LocalDate.of(2024, Month.OCTOBER, 6))
111+
112+
findOktoberfest(2023) shouldBe
113+
(LocalDate.of(2023, Month.SEPTEMBER, 16) to LocalDate.of(2023, Month.OCTOBER, 3))
114+
}
78115
}

0 commit comments

Comments
 (0)