Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ import org.thoughtcrime.securesms.wallpaper.ChatWallpaperDimLevelUtil
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZoneOffset
import java.util.Locale
import java.util.Optional
import java.util.concurrent.ExecutionException
Expand Down Expand Up @@ -5247,7 +5248,7 @@ class ConversationFragment :
datePicker.addOnPositiveButtonClickListener { selectedDate ->
if (selectedDate != null) {
val localMidnightTimestamp = Instant.ofEpochMilli(selectedDate)
.atZone(ZoneId.systemDefault())
.atZone(ZoneOffset.UTC)
.toLocalDate()
.atStartOfDay(ZoneId.systemDefault())
.toInstant()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import java.time.Instant
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZoneOffset
import java.time.temporal.TemporalAdjusters
import java.util.concurrent.Executor
import kotlin.time.Duration.Companion.days
Expand Down Expand Up @@ -105,7 +106,7 @@ class JumpToDateValidator private constructor(

private fun normalizeToLocalMidnight(timestamp: Long): Long {
return Instant.ofEpochMilli(timestamp)
.atZone(zoneId)
.atZone(ZoneOffset.UTC)
.toLocalDate()
.atStartOfDay(zoneId)
.toInstant()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,27 @@ class JumpToDateValidatorTest {

assertThat(validator.isValid(june15Utc)).isTrue()
}

@Test
fun `picker date maps to the same calendar day in a negative-offset zone`() {
val newYorkZone = ZoneId.of("America/New_York")

// Days are keyed by local midnight in the database.
val june15NewYorkMidnight = LocalDate.of(2024, 6, 15)
.atStartOfDay(newYorkZone)
.toInstant()
.toEpochMilli()

val lookup = { dates: Collection<Long> ->
dates.associateWith { it == june15NewYorkMidnight }
}
val validator = createValidator(lookup, zone = newYorkZone)

// The picker reports June 15 as UTC midnight; it must map to June 15 locally, not June 14.
val june15PickerUtc = timestampForDate(2024, 6, 15)

validator.isValid(june15PickerUtc)

assertThat(validator.isValid(june15PickerUtc)).isTrue()
}
}