Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 47dd6a90 authored by Ricki Hirner's avatar Ricki Hirner Committed by GitHub
Browse files

Interpret Last-Modified GMT times as GMT and not as local timezone (#13)

Closes #12
parent b854048d
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@ import java.util.*

object HttpUtils {

    const val httpDateFormatStr = "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
    val httpDateFormat = SimpleDateFormat(httpDateFormatStr, Locale.ROOT)
    private const val httpDateFormatStr = "EEE, dd MMM yyyy HH:mm:ss zzz"
    private val httpDateFormat = SimpleDateFormat(httpDateFormatStr, Locale.ROOT)

    /**
     * Gets the resource name (the last segment of the path) from an URL.
@@ -58,8 +58,8 @@ object HttpUtils {
     */
    fun parseDate(dateStr: String) = try {
        DateUtils.parseDate(dateStr, Locale.US,
                httpDateFormatStr,
                "EEE, dd MMM yyyy HH:mm:ss zzz", // RFC 822, updated by RFC 1123 with any TZ
                httpDateFormatStr,               // RFC 822, updated by RFC 1123 with any TZ
                "EEE, dd MMM yyyy HH:mm:ss zzz",
                "EEEE, dd-MMM-yy HH:mm:ss zzz",  // RFC 850, obsoleted by RFC 1036 with any TZ.
                "EEE MMM d HH:mm:ss yyyy",       // ANSI C's asctime() format
                // Alternative formats.
+6 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ import org.junit.Test
class HttpUtilsTest {

    @Test
    fun testFilename() {
    fun fileName() {
        assertEquals("", HttpUtils.fileName("https://example.com".toHttpUrl()))
        assertEquals("", HttpUtils.fileName("https://example.com/".toHttpUrl()))
        assertEquals("file1", HttpUtils.fileName("https://example.com/file1".toHttpUrl()))
@@ -22,4 +22,9 @@ class HttpUtilsTest {
        assertEquals("dir2", HttpUtils.fileName("https://example.com/dir1/dir2/".toHttpUrl()))
    }

    @Test
    fun parseDate() {
        assertEquals(1683825995000, HttpUtils.parseDate("Thu, 11 May 2023 17:26:35 GMT")?.time)
    }

}