Fix/datepicker utc offset#368
Open
John-Swindell wants to merge 1 commit into
Open
Conversation
a02b8ab to
c3375f6
Compare
c3375f6 to
ddecf8b
Compare
mhss1
requested changes
May 31, 2026
| onDatePicked: (Long) -> Unit, | ||
| ) { | ||
| val datePickerState = rememberDatePickerState( | ||
| initialSelectedDateMillis = initialDate |
Owner
There was a problem hiding this comment.
I think we still need set the date pickers (this and the one in DateDialog) to UTC midnight.
will need another utility function like this in DateUtils
fun Long.toUtcMidnight(): Long {
val date = this.localDateTime.date
return LocalDateTime(
year = date.year,
month = date.month,
day = date.day,
hour = 0,
minute = 0,
second = 0,
nanosecond = 0
).toInstant(TimeZone.UTC).toEpochMilliseconds()
}
Suggested change
| initialSelectedDateMillis = initialDate.toUtcMidnight() |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Please include a summary of the changes and the related issue.
Fix date picker off-by-one for users west of UTC
Material3 DatePicker returns selectedDateMillis as UTC midnight of the chosen date. The old code called Long.at(hour, minute), which reinterprets the millis in the local timezone. For users west of UTC that rolls the date back one day (and for users east it shifts the stored time), so picking April 20 saved April 19, and setting a task due date for tomorrow silently reverted to today.
Added Long.utcDateAt(hours, minutes) that reads the year, month, and day in UTC and reassembles a local-timezone instant at the given time. DateDialog and DateTimeDialog now use utcDateAt on the picker output. This affects calendar event start and end dates, task due dates, and diary entries.
Fixes #252, #293, #305
Type of change
Checklist:
devbranch