Skip to content

Instantly share code, notes, and snippets.

@lgawin
Created March 7, 2024 03:51
Show Gist options
  • Save lgawin/6ed4b08ec3ac12aa53d0fd8191a63213 to your computer and use it in GitHub Desktop.
Save lgawin/6ed4b08ec3ac12aa53d0fd8191a63213 to your computer and use it in GitHub Desktop.
AM/PM translations
import org.junit.Assert.assertEquals
import org.junit.Test
import java.time.LocalTime
import java.time.format.DateTimeFormatter
import java.util.Locale
class TimeSuffixesTest {
@Test
fun getAmPm() {
val timeSuffixes: (Locale) -> List<String> = { locale ->
listOf(
LocalTime.of(0, 1),
LocalTime.of(12, 1),
).map {
DateTimeFormatter.ofPattern("a", locale).format(it)
}
}
assertEquals(listOf("AM", "PM"), timeSuffixes(Locale.ENGLISH))
assertEquals(listOf("AM", "PM"), timeSuffixes(Locale.GERMAN))
assertEquals(listOf("오전", "오후"), timeSuffixes(Locale.KOREAN))
assertEquals(listOf("上午", "下午"), timeSuffixes(Locale.CHINESE))
assertEquals(listOf("a.m.", "p.m."), timeSuffixes(Locale.CANADA_FRENCH))
assertEquals(listOf("ก่อนเที่ยง", "หลังเที่ยง"), timeSuffixes(Locale("th", "TH"))) // Thailand
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment