A Kotlin Multiplatform library that provides localized display names for kotlinx-datetime types.
This library extends kotlinx-datetime by adding extension functions to get localized display names for DayOfWeek and Month enums, as well as format LocalDateTime, LocalDate, and LocalTime values. It supports multiple text styles (FULL, SHORT, NARROW) and format styles, using platform-specific localization APIs to provide accurate, locale-aware formatting.
dependencies {
implementation("io.github.adrcotfas:kotlinx-datetime-names:0.1.1")
}import io.github.adrcotfas.datetime.names.*
import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.Month
// Get localized day names
val monday = DayOfWeek.MONDAY
println(monday.getDisplayName()) // "Monday" (or localized equivalent)
// Get localized month names
val january = Month.JANUARY
println(january.getDisplayName()) // "January" (or localized equivalent)import io.github.adrcotfas.datetime.names.*
import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.Month
// Specify locale and text style
val locale = java.util.Locale.GERMAN // or platform-specific locale
val day = DayOfWeek.MONDAY
// Full name
println(day.getDisplayName(TextStyle.FULL, locale)) // "Montag"
// Short name
println(day.getDisplayName(TextStyle.SHORT, locale)) // "Mo"
// Narrow name
println(day.getDisplayName(TextStyle.NARROW, locale)) // "M"The library also provides extension functions to format LocalDateTime, LocalDate, and LocalTime with locale-aware formatting:
import io.github.adrcotfas.datetime.names.*
import kotlinx.datetime.*
val dateTime = LocalDateTime(2024, 12, 1, 15, 30, 0)
val date = LocalDate(2024, 12, 1)
val time = LocalTime(15, 30, 0)
// Format LocalDateTime with separate date and time styles
dateTime.format(
dateStyle = FormatStyle.FULL,
timeStyle = FormatStyle.MEDIUM
) // "Sunday, December 1, 2024, 3:30:00 PM" (default locale)
// Format LocalDate
date.format(FormatStyle.SHORT) // "12/1/24" (default locale)
date.format(FormatStyle.FULL) // "Sunday, December 1, 2024" (default locale)
// Format LocalTime
time.format(FormatStyle.SHORT) // "3:30 PM" (default locale)
time.format(FormatStyle.MEDIUM) // "3:30:00 PM" (default locale)
// Format with different locales - same date, different results
val locale = java.util.Locale.GERMAN // or platform-specific locale
date.format(FormatStyle.FULL)
// Default locale: "Sunday, December 1, 2024"
// German locale: "Sonntag, 1. Dezember 2024"
date.format(FormatStyle.SHORT, locale)
// "01.12.24" (German format)
time.format(FormatStyle.MEDIUM, locale)
// "15:30:00" (24-hour format in German)
dateTime.format(
dateStyle = FormatStyle.LONG,
timeStyle = FormatStyle.SHORT,
locale = locale
)
// "1. Dezember 2024, 15:30"TextStyle (for day/month names):
TextStyle.FULL- Full display name (e.g., "Monday", "January")TextStyle.FULL_STANDALONE- Full standalone nameTextStyle.SHORT- Short display name (e.g., "Mon", "Jan")TextStyle.SHORT_STANDALONE- Short standalone nameTextStyle.NARROW- Narrow name (e.g., "M", "J")TextStyle.NARROW_STANDALONE- Narrow standalone name
FormatStyle (for date/time formatting):
FormatStyle.SHORT- Shortest format (e.g., "12/1/24", "3:30 PM")FormatStyle.MEDIUM- Medium length format (e.g., "Dec 1, 2024", "3:30:00 PM")FormatStyle.LONG- Long format with more detailFormatStyle.FULL- Longest format (e.g., "Sunday, December 1, 2024")
The library includes a demo app that showcases localized names across different locales and text styles.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.



