Skip to content

Commit fd3dccc

Browse files
committed
Refactor rate limit time calculation and organize imports
- Update `RateLimitInfo.timeUntilReset()` to use `Instant` and `Clock.System.now()` for more accurate duration calculation. - Fix an issue where `resetTimestamp` was treated as milliseconds instead of seconds. - Organize and clean up imports in `TimeFormatters.kt`.
1 parent 06d89ce commit fd3dccc

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

  • core

core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/RateLimitInfo.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package zed.rainxch.core.domain.model
33
import kotlin.time.Clock
44
import kotlin.time.Duration
55
import kotlin.time.Duration.Companion.seconds
6+
import kotlin.time.Instant
67

78
data class RateLimitInfo(
89
val limit: Int,
@@ -14,8 +15,8 @@ data class RateLimitInfo(
1415
get() = remaining == 0
1516

1617
fun timeUntilReset(): Duration {
17-
val diff = resetTimestamp - Clock.System.now().toEpochMilliseconds()
18-
return diff.seconds.coerceAtLeast(Duration.ZERO)
18+
val reset = Instant.fromEpochSeconds(resetTimestamp)
19+
return (reset - Clock.System.now()).coerceAtLeast(Duration.ZERO)
1920
}
2021

2122
fun isCurrentlyLimited(): Boolean {

core/presentation/src/commonMain/kotlin/zed/rainxch/core/presentation/utils/TimeFormatters.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package zed.rainxch.core.presentation.utils
22

33
import androidx.compose.runtime.Composable
4-
import zed.rainxch.githubstore.core.presentation.res.*
54
import kotlinx.datetime.TimeZone
65
import kotlinx.datetime.toLocalDateTime
76
import org.jetbrains.compose.resources.getString
87
import org.jetbrains.compose.resources.stringResource
8+
import zed.rainxch.githubstore.core.presentation.res.*
99
import kotlin.time.Clock
1010
import kotlin.time.Duration
1111
import kotlin.time.Duration.Companion.days

0 commit comments

Comments
 (0)