Migrate osm opening hours parsing to external library (#900)

* Fix: don't treat PH OpeningHours with specified time as `everyDay`

* migrate to osm-opening-hours, add tests for openinghours parsing

* Style nit

* implement 'PH,Su off'

* implement SpecificWeekdays

* decrypt source code (a little)

* fix constructor call in OpeningHoursTest.kt

* lint

* fix negative durations, add test for LastNth + test to combine everything implemented

* add copyright note for osm-opening-hours

* remove unused library
This commit is contained in:
Christoph
2024-10-20 11:47:16 +02:00
committed by GitHub
parent 7d490f2179
commit 16637265fb
9 changed files with 513 additions and 172 deletions
@@ -0,0 +1,18 @@
package de.mm20.launcher2.ktx
fun <T,V> Iterable<T>.flatMapNotNull(transform: (T) -> Iterable<V>?) : List<V> {
val destination = mutableListOf<V>()
for (it in this) {
val transformed = transform(it) ?: continue
destination.addAll(transformed)
}
return destination
}
fun <T,V> Iterable<Pair<T, V>>.toMultiMap() : Map<T, List<V>> {
val destination = mutableMapOf<T, MutableList<V>>()
for ((k, v) in this) {
destination.getOrPut(k) { mutableListOf() } += v
}
return destination
}
@@ -10,4 +10,8 @@ fun <T> List<T>.randomElement(): T {
fun <T> List<T>.randomElementOrNull(): T? {
if (isEmpty()) return null
return get(Random().nextInt(size))
}
}
fun <T> List<T>?.ifNullOrEmpty(block: () -> List<T>): List<T> {
return if (this.isNullOrEmpty()) block() else this
}
@@ -0,0 +1,5 @@
package de.mm20.launcher2.ktx
fun <A, B> Pair<A, A>.map(transform: (A) -> B): Pair<B, B> = transform(first) to transform(second)
fun <A, B, C> Pair<A, B>.into(transform: (A, B) -> C): C = transform(first, second)