keep only the previous 24 hours

This commit is contained in:
PranshulGG committed 2026-08-20 17:56:20 +05:30
1 parent d95b1e7238
commit 08bd6aeb58
1 file changed
+6
@@ -1,6 +1,8 @@
package com.pranshulgg.weather_master_app.core.utils.weather.forecast
import com.pranshulgg.weather_master_app.data.local.entity.weather.HourlyWeatherEntity
import kotlin.time.Clock
import kotlin.time.Duration.Companion.hours
/**
@@ -12,7 +14,11 @@ fun mergeHourlyWeather(
existing: List<HourlyWeatherEntity>,
incoming: List<HourlyWeatherEntity>
): List<HourlyWeatherEntity> {
val cutoff = Clock.System.now().minus(24.hours).toEpochMilliseconds()
return (existing + incoming)
.filter { it.time >= cutoff }
.associateBy { it.locationId to it.time }
.values
.sortedBy { it.time }