mirror of
https://github.com/PranshulGG/WeatherMaster.git
synced 2026-10-21 18:43:03 -05:00
keep only the previous 24 hours
This commit is contained in:
1 parent
d95b1e7238
commit
08bd6aeb58
1 file changed
+6
+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 }
|
||||
|
||||
Reference in new issue
Block a user