< prev index next >

src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java

Print this page
rev 57965 : 8234347: "Turkey" meta time zone does not generate composed localized names
8236548: Localized time zone name inconsistency between English and other locales
Reviewed-by:
   1 /*
   2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


4243          * Etc/GMC although both are valid.
4244          */
4245         @Override
4246         public int parse(DateTimeParseContext context, CharSequence text, int position) {
4247             int length = text.length();
4248             if (position > length) {
4249                 throw new IndexOutOfBoundsException();
4250             }
4251             if (position == length) {
4252                 return ~position;
4253             }
4254 
4255             // handle fixed time-zone IDs
4256             char nextChar = text.charAt(position);
4257             if (nextChar == '+' || nextChar == '-') {
4258                 return parseOffsetBased(context, text, position, position, OffsetIdPrinterParser.INSTANCE_ID_Z);
4259             } else if (length >= position + 2) {
4260                 char nextNextChar = text.charAt(position + 1);
4261                 if (context.charEquals(nextChar, 'U') && context.charEquals(nextNextChar, 'T')) {
4262                     if (length >= position + 3 && context.charEquals(text.charAt(position + 2), 'C')) {




4263                         return parseOffsetBased(context, text, position, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
4264                     }

4265                     return parseOffsetBased(context, text, position, position + 2, OffsetIdPrinterParser.INSTANCE_ID_ZERO);

4266                 } else if (context.charEquals(nextChar, 'G') && length >= position + 3 &&
4267                         context.charEquals(nextNextChar, 'M') && context.charEquals(text.charAt(position + 2), 'T')) {
4268                     if (length >= position + 4 && context.charEquals(text.charAt(position + 3), '0')) {
4269                         context.setParsed(ZoneId.of("GMT0"));
4270                         return position + 4;
4271                     }
4272                     return parseOffsetBased(context, text, position, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
4273                 }
4274             }
4275 
4276             // parse
4277             PrefixTree tree = getTree(context);
4278             ParsePosition ppos = new ParsePosition(position);
4279             String parsedZoneId = tree.match(text, ppos);
4280             if (parsedZoneId == null) {
4281                 if (context.charEquals(nextChar, 'Z')) {
4282                     context.setParsed(ZoneOffset.UTC);
4283                     return position + 1;
4284                 }
4285                 return ~position;


   1 /*
   2  * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


4243          * Etc/GMC although both are valid.
4244          */
4245         @Override
4246         public int parse(DateTimeParseContext context, CharSequence text, int position) {
4247             int length = text.length();
4248             if (position > length) {
4249                 throw new IndexOutOfBoundsException();
4250             }
4251             if (position == length) {
4252                 return ~position;
4253             }
4254 
4255             // handle fixed time-zone IDs
4256             char nextChar = text.charAt(position);
4257             if (nextChar == '+' || nextChar == '-') {
4258                 return parseOffsetBased(context, text, position, position, OffsetIdPrinterParser.INSTANCE_ID_Z);
4259             } else if (length >= position + 2) {
4260                 char nextNextChar = text.charAt(position + 1);
4261                 if (context.charEquals(nextChar, 'U') && context.charEquals(nextNextChar, 'T')) {
4262                     if (length >= position + 3 && context.charEquals(text.charAt(position + 2), 'C')) {
4263                         // There are localized zone texts that start with "UTC", e.g.
4264                         // "UTC\u221210:00" (MINUS SIGN instead of HYPHEN-MINUS) in French.
4265                         // Exclude those ZoneText cases.
4266                         if (!(this instanceof ZoneTextPrinterParser)) {
4267                             return parseOffsetBased(context, text, position, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
4268                         }
4269                     } else {
4270                         return parseOffsetBased(context, text, position, position + 2, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
4271                     }
4272                 } else if (context.charEquals(nextChar, 'G') && length >= position + 3 &&
4273                         context.charEquals(nextNextChar, 'M') && context.charEquals(text.charAt(position + 2), 'T')) {
4274                     if (length >= position + 4 && context.charEquals(text.charAt(position + 3), '0')) {
4275                         context.setParsed(ZoneId.of("GMT0"));
4276                         return position + 4;
4277                     }
4278                     return parseOffsetBased(context, text, position, position + 3, OffsetIdPrinterParser.INSTANCE_ID_ZERO);
4279                 }
4280             }
4281 
4282             // parse
4283             PrefixTree tree = getTree(context);
4284             ParsePosition ppos = new ParsePosition(position);
4285             String parsedZoneId = tree.match(text, ppos);
4286             if (parsedZoneId == null) {
4287                 if (context.charEquals(nextChar, 'Z')) {
4288                     context.setParsed(ZoneOffset.UTC);
4289                     return position + 1;
4290                 }
4291                 return ~position;


< prev index next >