git.iko.soy/parseable-android
on 0da331f help sign in
59 lines 1.7 kB history raw
1package com.parseable.android
3import com.parseable.android.data.formatTimestamp
4import org.junit.Assert.*
5import org.junit.Test
6import java.util.TimeZone
8class FormatTimestampTest {
10 @Test
11 fun `formats ISO8601 UTC timestamp`() {
12 // Force UTC for test determinism
13 val original = TimeZone.getDefault()
14 try {
15 TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
16 val result = formatTimestamp("2024-12-15T14:30:45.123Z")
17 assertEquals("Dec 15 14:30:45.123", result)
18 } finally {
19 TimeZone.setDefault(original)
20 }
21 }
23 @Test
24 fun `formats Parseable timestamp format with +00 00 suffix`() {
25 val original = TimeZone.getDefault()
26 try {
27 TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
28 val result = formatTimestamp("2024-12-15T14:30:45.123456+00:00")
29 assertEquals("Dec 15 14:30:45.123", result)
30 } finally {
31 TimeZone.setDefault(original)
32 }
33 }
35 @Test
36 fun `returns raw string for unparseable timestamp`() {
37 val result = formatTimestamp("not-a-timestamp")
38 assertEquals("not-a-timestamp", result)
39 }
41 @Test
42 fun `handles empty string`() {
43 val result = formatTimestamp("")
44 assertEquals("", result)
45 }
47 @Test
48 fun `converts to local timezone`() {
49 val original = TimeZone.getDefault()
50 try {
51 TimeZone.setDefault(TimeZone.getTimeZone("America/New_York"))
52 val result = formatTimestamp("2024-06-15T18:30:45.000Z")
53 // June = EDT = UTC-4
54 assertEquals("Jun 15 14:30:45.000", result)
55 } finally {
56 TimeZone.setDefault(original)
57 }
58 }