nextOrSame

Returns a LocalDate that has the given dayOfWeek not earlier than this date.

If the dayOfWeek is already the one this date has, the date will be returned unchanged. See next for a version that always returns a different date later than the provided one.

See also

for a symmetrical operation that searches the given dayOfWeek in the past.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val today = LocalDate(2026, 2, 14)
check(today.dayOfWeek == DayOfWeek.SATURDAY)
// Find the end of the Monday-based week that contains the given date.
val endOfCurrentMondayBasedWeek = today.nextOrSame(DayOfWeek.SUNDAY)
check(endOfCurrentMondayBasedWeek == LocalDate(2026, 2, 15))
// Find the end of the Sunday-based week that contains the given date.
val endOfCurrentSundayBasedWeek = today.nextOrSame(DayOfWeek.SATURDAY)
check(endOfCurrentSundayBasedWeek == LocalDate(2026, 2, 14)) 
   //sampleEnd
}