Author: Adam <git@apiote.xyz>
parse lastUpdate date
app/src/main/java/ml/adamsprogs/bimba/api/Structs.kt | 41 +++++++++++++
diff --git a/app/src/main/java/ml/adamsprogs/bimba/api/Structs.kt b/app/src/main/java/ml/adamsprogs/bimba/api/Structs.kt index 05903f2d7837f44e74016db3c97799d54bdbb637..72b68952db24dc2ba3c1b54e4cbf5d616991a5a4 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/api/Structs.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/api/Structs.kt @@ -13,12 +13,49 @@ import kotlin.math.abs import kotlin.math.pow import kotlin.math.roundToInt +data class DateTime( + val year: Int, + val month: Int, + val day: Int, + val hour: Int, + val minute: Int, + val second: Int, + val offsetSign: Int, + val offsetH: Int, + val offsetM: Int +) { + companion object { + fun of(s: String): DateTime { + val (oH, oM) = if (s[19] == 'Z') { + arrayOf(0, 0) + } else { + arrayOf(Integer.parseInt(s.substring(20, 22)), Integer.parseInt(s.substring(23, 25))) + } + val oS = when (s[19]) { + 'Z' -> 0 + '+' -> 1 + '-' -> -1 + else -> TODO("Throw invalid") + } + return DateTime( + Integer.parseInt(s.substring(0, 4)), + Integer.parseInt(s.substring(5, 7)), + Integer.parseInt(s.substring(8, 10)), + Integer.parseInt(s.substring(11, 13)), + Integer.parseInt(s.substring(14, 16)), + Integer.parseInt(s.substring(17, 19)), + oS, oH, oM + ) + } + } +} + data class FeedInfo( val name: String, val id: String, val attribution: String, val description: String, - val lastUpdate: String // todo date from RFC + val lastUpdate: DateTime ) { companion object { fun unmarshal(stream: InputStream): FeedInfo { @@ -28,7 +65,7 @@ reader.readString(), reader.readString(), reader.readString(), reader.readString(), - reader.readString() + DateTime.of(reader.readString()) ) } }