diff --git a/capy/src/main/java/com/jocmp/capy/common/DateTimeFormatters.kt b/capy/src/main/java/com/jocmp/capy/common/DateTimeFormatters.kt index 0292651b..f35d21bb 100644 --- a/capy/src/main/java/com/jocmp/capy/common/DateTimeFormatters.kt +++ b/capy/src/main/java/com/jocmp/capy/common/DateTimeFormatters.kt @@ -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") + } } diff --git a/capy/src/main/java/com/jocmp/capy/common/TimeHelpers.kt b/capy/src/main/java/com/jocmp/capy/common/TimeHelpers.kt index dc7ee669..a1552ff4 100644 --- a/capy/src/main/java/com/jocmp/capy/common/TimeHelpers.kt +++ b/capy/src/main/java/com/jocmp/capy/common/TimeHelpers.kt @@ -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 @@ -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, ) /** diff --git a/capy/src/test/java/com/jocmp/capy/common/TimeHelpersTest.kt b/capy/src/test/java/com/jocmp/capy/common/TimeHelpersTest.kt index d729b484..518f2187 100644 --- a/capy/src/test/java/com/jocmp/capy/common/TimeHelpersTest.kt +++ b/capy/src/test/java/com/jocmp/capy/common/TimeHelpersTest.kt @@ -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) + } }