Day Of Week Names
A description of how the names of weekdays are formatted.
Instances of this class are typically used as arguments to DateTimeFormatBuilder.WithDate.dayOfWeek.
Predefined instances are available as ENGLISH_FULL and ENGLISH_ABBREVIATED. You can also create custom instances using the constructor.
An IllegalArgumentException will be thrown if some day-of-week name is empty or there are duplicate names.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() {
//sampleStart
// Using strings for day-of-week names in a custom format
val format = LocalDate.Format {
date(LocalDate.Formats.ISO)
chars(", ")
dayOfWeek(DayOfWeekNames.ENGLISH_ABBREVIATED) // "Mon", "Tue", ...
}
check(format.format(LocalDate(2021, 1, 13)) == "2021-01-13, Wed")
//sampleEnd
}
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() {
//sampleStart
// Constructing a custom set of day of week names for parsing and formatting
val germanDayOfWeekNames = listOf(
"Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"
)
// constructing by passing a list of 7 strings
val myDayOfWeekNames = DayOfWeekNames(germanDayOfWeekNames)
check(myDayOfWeekNames.names == germanDayOfWeekNames)
//sampleEnd
}