-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse published date in local delegate
- Loading branch information
Showing
13 changed files
with
145 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package com.jocmp.basil.accounts | ||
|
||
import java.time.OffsetDateTime | ||
|
||
internal data class ParsedItem( | ||
val externalID: String, | ||
val title: String? = null, | ||
val contentHTML: String? = null, | ||
val url: String? = null, | ||
val summary: String? = null, | ||
val imageURL: String? = null, | ||
val publishedAt: OffsetDateTime? | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.jocmp.basil.shared | ||
|
||
import java.time.OffsetDateTime | ||
import java.time.ZoneOffset | ||
import java.time.format.DateTimeParseException | ||
|
||
fun parseISODate(value: String?): OffsetDateTime? { | ||
value ?: return null | ||
|
||
return try { | ||
OffsetDateTime.parse(value).withOffsetSameInstant(ZoneOffset.UTC) | ||
} catch (_: DateTimeParseException) { | ||
null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
basil/src/test/java/com/jocmp/basil/shared/TimeHelpersTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.jocmp.basil.shared | ||
|
||
|
||
import org.junit.Test | ||
import java.time.OffsetDateTime | ||
import java.time.ZoneOffset | ||
import kotlin.test.assertEquals | ||
|
||
class TimeHelpersTest { | ||
@Test | ||
fun `parseISODate parses an offset ISO timestamp to UTC`() { | ||
val result = parseISODate("2023-12-25T09:00:00-05:00") | ||
|
||
val expected = OffsetDateTime.of( | ||
2023, | ||
12, | ||
25, | ||
14, | ||
0, | ||
0, | ||
0, | ||
ZoneOffset.UTC | ||
) | ||
|
||
assertEquals(expected = expected, actual = result) | ||
} | ||
|
||
@Test | ||
fun `parseISODate discards non-ISO formatted strings`() { | ||
val result = parseISODate("Mon, 25 Dec 2023 17:18:03 +0000") | ||
|
||
assertEquals(expected = null, actual = result) | ||
} | ||
|
||
@Test | ||
fun `parseISODate discards null values`() { | ||
val result = parseISODate(null) | ||
|
||
assertEquals(expected = null, actual = result) | ||
} | ||
} |