Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/main/kotlin/at/bitfire/dav4jvm/HttpUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -58,10 +58,10 @@ 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
"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
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.
"EEE, dd-MMM-yyyy HH:mm:ss z",
"EEE, dd-MMM-yyyy HH-mm-ss z",
Expand Down
7 changes: 6 additions & 1 deletion src/test/kotlin/at/bitfire/dav4jvm/HttpUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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)
}

}