KieronQuinn / SmartspacerPlugins

A collection of plugins for Smartspacer
GNU General Public License v3.0
79 stars 2 forks source link

[Bug] Countdown: Date picker in settings shifts 1 day back #28

Closed Yixuan-Wang closed 6 months ago

Yixuan-Wang commented 6 months ago

Select the Plugin you are reporting for

Countdown

Description

date picker settings

When you select a day in the Countdown to option, the date always shifts 1 day backwards. If you open the date picker, do nothing and press "Ok", the date will continue to shift 1 day back.

Currently I'm in UTC-6 timezone, which might be relevant to the bug.

I think the problem should be around here during Instant conversion: https://github.com/KieronQuinn/SmartspacerPlugins/blob/6983c3859c318fcee585c50757c02e70abb39d25/countdown/src/main/java/com/kieronquinn/app/smartspacer/plugin/countdown/ui/screens/configuration/ConfigurationViewModel.kt#L80C5

Yixuan-Wang commented 6 months ago

After consulting ChatGPT, I think the fix it provided should be correct. The epoch returned from the DatePicker is based on UTC, not the device's local timezone? You are in UTC+0 so this bug cannot be reproduced.

val instant = Instant.ofEpochMilli(date)
val localDate = instant.atZone(ZoneOffset.UTC).toLocalDate()
// Format the date as needed
val formattedDate = localDate.format(DateTimeFormatter.ISO_LOCAL_DATE)

updateComplicationData {
    it.copy(endDate = formattedDate)
}
KieronQuinn commented 6 months ago

Fixed in countdown v1.0.1, ChatGPT was right for once in that the timezone is indeed meant to be in UTC