-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
383 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/com/github/smaugfm/models/serializers/HumanReadableDateSerializer.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,28 @@ | ||
package com.github.smaugfm.models.serializers | ||
|
||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
class HumanReadableDateSerializer : KSerializer<LocalDateTime> { | ||
private val formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss") | ||
|
||
override val descriptor = PrimitiveSerialDescriptor( | ||
this::class.qualifiedName!!, | ||
PrimitiveKind.LONG | ||
) | ||
|
||
override fun deserialize(decoder: Decoder): LocalDateTime = | ||
LocalDateTime.parse( | ||
decoder.decodeString(), | ||
formatter | ||
) | ||
|
||
override fun serialize(encoder: Encoder, value: LocalDateTime) { | ||
encoder.encodeString(formatter.format(value)) | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
.../github/smaugfm/util/IErrorFormattable.kt → ...m/github/smaugfm/util/ErrorFormattable.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.github.smaugfm.util | ||
|
||
interface IErrorFormattable { | ||
interface ErrorFormattable { | ||
fun formatError(): String | ||
} |
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,32 @@ | ||
package com.github.smaugfm.util | ||
|
||
import kotlinx.coroutines.InternalCoroutinesApi | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.flow | ||
|
||
@OptIn(InternalCoroutinesApi::class) | ||
fun <T> Flow<T>.throttle(periodMillis: Long): Flow<T> { | ||
require(periodMillis > 0) { "period should be positive" } | ||
return flow { | ||
var lastTime = 0L | ||
collect { | ||
val currentTime = System.currentTimeMillis() | ||
if (currentTime - lastTime >= periodMillis) { | ||
lastTime = currentTime | ||
emit(it) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun <T> Flow<T>.chunked(size: Int): Flow<List<T>> = flow { | ||
val chunkedList = mutableListOf<T>() | ||
collect { | ||
chunkedList.add(it) | ||
if (chunkedList.size == size) { | ||
emit(chunkedList.toList()) | ||
chunkedList.clear() | ||
} | ||
} | ||
} |
Oops, something went wrong.