diff options
author | Elliott Hughes <enh@google.com> | 2012-09-06 15:30:51 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2012-09-06 15:42:09 -0700 |
commit | 6c7f55ee4b73d0131103f10211fdbe3742b41cbb (patch) | |
tree | c65ec487ea9c1246f5c3aa6d2c9c77b5da3580b7 /src/com/android/settings/DateTimeSettings.java | |
parent | 33f8619677393d3d15fcb25784985009af5d7bbd (diff) | |
download | packages_apps_Settings-6c7f55ee4b73d0131103f10211fdbe3742b41cbb.zip packages_apps_Settings-6c7f55ee4b73d0131103f10211fdbe3742b41cbb.tar.gz packages_apps_Settings-6c7f55ee4b73d0131103f10211fdbe3742b41cbb.tar.bz2 |
Stop using getDSTSavings.
The original code was actually correct, but code calling inDaylightTime
and getDSTSavings directly is inherently suspect, so I want to clean up
this false positive along with the real abusers.
Bug: 6901488
Change-Id: I6c89e7aa29d88b81ed2c7fd6c915e0346b90a442
Diffstat (limited to 'src/com/android/settings/DateTimeSettings.java')
-rw-r--r-- | src/com/android/settings/DateTimeSettings.java | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/src/com/android/settings/DateTimeSettings.java b/src/com/android/settings/DateTimeSettings.java index 9586933..30d4f0a 100644 --- a/src/com/android/settings/DateTimeSettings.java +++ b/src/com/android/settings/DateTimeSettings.java @@ -337,8 +337,6 @@ public class DateTimeSettings extends SettingsPreferenceFragment } } - /* Helper routines to format timezone */ - /* package */ static void setDate(int year, int month, int day) { Calendar c = Calendar.getInstance(); @@ -366,45 +364,40 @@ public class DateTimeSettings extends SettingsPreferenceFragment } } - /* package */ static String getTimeZoneText(TimeZone tz) { - boolean daylight = tz.inDaylightTime(new Date()); - StringBuilder sb = new StringBuilder(); + /* Helper routines to format timezone */ - sb.append(formatOffset(tz.getRawOffset() + - (daylight ? tz.getDSTSavings() : 0))). + /* package */ static String getTimeZoneText(TimeZone tz) { + // Similar to new SimpleDateFormat("'GMT'Z, zzzz").format(new Date()), but + // we want "GMT-03:00" rather than "GMT-0300". + Date now = new Date(); + return formatOffset(new StringBuilder(), tz, now). append(", "). - append(tz.getDisplayName(daylight, TimeZone.LONG)); - - return sb.toString(); + append(tz.getDisplayName(tz.inDaylightTime(now), TimeZone.LONG)).toString(); } - private static char[] formatOffset(int off) { - off = off / 1000 / 60; - - char[] buf = new char[9]; - buf[0] = 'G'; - buf[1] = 'M'; - buf[2] = 'T'; + private static StringBuilder formatOffset(StringBuilder sb, TimeZone tz, Date d) { + int off = tz.getOffset(d.getTime()) / 1000 / 60; + sb.append("GMT"); if (off < 0) { - buf[3] = '-'; + sb.append('-'); off = -off; } else { - buf[3] = '+'; + sb.append('+'); } int hours = off / 60; int minutes = off % 60; - buf[4] = (char) ('0' + hours / 10); - buf[5] = (char) ('0' + hours % 10); + sb.append((char) ('0' + hours / 10)); + sb.append((char) ('0' + hours % 10)); - buf[6] = ':'; + sb.append(':'); - buf[7] = (char) ('0' + minutes / 10); - buf[8] = (char) ('0' + minutes % 10); + sb.append((char) ('0' + minutes / 10)); + sb.append((char) ('0' + minutes % 10)); - return buf; + return sb; } private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |