forked from plusonelabs/calendar-widget
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#106: Default Time zone in app doesn't change, when Android System Ti…
…me Zone changes
- Loading branch information
Showing
5 changed files
with
22 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
/** | ||
* A clock, the can be changed independently from a Device clock | ||
* | ||
* @author [email protected] | ||
*/ | ||
public class MyClock { | ||
|
@@ -21,10 +22,16 @@ public class MyClock { | |
private volatile DateTime snapshotDate = null; | ||
private volatile DateTime snapshotDateSetAt = null; | ||
private volatile String lockedTimeZoneId = ""; | ||
private volatile DateTimeZone zone; | ||
private static volatile DateTimeZone defaultTimeZone = null; | ||
private volatile DateTimeZone zone = getDefaultTimeZone(); | ||
|
||
public MyClock() { | ||
zone = DateTimeZone.getDefault(); | ||
|
||
public static void setDefaultTimeZone(DateTimeZone zone) { | ||
defaultTimeZone = zone; | ||
} | ||
|
||
public static DateTimeZone getDefaultTimeZone() { | ||
return defaultTimeZone != null ? defaultTimeZone : DateTimeZone.forTimeZone(java.util.TimeZone.getDefault()); | ||
} | ||
|
||
public void setSnapshotMode(SnapshotMode snapshotModeIn, InstanceSettings settings) { | ||
|
@@ -47,13 +54,13 @@ public void setLockedTimeZoneId(String timeZoneId) { | |
updateZone(); | ||
} | ||
|
||
private void updateZone() { | ||
public void updateZone() { | ||
if (snapshotMode == SnapshotMode.SNAPSHOT_TIME && snapshotDate != null) { | ||
zone = snapshotDate.getZone(); | ||
} else if (StringUtil.nonEmpty(lockedTimeZoneId)) { | ||
zone = DateTimeZone.forID(lockedTimeZoneId); | ||
} else { | ||
zone = DateTimeZone.getDefault(); | ||
zone = getDefaultTimeZone(); | ||
} | ||
} | ||
|
||
|
@@ -76,8 +83,8 @@ public DateTime now(DateTimeZone zone) { | |
DateTime snapshotDate = this.snapshotDate; | ||
if (getSnapshotMode() == SnapshotMode.SNAPSHOT_TIME && snapshotDate != null) { | ||
return PermissionsUtil.isTestMode() | ||
? getTimeMachineDate(zone) | ||
: snapshotDate.withZone(zone); | ||
? getTimeMachineDate(zone) | ||
: snapshotDate.withZone(zone); | ||
} else { | ||
return DateTime.now(zone); | ||
} | ||
|
@@ -132,7 +139,7 @@ public int getNumberOfDaysTo(DateTime date) { | |
|
||
public int getNumberOfMinutesTo(DateTime date) { | ||
return Minutes.minutesBetween(now(date.getZone()), date) | ||
.getMinutes(); | ||
.getMinutes(); | ||
} | ||
|
||
public DateTime startOfTomorrow() { | ||
|