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:
@@ -228,4 +228,12 @@ val OpenSourceLicenses = arrayOf(
|
||||
url = "https://github.com/aallam/string-similarity-kotlin",
|
||||
copyrightNote = "Copyright (c) 2023 Mouaad Aallam",
|
||||
),
|
||||
OpenSourceLibrary(
|
||||
name = "osm-opening-hours",
|
||||
description = "Kotlin multiplatform library to parse OpenStreetMap opening hours",
|
||||
licenseName = R.string.mit_license_name,
|
||||
licenseText = R.raw.license_mit,
|
||||
url = "https://github.com/westnordost/osm-opening-hours",
|
||||
copyrightNote = "Copyright (c) 2024 Tobias Zwick",
|
||||
)
|
||||
)
|
||||
@@ -18,8 +18,7 @@ class OpeningScheduleTest(val date: LocalDateTime, val expected: Boolean) {
|
||||
|
||||
@Test
|
||||
fun isOpen() {
|
||||
val openingSchedule = OpeningSchedule(
|
||||
isTwentyFourSeven = false,
|
||||
val openingSchedule = OpeningSchedule.Hours(
|
||||
/**
|
||||
* Monday: 18:00 - Tue. 01:00
|
||||
* Tuesday: 10:00 - 00:00
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user