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

Fix bug when changing TimeZone of the device #622

Merged
merged 4 commits into from
Jun 25, 2018
Merged
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 @@ -16,6 +16,7 @@
import java.util.Calendar;
import java.util.Collection;
import java.util.List;
import java.util.TimeZone;

import static com.prolificinteractive.materialcalendarview.MaterialCalendarView.SHOW_DEFAULTS;
import static com.prolificinteractive.materialcalendarview.MaterialCalendarView.showOtherMonths;
Expand All @@ -27,6 +28,7 @@ abstract class CalendarPagerView extends ViewGroup implements View.OnClickListen
protected static final int DEFAULT_MAX_WEEKS = 6;
protected static final int DAY_NAMES_ROW = 1;
private static final Calendar tempWorkingCalendar = CalendarUtils.getInstance();
private static final String TIME_ZONE_DEFAULT = "UTC";
private final ArrayList<WeekDayView> weekDayViews = new ArrayList<>();
private final ArrayList<DecoratorResult> decoratorResults = new ArrayList<>();
@ShowOtherDates
Expand All @@ -50,6 +52,15 @@ public CalendarPagerView(@NonNull MaterialCalendarView view,
this.firstDayOfWeek = firstDayOfWeek;
this.showWeekDays = showWeekDays;

/*
* Set the defaultTimeZone to avoid wrong calculations that are positioning the last day of the
* previous month on the first day of the current month when changing the TimeZone of the device
*
* It's recommended that when manipulating Date objects that TimeZone could change according to
* device configuration to use a default TimeZone to do the calculations.
*/
TimeZone.setDefault(TimeZone.getTimeZone(TIME_ZONE_DEFAULT));

setClipChildren(false);
setClipToPadding(false);

Expand Down