
Time-of-day greeting generator in Indonesian and English, returns morning/afternoon/evening/night messages based on current hour; supports language selection and customizable hour provider.
A simple Kotlin Multiplatform library for greeting messages based on the time of day and language.
Supported Languages
The library currently supports:
ID – Indonesian
EN – English
enum class Language {
EN, ID
}import io.github.kotlin.greeting.*
fun main() {
println(greet()) // e.g., "Selamat Pagi" if it's morning
}import io.github.kotlin.greeting.*
fun main() {
println(greet(Language.EN)) // e.g., "Good Morning" if it's morning
}The greet() function determines the current hour using the platform-specific currentHour() function:
expect fun currentHour(): Intactual fun currentHour(): Int {
return java.util.Calendar.getInstance().get(java.util.Calendar.HOUR_OF_DAY)
}import platform.Foundation.*
actual fun currentHour(): Int {
val date = NSDate()
val calendar = NSCalendar.currentCalendar
return calendar.component(NSCalendarUnitHour, date = date).toInt()
}| Hour Range | Indonesian | English |
|---|---|---|
4-10 |
Selamat Pagi | Good Morning |
11-14 |
Selamat Siang | Good Afternoon |
15-17 |
Selamat Sore | Good Evening |
18-20 |
Selamat Malam | Good Night |
Otherwise |
Selamat Malam | Good Night |
If published to Maven Central:
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.johnylie:kotlin-greeting:1.0.3")
}A simple Kotlin Multiplatform library for greeting messages based on the time of day and language.
Supported Languages
The library currently supports:
ID – Indonesian
EN – English
enum class Language {
EN, ID
}import io.github.kotlin.greeting.*
fun main() {
println(greet()) // e.g., "Selamat Pagi" if it's morning
}import io.github.kotlin.greeting.*
fun main() {
println(greet(Language.EN)) // e.g., "Good Morning" if it's morning
}The greet() function determines the current hour using the platform-specific currentHour() function:
expect fun currentHour(): Intactual fun currentHour(): Int {
return java.util.Calendar.getInstance().get(java.util.Calendar.HOUR_OF_DAY)
}import platform.Foundation.*
actual fun currentHour(): Int {
val date = NSDate()
val calendar = NSCalendar.currentCalendar
return calendar.component(NSCalendarUnitHour, date = date).toInt()
}| Hour Range | Indonesian | English |
|---|---|---|
4-10 |
Selamat Pagi | Good Morning |
11-14 |
Selamat Siang | Good Afternoon |
15-17 |
Selamat Sore | Good Evening |
18-20 |
Selamat Malam | Good Night |
Otherwise |
Selamat Malam | Good Night |
If published to Maven Central:
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.johnylie:kotlin-greeting:1.0.3")
}