Skip to content

Fix/datepicker utc offset#368

Open
John-Swindell wants to merge 1 commit into
mhss1:devfrom
John-Swindell:fix/datepicker-utc-offset
Open

Fix/datepicker utc offset#368
John-Swindell wants to merge 1 commit into
mhss1:devfrom
John-Swindell:fix/datepicker-utc-offset

Conversation

@John-Swindell
Copy link
Copy Markdown

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style (formatting, new lines, etc.)
  • Refactoring (no functional changes, renaming)
  • Other (describe the changes):

Checklist:

  • The PR is to the dev branch
  • My code follows the style and architecture of the project
  • I have performed a self-review of my code
  • I have tested the app on an actual Android device and everything works as expected
  • My changes generate no new warnings or errors
  • New and existing tests pass locally with my changes
  • I have commented my code, particularly in hard-to-understand areas (no, but changes is very simple)

@John-Swindell John-Swindell force-pushed the fix/datepicker-utc-offset branch from a02b8ab to c3375f6 Compare April 20, 2026 12:43
Adds Long.utcDateAt(hours, minutes) to read the year, month, and day in UTC and reassemble a local-timezone instant. Fixes mhss1#252, mhss1#293, mhss1#305.
@John-Swindell John-Swindell force-pushed the fix/datepicker-utc-offset branch from c3375f6 to ddecf8b Compare April 20, 2026 12:51
onDatePicked: (Long) -> Unit,
) {
val datePickerState = rememberDatePickerState(
initialSelectedDateMillis = initialDate
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants