Skip to content

Commit 10ed2e6

Browse files
Merge pull request #14686 from woocommerce/issue/WOOMOB-1404-bookings-date-updates
[CIAB Bookings] Update logic of tabs filtering
2 parents 36df697 + 388529f commit 10ed2e6

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/bookings/list/BookingListFiltersBuilder.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@ package com.woocommerce.android.ui.bookings.list
22

33
import org.wordpress.android.fluxc.network.rest.wpcom.wc.bookings.BookingsFilterOption
44
import java.time.Clock
5-
import java.time.Instant
5+
import java.time.LocalDate
66
import java.time.LocalTime
7-
import java.time.ZonedDateTime
7+
import java.time.ZoneOffset
88
import javax.inject.Inject
99

1010
class BookingListFiltersBuilder @Inject constructor(
1111
private val clock: Clock
1212
) {
13+
/**
14+
* Returns a [BookingsFilterOption.DateRange] based on the selected [BookingListTab].
15+
*
16+
* We use UTC for the API calls, as the API stores the dates without timezone information, which means that
17+
* when comparing dates, they are treated as UTC times.
18+
* See p1759398245019489-slack-C09FHQNQERG
19+
*/
1320
fun BookingListTab.asDateRangeFilter(): BookingsFilterOption.DateRange? {
21+
fun todayAtMidnight() = LocalDate.now(clock).atTime(LocalTime.MIDNIGHT).atOffset(ZoneOffset.UTC).toInstant()
22+
fun todayAtEndOfDay() = LocalDate.now(clock).atTime(LocalTime.MAX).atOffset(ZoneOffset.UTC).toInstant()
23+
1424
return when (this) {
1525
BookingListTab.Today -> BookingsFilterOption.DateRange(
16-
before = ZonedDateTime.now(clock).with(LocalTime.MAX).toInstant(),
17-
after = ZonedDateTime.now(clock).with(LocalTime.MIN).toInstant()
26+
before = todayAtEndOfDay(),
27+
after = todayAtMidnight()
1828
)
1929

2030
BookingListTab.Upcoming -> BookingsFilterOption.DateRange(
2131
before = null,
22-
after = Instant.now(clock)
32+
after = todayAtEndOfDay()
2333
)
2434

2535
BookingListTab.All -> null

WooCommerce/src/test/kotlin/com/woocommerce/android/ui/bookings/list/BookingListFilterBuilderTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class BookingListFilterBuilderTest {
2121
}
2222

2323
assertThat(filter).isNotNull()
24-
assertThat(filter?.after).isEqualTo(Instant.parse("2025-01-01T00:00:00+02:00"))
25-
assertThat(filter?.before).isEqualTo(Instant.parse("2025-01-01T23:59:59.999999999+02:00"))
24+
assertThat(filter?.after).isEqualTo(Instant.parse("2025-01-01T00:00:00+00:00"))
25+
assertThat(filter?.before).isEqualTo(Instant.parse("2025-01-01T23:59:59.999999999+00:00"))
2626
}
2727

2828
@Test
@@ -32,7 +32,7 @@ class BookingListFilterBuilderTest {
3232
}
3333

3434
assertThat(filter).isNotNull()
35-
assertThat(filter?.after).isEqualTo(mockedNow)
35+
assertThat(filter?.after).isEqualTo(Instant.parse("2025-01-01T23:59:59.999999999+00:00"))
3636
assertThat(filter?.before).isNull()
3737
}
3838

0 commit comments

Comments
 (0)