Skip to content

Commit

Permalink
Restore Zulu timestamp handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jocmp committed Sep 15, 2024
1 parent 88f39ae commit 3a22177
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ internal object DateTimeFormatters {
.appendOffset("+HHMM", "GMT")
.toFormatter()
}

val ZULU_DATE_TIME_FORMATTER: DateTimeFormatter by lazy {
DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss z")
}
}
2 changes: 2 additions & 0 deletions capy/src/main/java/com/jocmp/capy/common/TimeHelpers.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jocmp.capy.common

import com.jocmp.capy.common.DateTimeFormatters.LONG_MONTH_DATE_TIME_FORMATTER
import com.jocmp.capy.common.DateTimeFormatters.ZULU_DATE_TIME_FORMATTER
import java.time.Instant
import java.time.ZoneOffset
import java.time.ZonedDateTime
Expand All @@ -11,6 +12,7 @@ val formatters = listOf(
DateTimeFormatter.ISO_ZONED_DATE_TIME,
DateTimeFormatter.RFC_1123_DATE_TIME,
LONG_MONTH_DATE_TIME_FORMATTER,
ZULU_DATE_TIME_FORMATTER,
)

/**
Expand Down
18 changes: 18 additions & 0 deletions capy/src/test/java/com/jocmp/capy/common/TimeHelpersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,22 @@ class TimeHelpersTest {

assertEquals(expected = now, actual = result)
}

@Test
fun `RFC1123 with Z offset`() {
val result = "Fri, 30 Aug 2024 05:23:12 Z".toDateTime

val expected = ZonedDateTime.of(
2024,
8,
30,
5,
23,
12,
0,
ZoneOffset.UTC
)

assertEquals(expected = expected, actual = result)
}
}

0 comments on commit 3a22177

Please sign in to comment.