Lukasz Kalnik
11/13/2025, 2:17 PMLukasz Kalnik
11/13/2025, 2:18 PMLocalDate? Or is there a class for this in Kotlin stdlib?Lukasz Kalnik
11/13/2025, 2:34 PM// Nov 28th - Jan 6th (both inclusive and regardless of year)
val isXmasSeason = with(LocalDate.now()) {
(month == Month.NOVEMBER && dayOfMonth >= 28) ||
month == Month.DECEMBER ||
(month == Month.JANUARY && dayOfMonth <= 6)
}
I guess if it's regardless of year then there's no nicer way.bishiboosh
11/13/2025, 2:35 PMLukasz Kalnik
11/13/2025, 2:36 PMLukasz Kalnik
11/13/2025, 2:36 PMJavier
11/13/2025, 2:39 PMval isBetween = date in dateA..dateBStephan Schröder
11/13/2025, 2:55 PMJames Richardson
11/13/2025, 3:04 PMimport java.time.LocalDate
import java.time.MonthDay
fun LocalDate.between(a: MonthDay, b: MonthDay): Boolean {
val md = MonthDay.from(this)
if ( a < b ) {
return a <= md && md <= b
}
else {
return a <= md || b >= md
}
}
print(LocalDate.of(2025, 11, 14).between(MonthDay.of(11, 6), MonthDay.of(1, 9)))
print(LocalDate.of(2025, 12, 14).between(MonthDay.of(11, 6), MonthDay.of(1, 9)))
print(LocalDate.of(2025, 1, 4).between(MonthDay.of(11, 6), MonthDay.of(1, 9)))
print(LocalDate.of(2025, 1, 10).between(MonthDay.of(11, 6), MonthDay.of(1, 9)))
print(LocalDate.of(2025, 11,5).between(MonthDay.of(11, 6), MonthDay.of(1, 9)))James Richardson
11/13/2025, 3:07 PMStephan Schröder
11/13/2025, 3:07 PMJames Richardson
11/13/2025, 3:10 PMStephan Schröder
11/13/2025, 3:13 PMfun LocalDate.between(a: MonthDay, b: MonthDay): Boolean = MonthDay.from(this).let{ md ->
if ( a < b ) {
a <= md && md <= b
} else {
a <= md || b >= md
}
}
🤷♂️😅James Richardson
11/13/2025, 3:15 PMLukasz Kalnik
11/13/2025, 3:20 PMMonthDay in kotlinx.datetime, so probably will revert to Java, because at least here's a reusable, concise function.James Richardson
11/13/2025, 3:20 PMLukasz Kalnik
11/13/2025, 3:22 PMLukasz Kalnik
11/13/2025, 3:25 PMa <= md && md <= b with a range check md in a..b.James Richardson
11/13/2025, 3:28 PMLukasz Kalnik
11/13/2025, 3:28 PMMonthDay and with safeguards.Lukasz Kalnik
11/13/2025, 3:28 PMLukasz Kalnik
11/13/2025, 3:32 PMSince a MonthDay does not possess a year, the leap day of February 29th is considered valid
Paulo Cereda
11/13/2025, 3:32 PMdayOfYear, but that would only work if start month < end month. 😅James Richardson
11/13/2025, 4:00 PMJames Richardson
11/13/2025, 4:04 PMimport java.time.LocalDate
import java.time.MonthDay
fun LocalDate.between(a: MonthDay, b: MonthDay): Boolean =
MonthDay.from(this).let {
if (a < b) {
a <= it && it <= b
} else {
a <= it || b >= it
}
}
//fun LocalDate.between(a: MonthDay, b: MonthDay): Boolean = MonthDay.from(this).let {
// if (a <= b) {
// it in a..b
// } else {
// it in b..a
// }
//}
println("Expect true: " + LocalDate.of(2025, 11, 14).between(MonthDay.of(11, 6), MonthDay.of(1, 9)))
println("Expect true: " +LocalDate.of(2025, 12, 14).between(MonthDay.of(11, 6), MonthDay.of(1, 9)))
println("Expect true: " +LocalDate.of(2025, 1, 4).between(MonthDay.of(11, 6), MonthDay.of(1, 9)))
println("Expect false: " +LocalDate.of(2025, 1, 10).between(MonthDay.of(11, 6), MonthDay.of(1, 9)))
println("Expect false: " +LocalDate.of(2025, 11, 5).between(MonthDay.of(11, 6), MonthDay.of(1, 9)))James Richardson
11/13/2025, 4:05 PMLukasz Kalnik
11/13/2025, 4:44 PMelse case didn't implement wrapping (e.g. between December and January), but just assumed the input order was wrong. Thanks for catching the bug!