Refactor "GMT" magic string.

This commit is contained in:
Gary Gregory 2017-10-09 14:40:43 -06:00
parent 4485491219
commit fd60085a2a
2 changed files with 34 additions and 3 deletions

View File

@ -844,7 +844,7 @@ public class FastDateParser implements DateParser, Serializable {
for (final String[] zoneNames : zones) {
// offset 0 is the time zone ID and is not localized
final String tzId = zoneNames[ID];
if (tzId.equalsIgnoreCase("GMT")) {
if (tzId.equalsIgnoreCase(TimeZones.GMT_ID)) {
continue;
}
final TimeZone tz = TimeZone.getTimeZone(tzId);
@ -889,9 +889,9 @@ public class FastDateParser implements DateParser, Serializable {
@Override
void setCalendar(final FastDateParser parser, final Calendar cal, final String timeZone) {
if (timeZone.charAt(0) == '+' || timeZone.charAt(0) == '-') {
final TimeZone tz = TimeZone.getTimeZone("GMT" + timeZone);
final TimeZone tz = TimeZone.getTimeZone(TimeZones.GMT_ID + timeZone);
cal.setTimeZone(tz);
} else if (timeZone.regionMatches(true, 0, "GMT", 0, 3)) {
} else if (timeZone.regionMatches(true, 0, TimeZones.GMT_ID, 0, 3)) {
final TimeZone tz = TimeZone.getTimeZone(timeZone.toUpperCase(Locale.ROOT));
cal.setTimeZone(tz);
} else {

View File

@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.lang3.time;
/**
* Helps to deal with {@link java.util.TimeZone}s.
*
* @since 3.7
*/
public class TimeZones {
/**
* A public version of {@link java.util.TimeZone}'s package private {@code GMT_ID} field.
*/
public static final String GMT_ID = "GMT";
}