-
Notifications
You must be signed in to change notification settings - Fork 136
[WOOMOB-1722] - Properly clean the Bookings table for Today/Upcoming tabs' first page load #15022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+439
−77
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b6cd96c
Prefer BookingFilters.EMPTY over nullable property
AdamGrzybkowski 98c6ec8
Extract Today/Upcoming DateRange creation for reuse in other places
AdamGrzybkowski 99c3735
Properly clear the Booking table for Today/Upcoming tabs
AdamGrzybkowski 5ef2be3
Make sure that only date range matching today/upcoming is applied
AdamGrzybkowski e19f6d1
Improve BookingsDateRangePresets
AdamGrzybkowski c2cf448
Wrap delete and insert in one DB transaction
AdamGrzybkowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 5 additions & 24 deletions
29
...rce/src/main/kotlin/com/woocommerce/android/ui/bookings/list/BookingListFiltersBuilder.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,19 @@ | ||
| package com.woocommerce.android.ui.bookings.list | ||
|
|
||
| import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingsDateRangePresets | ||
| import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingsFilterOption | ||
| import java.time.Clock | ||
| import java.time.LocalDate | ||
| import java.time.LocalTime | ||
| import java.time.ZoneOffset | ||
| import javax.inject.Inject | ||
|
|
||
| class BookingListFiltersBuilder @Inject constructor( | ||
| private val clock: Clock | ||
| ) { | ||
| /** | ||
| * Returns a [BookingsFilterOption.DateRange] based on the selected [BookingListTab]. | ||
| * | ||
| * We use UTC for the API calls, as the API stores the dates without timezone information, which means that | ||
| * when comparing dates, they are treated as UTC times. | ||
| * See p1759398245019489-slack-C09FHQNQERG | ||
| */ | ||
| fun BookingListTab.asDateRangeFilter(): BookingsFilterOption.DateRange? { | ||
| fun todayAtMidnight() = LocalDate.now(clock).atTime(LocalTime.MIDNIGHT).atOffset(ZoneOffset.UTC).toInstant() | ||
| fun todayAtEndOfDay() = LocalDate.now(clock).atTime(LocalTime.MAX).atOffset(ZoneOffset.UTC).toInstant() | ||
|
|
||
| return when (this) { | ||
| BookingListTab.Today -> BookingsFilterOption.DateRange( | ||
| before = todayAtEndOfDay(), | ||
| after = todayAtMidnight() | ||
| ) | ||
|
|
||
| BookingListTab.Upcoming -> BookingsFilterOption.DateRange( | ||
| before = null, | ||
| after = todayAtEndOfDay() | ||
| ) | ||
|
|
||
| BookingListTab.All -> null | ||
| } | ||
| fun BookingListTab.asDateRangeFilter(): BookingsFilterOption.DateRange? = when (this) { | ||
| BookingListTab.Today -> BookingsDateRangePresets.today(clock) | ||
| BookingListTab.Upcoming -> BookingsDateRangePresets.upcoming(clock) | ||
| BookingListTab.All -> null | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
...in/org/wordpress/android/fluxc/network/rest/wpcom/wc/bookings/BookingsDateRangePresets.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings | ||
|
|
||
| import java.time.Clock | ||
| import java.time.LocalDate | ||
| import java.time.LocalTime | ||
| import java.time.ZoneOffset | ||
|
|
||
| /** | ||
| * Factory for canonical booking date range presets used across app and data layers. | ||
| * | ||
| * Notes about time zone: | ||
| * The WC Bookings API stores dates without timezone information. To ensure | ||
| * consistent comparisons and filtering on both client and server, we construct | ||
| * ranges in UTC. | ||
| * See p1759398245019489-slack-C09FHQNQERG | ||
| */ | ||
| object BookingsDateRangePresets { | ||
| /** | ||
| * Returns a DateRange that spans the current day in UTC, inclusive of the | ||
| * full day when interpreted by the API (midnight to end-of-day). | ||
| */ | ||
| fun today(clock: Clock): BookingsFilterOption.DateRange { | ||
| val start = LocalDate.now(clock) | ||
| .atTime(LocalTime.MIDNIGHT) | ||
| .atOffset(ZoneOffset.UTC) | ||
| .toInstant() | ||
| val end = LocalDate.now(clock) | ||
| .atTime(LocalTime.MAX) | ||
| .atOffset(ZoneOffset.UTC) | ||
| .toInstant() | ||
| return BookingsFilterOption.DateRange(before = end, after = start) | ||
| } | ||
|
|
||
| /** | ||
| * Returns a DateRange that includes bookings strictly after the end of the | ||
| * current day in UTC (i.e., upcoming bookings from tomorrow onwards). | ||
| * | ||
| * before = null and after = end-of-today. | ||
AdamGrzybkowski marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| fun upcoming(clock: Clock): BookingsFilterOption.DateRange { | ||
| val endOfToday = LocalDate.now(clock) | ||
| .atTime(LocalTime.MAX) | ||
| .atOffset(ZoneOffset.UTC) | ||
| .toInstant() | ||
| return BookingsFilterOption.DateRange(before = null, after = endOfToday) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.