shlogg · Early preview
Kiolk @kiolk

Fixing Time Calculation Issue With Kotlinx.datetime Package

Fixed time issue by calculating past dates with kotlinx.datetime package. Refactored code and extracted methods/constants. Next steps: update README, fix comment element, implement WebView & theme configuration.

What I did:
I spent today fixing the issue of sending time as a request parameter. The issue wasn't with sending time, but with calculating a specific time in the past. I use the kotlinx.datetime package for manipulating dates. My final solution looks like this:

fun SortingType.toTime(): Instant? {
    val currentInstant: Instant = Clock.System.now()
    return when (this) {
        SortingType.Infinity -> currentInstant.minus(365.toDuration(DurationUnit.DAYS) * YEARS_AGO_FOR_INFINITY)
        SortingType.Month -> currentInstant.minus(30.toDuration(DurationUnit.DAYS))
        SortingType.Week...