diff --git a/sdk/core/src/test/java/com/klaviyo/core/config/SystemClockTest.kt b/sdk/core/src/test/java/com/klaviyo/core/config/SystemClockTest.kt index be99897b9..11ce4b2bc 100644 --- a/sdk/core/src/test/java/com/klaviyo/core/config/SystemClockTest.kt +++ b/sdk/core/src/test/java/com/klaviyo/core/config/SystemClockTest.kt @@ -1,10 +1,34 @@ package com.klaviyo.core.config +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale +import java.util.TimeZone +import junit.framework.TestCase.assertEquals +import org.junit.After import org.junit.Assert +import org.junit.Before import org.junit.Test class SystemClockTest { + private var defaultLocale: Locale? = null + + @Before + fun setUp() { + // Save the original default locale + defaultLocale = Locale.getDefault() + + // Set default locale to Arabic + Locale.setDefault(Locale("ar")) + } + + @After + fun tearDown() { + // Restore the original default locale after test + defaultLocale?.let { Locale.setDefault(it) } + } + @Test fun `Clock uses proper date format`() { val regex7 = "^\\d{4}(-\\d\\d(-\\d\\d(T\\d\\d:\\d\\d(:\\d\\d)?(\\.\\d+)?(([+-]\\d\\d:*\\d\\d)|Z)?)?)?)?\$".toRegex() @@ -36,4 +60,20 @@ class SystemClockTest { Thread.sleep(20L) Assert.assertEquals(1, counter) } + + @Test + fun `Clock uses English locale for date formatting`() { + val expectedFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH).apply { + timeZone = TimeZone.getTimeZone("UTC") + } + + // Use a known timestamp for test consistency + val testTimestamp = 0L + val expectedOutput = expectedFormat.format(Date(testTimestamp)) + + // using the utility + val actualOutput = SystemClock.isoTime(testTimestamp) + + assertEquals(expectedOutput, actualOutput) + } }