Reuse constant TimeZones.GMT_ID.

This commit is contained in:
Gary Gregory 2021-08-31 10:38:21 -04:00
parent f8e225cf46
commit c267e39091
4 changed files with 13 additions and 10 deletions

View File

@ -45,10 +45,13 @@ class GmtTimeZone extends TimeZone {
} }
final int milliseconds = (minutes + (hours * MINUTES_PER_HOUR)) * MILLISECONDS_PER_MINUTE; final int milliseconds = (minutes + (hours * MINUTES_PER_HOUR)) * MILLISECONDS_PER_MINUTE;
offset = negate ? -milliseconds : milliseconds; offset = negate ? -milliseconds : milliseconds;
zoneId = twoDigits( // @formatter:off
twoDigits(new StringBuilder(9).append("GMT").append(negate ? '-' : '+'), hours) zoneId = twoDigits(twoDigits(new StringBuilder(9)
.append(':'), minutes).toString(); .append(TimeZones.GMT_ID)
.append(negate ? '-' : '+'), hours)
.append(':'), minutes)
.toString();
// @formatter:on
} }
private static StringBuilder twoDigits(final StringBuilder sb, final int n) { private static StringBuilder twoDigits(final StringBuilder sb, final int n) {

View File

@ -90,7 +90,7 @@ public class FastDateParserTest {
private static final TimeZone REYKJAVIK = TimeZone.getTimeZone("Atlantic/Reykjavik"); private static final TimeZone REYKJAVIK = TimeZone.getTimeZone("Atlantic/Reykjavik");
private static final TimeZone NEW_YORK = TimeZone.getTimeZone("America/New_York"); private static final TimeZone NEW_YORK = TimeZone.getTimeZone("America/New_York");
static final TimeZone GMT = TimeZone.getTimeZone("GMT"); static final TimeZone GMT = TimeZone.getTimeZone(TimeZones.GMT_ID);
private static final TimeZone INDIA = TimeZone.getTimeZone("Asia/Calcutta"); private static final TimeZone INDIA = TimeZone.getTimeZone("Asia/Calcutta");
private static final Locale SWEDEN = new Locale("sv", "SE"); private static final Locale SWEDEN = new Locale("sv", "SE");

View File

@ -60,7 +60,7 @@ public class FastDatePrinterTest {
} }
private static final String YYYY_MM_DD = "yyyy/MM/dd"; private static final String YYYY_MM_DD = "yyyy/MM/dd";
private static final TimeZone NEW_YORK = TimeZone.getTimeZone("America/New_York"); private static final TimeZone NEW_YORK = TimeZone.getTimeZone("America/New_York");
private static final TimeZone GMT = TimeZone.getTimeZone("GMT"); private static final TimeZone GMT = TimeZone.getTimeZone(TimeZones.GMT_ID);
private static final TimeZone INDIA = TimeZone.getTimeZone("Asia/Calcutta"); private static final TimeZone INDIA = TimeZone.getTimeZone("Asia/Calcutta");
private static final Locale SWEDEN = new Locale("sv", "SE"); private static final Locale SWEDEN = new Locale("sv", "SE");
@ -126,7 +126,7 @@ public class FastDatePrinterTest {
@Test @Test
public void testAppendableOptions() { public void testAppendableOptions() {
final DatePrinter format = getInstance("yyyy-MM-dd HH:mm:ss.SSS Z", TimeZone.getTimeZone("GMT")); final DatePrinter format = getInstance("yyyy-MM-dd HH:mm:ss.SSS Z", TimeZone.getTimeZone(TimeZones.GMT_ID));
final Calendar calendar = Calendar.getInstance(); final Calendar calendar = Calendar.getInstance();
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
final String expected = format.format(calendar, sb).toString(); final String expected = format.format(calendar, sb).toString();
@ -262,7 +262,7 @@ public class FastDatePrinterTest {
cal.clear(); cal.clear();
cal.set(2009, Calendar.OCTOBER, 16, 8, 42, 16); cal.set(2009, Calendar.OCTOBER, 16, 8, 42, 16);
final DatePrinter format = getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("GMT")); final DatePrinter format = getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone(TimeZones.GMT_ID));
assertEquals("2009-10-16T16:42:16.000Z", format.format(cal.getTime()), "dateTime"); assertEquals("2009-10-16T16:42:16.000Z", format.format(cal.getTime()), "dateTime");
assertEquals("2009-10-16T16:42:16.000Z", format.format(cal), "dateTime"); assertEquals("2009-10-16T16:42:16.000Z", format.format(cal), "dateTime");
} }
@ -387,7 +387,7 @@ public class FastDatePrinterTest {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Test @Test
public void testStringBufferOptions() { public void testStringBufferOptions() {
final DatePrinter format = getInstance("yyyy-MM-dd HH:mm:ss.SSS Z", TimeZone.getTimeZone("GMT")); final DatePrinter format = getInstance("yyyy-MM-dd HH:mm:ss.SSS Z", TimeZone.getTimeZone(TimeZones.GMT_ID));
final Calendar calendar = Calendar.getInstance(); final Calendar calendar = Calendar.getInstance();
final StringBuffer sb = new StringBuffer(); final StringBuffer sb = new StringBuffer();
final String expected = format.format(calendar, sb, new FieldPosition(0)).toString(); final String expected = format.format(calendar, sb, new FieldPosition(0)).toString();

View File

@ -34,7 +34,7 @@ public class FastTimeZoneTest {
@Test @Test
public void testBareGmt() { public void testBareGmt() {
assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone("GMT")); assertEquals(FastTimeZone.getGmtTimeZone(), FastTimeZone.getTimeZone(TimeZones.GMT_ID));
} }
@Test @Test