Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time zone changes lead to misinterpretation of times #15

Open
Kumpewo opened this issue May 18, 2020 · 0 comments
Open

Time zone changes lead to misinterpretation of times #15

Kumpewo opened this issue May 18, 2020 · 0 comments

Comments

@Kumpewo
Copy link

Kumpewo commented May 18, 2020

In TimePickerPreference.java a static SimpleDateFormat FORMAT is defined which saves the local time zone at creation time (line 49) for the entire application process lifetime.
This format is used to parse a time String into a Date object (receives the time zone from FORMAT, line 240) and then the result is assigned to a newly instantiated Calendar object (that has the current local time zone, line 277).
When the System's time zone changes between storing a time String into SharedPreferences and recovering it from SharedPreferences while the application process is still running, then the hours (and probably minutes) are shifted to the new System time zone.
It only happens under very special circumstances, for example if you have an AppWidget and therefore a permanently running process - but that is exactly my use case of your fabulous Preference.

Suggestion to solve the issue: instead of using a static fixed FORMAT have a static method
public static getFORMAT() { return new SimpleDateFormat(PATTERN, Locale.US); }
Then you'll always have a format residing in the current time zone as the Calendar objects do.

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

No branches or pull requests

1 participant