Created
November 11, 2024 22:01
-
-
Save jordanbeck/e0bb66247d9566459d8c63e9d5265061 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/app/src/main/java/com/etsy/android/interview/Message.kt b/app/src/main/java/com/etsy/android/interview/Message.kt | |
| index 4760acd..6e5c00a 100644 | |
| --- a/app/src/main/java/com/etsy/android/interview/Message.kt | |
| +++ b/app/src/main/java/com/etsy/android/interview/Message.kt | |
| @@ -1,6 +1,7 @@ | |
| package com.etsy.android.interview | |
| import java.text.SimpleDateFormat | |
| +import java.util.Locale | |
| data class Message( | |
| val content: String, | |
| @@ -12,6 +13,7 @@ data class Message( | |
| * Use a time formatter (e.g. [SimpleDateFormat]) to create a human readable time string | |
| */ | |
| fun formatTime(): String { | |
| - return "" | |
| + val format = SimpleDateFormat("MMM d, h:mm aaa", Locale.getDefault()) | |
| + return format.format(time) | |
| } | |
| } | |
| \ No newline at end of file | |
| diff --git a/app/src/test/java/com/etsy/android/interview/ui/MessageTest.kt b/app/src/test/java/com/etsy/android/interview/ui/MessageTest.kt | |
| index b3b5c00..2a79f4b 100644 | |
| --- a/app/src/test/java/com/etsy/android/interview/ui/MessageTest.kt | |
| +++ b/app/src/test/java/com/etsy/android/interview/ui/MessageTest.kt | |
| @@ -2,9 +2,19 @@ package com.etsy.android.interview.ui | |
| import com.etsy.android.interview.Message | |
| import org.junit.Assert.assertEquals | |
| +import org.junit.Before | |
| import org.junit.Test | |
| +import java.util.Locale | |
| +import java.util.TimeZone | |
| class MessageTest { | |
| + | |
| + @Before | |
| + fun setup() { | |
| + TimeZone.setDefault(TimeZone.getTimeZone("GMT")) | |
| + Locale.setDefault(Locale.US) | |
| + } | |
| + | |
| @Test | |
| fun `formatTime should return human readable date time`() { | |
| // Note: this is the format that needs to be matched, but it doesn't match the data in this test. | |
| @@ -14,7 +24,7 @@ class MessageTest { | |
| // Given | |
| val message = Message( | |
| content = "Hello", | |
| - time = 1630719120000, | |
| + time = 1704122100000, | |
| isFromUser = false | |
| ) | |
| val result = message.formatTime() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment