1package com.parseable.android
3import com.parseable.android.data.formatTimestamp
4import org.junit.Assert.*
6import java.util.TimeZone
8class FormatTimestampTest {
11 fun `formats ISO8601 UTC timestamp`() {
12 // Force UTC for test determinism
13 val original = TimeZone.getDefault()
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)
19 TimeZone.setDefault(original)
24 fun `formats Parseable timestamp format with +00 00 suffix`() {
25 val original = TimeZone.getDefault()
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)
31 TimeZone.setDefault(original)
36 fun `treats offset-less timestamp as UTC and converts to local`() {
37 val original = TimeZone.getDefault()
39 TimeZone.setDefault(TimeZone.getTimeZone("America/New_York"))
40 // No offset/zone: should be interpreted as UTC (Parseable stores UTC),
41 // then converted to local (June = EDT = UTC-4).
42 val result = formatTimestamp("2024-06-15T18:30:45.000")
43 assertEquals("Jun 15 14:30:45.000", result)
45 TimeZone.setDefault(original)
50 fun `returns raw string for unparseable timestamp`() {
51 val result = formatTimestamp("not-a-timestamp")
52 assertEquals("not-a-timestamp", result)
56 fun `handles empty string`() {
57 val result = formatTimestamp("")
58 assertEquals("", result)
62 fun `converts to local timezone`() {
63 val original = TimeZone.getDefault()
65 TimeZone.setDefault(TimeZone.getTimeZone("America/New_York"))
66 val result = formatTimestamp("2024-06-15T18:30:45.000Z")
68 assertEquals("Jun 15 14:30:45.000", result)
70 TimeZone.setDefault(original)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list