fix: Account for local timezone when fetching month events

This commit is contained in:
Peter Vacho 2024-12-30 15:01:49 +01:00
parent b3d9e426a2
commit c6c64bfa3f
Signed by: school
GPG key ID: 8CFC3837052871B4

View file

@ -21,6 +21,7 @@ import com.p_vacho.neat_calendar.models.CalendarDay
import kotlinx.coroutines.launch
import java.time.ZoneOffset
import java.time.YearMonth
import java.time.ZoneId
import java.time.format.TextStyle
import java.util.Locale
@ -72,8 +73,12 @@ class CalendarActivity : AppCompatActivity() {
* Note that this also includes the events this user was invited into.
*/
private suspend fun fetchEventsForMonth(yearMonth: YearMonth): Map<Int, List<EventResponse>> {
val startFrom = yearMonth.atDay(1).atStartOfDay().atOffset(ZoneOffset.UTC)
val endTo = yearMonth.atEndOfMonth().atTime(23, 59, 59).atOffset(ZoneOffset.UTC)
// Use the system's default time zone
val zoneId = ZoneId.systemDefault()
// Get the start and end of the month in the local time zone
val startFrom = yearMonth.atDay(1).atStartOfDay(zoneId).toOffsetDateTime()
val endTo = yearMonth.atEndOfMonth().atTime(23, 59, 59).atZone(zoneId).toOffsetDateTime()
val userId = tokenManager.userId