@@ -20,6 +20,9 @@ class DateTimeExtTest : BaseUnitTest() {
2020 val AFTERNOON : Instant = Instant .parse(" 2026-03-07T15:23:00Z" )
2121 val MIDNIGHT : Instant = Instant .parse(" 2026-03-07T00:15:00Z" )
2222 val NOON : Instant = Instant .parse(" 2026-03-07T12:05:00Z" )
23+
24+ // Midday so the calendar day, and with it the month name, holds in every time zone
25+ val MIDDAY_IN_JULY : Long = Instant .parse(" 2026-07-27T12:00:00Z" ).toEpochMilli()
2326 }
2427
2528 @Test
@@ -261,5 +264,40 @@ class DateTimeExtTest : BaseUnitTest() {
261264 assertEquals(UiDateStyle .DATE_TIME , uiDateStyleFor(lateEvening.epochSecond.toULong(), today, bucharest))
262265 }
263266
267+ @Test
268+ fun `toLocalizedTimestamp uses the supplied locale` () {
269+ val inGerman = MIDDAY_IN_JULY .toLocalizedTimestamp(Locale .GERMANY )
270+ val inUs = MIDDAY_IN_JULY .toLocalizedTimestamp(Locale .US )
271+
272+ assertTrue(inGerman.contains(" Juli" ), " expected a German month name, got '$inGerman '" )
273+ assertTrue(inUs.contains(" July" ), " expected an English month name, got '$inUs '" )
274+ }
275+
276+ @Test
277+ fun `toLocalizedTimestamp follows the default locale when none is supplied` () {
278+ val original = Locale .getDefault()
279+ try {
280+ Locale .setDefault(Locale .GERMANY )
281+ val result = MIDDAY_IN_JULY .toLocalizedTimestamp()
282+
283+ assertTrue(result.contains(" Juli" ), " expected a German month name, got '$result '" )
284+ } finally {
285+ Locale .setDefault(original)
286+ }
287+ }
288+
289+ @Test
290+ fun `toLocalizedTimestamp orders the date the way the locale does` () {
291+ val original = Locale .getDefault()
292+ try {
293+ Locale .setDefault(Locale .GERMANY )
294+ val result = MIDDAY_IN_JULY .toLocalizedTimestamp()
295+
296+ assertTrue(result.indexOf(" 27" ) < result.indexOf(" Juli" ), " expected day before month, got '$result '" )
297+ } finally {
298+ Locale .setDefault(original)
299+ }
300+ }
301+
264302 private fun Instant.formattedInUtc (pattern : String ) = formatted(pattern, Locale .US , UTC )
265303}
0 commit comments