src/java.base/share/classes/java/text/SimpleDateFormat.java
author jboes
Fri, 20 Sep 2019 11:07:52 +0100
changeset 58242 94bb65cb37d3
parent 57956 e0b8b019d2f5
child 58288 48e480e56aad
permissions -rw-r--r--
8230648: Replace @exception tag with @throws in java.base Summary: Minor coding style update of javadoc tag in any file in java.base Reviewed-by: prappo, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53431
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
     2
 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5283
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5283
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5283
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5283
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5283
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996-1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *   The original version of this source code and documentation is copyrighted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * materials are provided under terms of a License Agreement between Taligent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * and Sun. This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * patents. This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *   Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
package java.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.InvalidObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.ObjectInputStream;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
    44
import static java.text.DateFormatSymbols.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.Calendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.GregorianCalendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.SimpleTimeZone;
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
    51
import java.util.SortedMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.TimeZone;
7003
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6497
diff changeset
    53
import java.util.concurrent.ConcurrentHashMap;
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6497
diff changeset
    54
import java.util.concurrent.ConcurrentMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.util.calendar.CalendarUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.util.calendar.ZoneInfoFile;
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
    57
import sun.util.locale.provider.LocaleProviderAdapter;
49904
cadca99d52e7 8181157: CLDR Timezone name fallback implementation
naoto
parents: 48251
diff changeset
    58
import sun.util.locale.provider.TimeZoneNameUtility;
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
    59
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <code>SimpleDateFormat</code> is a concrete class for formatting and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * parsing dates in a locale-sensitive manner. It allows for formatting
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 18146
diff changeset
    63
 * (date &rarr; text), parsing (text &rarr; date), and normalization.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <code>SimpleDateFormat</code> allows you to start by choosing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * any user-defined patterns for date-time formatting. However, you
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * are encouraged to create a date-time formatter with either
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <code>getTimeInstance</code>, <code>getDateInstance</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <code>getDateTimeInstance</code> in <code>DateFormat</code>. Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * of these class methods can return a date/time formatter initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * with a default format pattern. You may modify the format pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * using the <code>applyPattern</code> methods as desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * For more information on using these methods, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * {@link DateFormat}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 53431
diff changeset
    77
 * <h2>Date and Time Patterns</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Date and time formats are specified by <em>date and time pattern</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * Within date and time pattern strings, unquoted letters from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <code>'A'</code> to <code>'Z'</code> and from <code>'a'</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <code>'z'</code> are interpreted as pattern letters representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * components of a date or time string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * Text can be quoted using single quotes (<code>'</code>) to avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * interpretation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <code>"''"</code> represents a single quote.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * All other characters are not interpreted; they're simply copied into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * output string during formatting or matched against the input string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * during parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * The following pattern letters are defined (all other characters from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * <code>'A'</code> to <code>'Z'</code> and from <code>'a'</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <code>'z'</code> are reserved):
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <blockquote>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
    96
 * <table class="striped">
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
    97
 * <caption style="display:none">Chart shows pattern letters, date/time component, presentation, and examples.</caption>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
    98
 * <thead>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
    99
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   100
 *         <th scope="col" style="text-align:left">Letter
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   101
 *         <th scope="col" style="text-align:left">Date or Time Component
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   102
 *         <th scope="col" style="text-align:left">Presentation
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   103
 *         <th scope="col" style="text-align:left">Examples
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   104
 * </thead>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   105
 * <tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   107
 *         <th scope="row"><code>G</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *         <td>Era designator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *         <td><a href="#text">Text</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *         <td><code>AD</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   111
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   112
 *         <th scope="row"><code>y</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *         <td>Year
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *         <td><a href="#year">Year</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *         <td><code>1996</code>; <code>96</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   117
 *         <th scope="row"><code>Y</code>
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   118
 *         <td>Week year
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   119
 *         <td><a href="#year">Year</a>
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   120
 *         <td><code>2009</code>; <code>09</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   121
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   122
 *         <th scope="row"><code>M</code>
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   123
 *         <td>Month in year (context sensitive)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *         <td><a href="#month">Month</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *         <td><code>July</code>; <code>Jul</code>; <code>07</code>
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   126
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   127
 *         <th scope="row"><code>L</code>
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   128
 *         <td>Month in year (standalone form)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   129
 *         <td><a href="#month">Month</a>
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   130
 *         <td><code>July</code>; <code>Jul</code>; <code>07</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   131
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   132
 *         <th scope="row"><code>w</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *         <td>Week in year
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *         <td><a href="#number">Number</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *         <td><code>27</code>
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   136
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   137
 *         <th scope="row"><code>W</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *         <td>Week in month
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *         <td><a href="#number">Number</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 *         <td><code>2</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   141
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   142
 *         <th scope="row"><code>D</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 *         <td>Day in year
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 *         <td><a href="#number">Number</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *         <td><code>189</code>
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   146
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   147
 *         <th scope="row"><code>d</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *         <td>Day in month
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *         <td><a href="#number">Number</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *         <td><code>10</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   151
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   152
 *         <th scope="row"><code>F</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *         <td>Day of week in month
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *         <td><a href="#number">Number</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *         <td><code>2</code>
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   156
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   157
 *         <th scope="row"><code>E</code>
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   158
 *         <td>Day name in week
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *         <td><a href="#text">Text</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *         <td><code>Tuesday</code>; <code>Tue</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   161
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   162
 *         <th scope="row"><code>u</code>
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   163
 *         <td>Day number of week (1 = Monday, ..., 7 = Sunday)
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   164
 *         <td><a href="#number">Number</a>
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   165
 *         <td><code>1</code>
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   166
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   167
 *         <th scope="row"><code>a</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *         <td>Am/pm marker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *         <td><a href="#text">Text</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *         <td><code>PM</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   171
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   172
 *         <th scope="row"><code>H</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 *         <td>Hour in day (0-23)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 *         <td><a href="#number">Number</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 *         <td><code>0</code>
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   176
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   177
 *         <th scope="row"><code>k</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 *         <td>Hour in day (1-24)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 *         <td><a href="#number">Number</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 *         <td><code>24</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   181
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   182
 *         <th scope="row"><code>K</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 *         <td>Hour in am/pm (0-11)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 *         <td><a href="#number">Number</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 *         <td><code>0</code>
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   186
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   187
 *         <th scope="row"><code>h</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 *         <td>Hour in am/pm (1-12)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 *         <td><a href="#number">Number</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 *         <td><code>12</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   191
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   192
 *         <th scope="row"><code>m</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 *         <td>Minute in hour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 *         <td><a href="#number">Number</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 *         <td><code>30</code>
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   196
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   197
 *         <th scope="row"><code>s</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 *         <td>Second in minute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 *         <td><a href="#number">Number</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 *         <td><code>55</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   201
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   202
 *         <th scope="row"><code>S</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 *         <td>Millisecond
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 *         <td><a href="#number">Number</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 *         <td><code>978</code>
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   206
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   207
 *         <th scope="row"><code>z</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 *         <td>Time zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 *         <td><a href="#timezone">General time zone</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 *         <td><code>Pacific Standard Time</code>; <code>PST</code>; <code>GMT-08:00</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   211
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   212
 *         <th scope="row"><code>Z</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 *         <td>Time zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 *         <td><a href="#rfc822timezone">RFC 822 time zone</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 *         <td><code>-0800</code>
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   216
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   217
 *         <th scope="row"><code>X</code>
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   218
 *         <td>Time zone
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   219
 *         <td><a href="#iso8601timezone">ISO 8601 time zone</a>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   220
 *         <td><code>-08</code>; <code>-0800</code>;  <code>-08:00</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   221
 * </tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 * Pattern letters are usually repeated, as their number determines the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * exact presentation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * <ul>
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 43011
diff changeset
   227
 * <li><strong><a id="text">Text:</a></strong>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 *     For formatting, if the number of pattern letters is 4 or more,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 *     the full form is used; otherwise a short or abbreviated form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 *     is used if available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 *     For parsing, both forms are accepted, independent of the number
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   232
 *     of pattern letters.<br><br></li>
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 43011
diff changeset
   233
 * <li><strong><a id="number">Number:</a></strong>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 *     For formatting, the number of pattern letters is the minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 *     number of digits, and shorter numbers are zero-padded to this amount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 *     For parsing, the number of pattern letters is ignored unless
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   237
 *     it's needed to separate two adjacent fields.<br><br></li>
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 43011
diff changeset
   238
 * <li><strong><a id="year">Year:</a></strong>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 *     If the formatter's {@link #getCalendar() Calendar} is the Gregorian
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 *     calendar, the following rules are applied.<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 *     <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 *     <li>For formatting, if the number of pattern letters is 2, the year
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 *         is truncated to 2 digits; otherwise it is interpreted as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 *         <a href="#number">number</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 *     <li>For parsing, if the number of pattern letters is more than 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 *         the year is interpreted literally, regardless of the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 *         digits. So using the pattern "MM/dd/yyyy", "01/11/12" parses to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 *         Jan 11, 12 A.D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 *     <li>For parsing with the abbreviated year pattern ("y" or "yy"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 *         <code>SimpleDateFormat</code> must interpret the abbreviated year
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 *         relative to some century.  It does this by adjusting dates to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 *         within 80 years before and 20 years after the time the <code>SimpleDateFormat</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 *         instance is created. For example, using a pattern of "MM/dd/yy" and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 *         <code>SimpleDateFormat</code> instance created on Jan 1, 1997,  the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 *         "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 *         would be interpreted as May 4, 1964.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 *         During parsing, only strings consisting of exactly two digits, as defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 *         {@link Character#isDigit(char)}, will be parsed into the default century.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 *         Any other numeric string, such as a one digit string, a three or more digit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 *         string, or a two digit string that isn't all digits (for example, "-1"), is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 *         interpreted literally.  So "01/02/3" or "01/02/003" are parsed, using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 *         same pattern, as Jan 2, 3 AD.  Likewise, "01/02/-3" is parsed as Jan 2, 4 BC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 *     </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 *     Otherwise, calendar system specific forms are applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 *     For both formatting and parsing, if the number of pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 *     letters is 4 or more, a calendar specific {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 *     Calendar#LONG long form} is used. Otherwise, a calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 *     specific {@linkplain Calendar#SHORT short or abbreviated form}
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   269
 *     is used.<br>
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   270
 *     <br>
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   271
 *     If week year {@code 'Y'} is specified and the {@linkplain
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   272
 *     #getCalendar() calendar} doesn't support any <a
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   273
 *     href="../util/GregorianCalendar.html#week_year"> week
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   274
 *     years</a>, the calendar year ({@code 'y'}) is used instead. The
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   275
 *     support of week years can be tested with a call to {@link
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   276
 *     DateFormat#getCalendar() getCalendar()}.{@link
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   277
 *     java.util.Calendar#isWeekDateSupported()
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   278
 *     isWeekDateSupported()}.<br><br></li>
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 43011
diff changeset
   279
 * <li><strong><a id="month">Month:</a></strong>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 *     If the number of pattern letters is 3 or more, the month is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 *     interpreted as <a href="#text">text</a>; otherwise,
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   282
 *     it is interpreted as a <a href="#number">number</a>.<br>
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   283
 *     <ul>
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   284
 *     <li>Letter <em>M</em> produces context-sensitive month names, such as the
39490
1450367e1082 8055900: j.t.SimpleDateFormat spec needs to be clarified regarding month patterns
nishjain
parents: 38750
diff changeset
   285
 *         embedded form of names. Letter <em>M</em> is context-sensitive in the
1450367e1082 8055900: j.t.SimpleDateFormat spec needs to be clarified regarding month patterns
nishjain
parents: 38750
diff changeset
   286
 *         sense that when it is used in the standalone pattern, for example,
1450367e1082 8055900: j.t.SimpleDateFormat spec needs to be clarified regarding month patterns
nishjain
parents: 38750
diff changeset
   287
 *         "MMMM", it gives the standalone form of a month name and when it is
1450367e1082 8055900: j.t.SimpleDateFormat spec needs to be clarified regarding month patterns
nishjain
parents: 38750
diff changeset
   288
 *         used in the pattern containing other field(s), for example, "d MMMM",
1450367e1082 8055900: j.t.SimpleDateFormat spec needs to be clarified regarding month patterns
nishjain
parents: 38750
diff changeset
   289
 *         it gives the format form of a month name. For example, January in the
1450367e1082 8055900: j.t.SimpleDateFormat spec needs to be clarified regarding month patterns
nishjain
parents: 38750
diff changeset
   290
 *         Catalan language is "de gener" in the format form while it is "gener"
1450367e1082 8055900: j.t.SimpleDateFormat spec needs to be clarified regarding month patterns
nishjain
parents: 38750
diff changeset
   291
 *         in the standalone form. In this case, "MMMM" will produce "gener" and
1450367e1082 8055900: j.t.SimpleDateFormat spec needs to be clarified regarding month patterns
nishjain
parents: 38750
diff changeset
   292
 *         the month part of the "d MMMM" will produce "de gener". If a
1450367e1082 8055900: j.t.SimpleDateFormat spec needs to be clarified regarding month patterns
nishjain
parents: 38750
diff changeset
   293
 *         {@code DateFormatSymbols} has been set explicitly with constructor
1450367e1082 8055900: j.t.SimpleDateFormat spec needs to be clarified regarding month patterns
nishjain
parents: 38750
diff changeset
   294
 *         {@link #SimpleDateFormat(String,DateFormatSymbols)} or method {@link
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   295
 *         #setDateFormatSymbols(DateFormatSymbols)}, the month names given by
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   296
 *         the {@code DateFormatSymbols} are used.</li>
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   297
 *     <li>Letter <em>L</em> produces the standalone form of month names.</li>
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   298
 *     </ul>
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   299
 *     <br></li>
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 43011
diff changeset
   300
 * <li><strong><a id="timezone">General time zone:</a></strong>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 *     Time zones are interpreted as <a href="#text">text</a> if they have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 *     names. For time zones representing a GMT offset value, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 *     following syntax is used:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 *     <pre>
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 43011
diff changeset
   305
 *     <a id="GMTOffsetTimeZone"><i>GMTOffsetTimeZone:</i></a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 *             <code>GMT</code> <i>Sign</i> <i>Hours</i> <code>:</code> <i>Minutes</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 *     <i>Sign:</i> one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 *             <code>+ -</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
 *     <i>Hours:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
 *             <i>Digit</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
 *             <i>Digit</i> <i>Digit</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
 *     <i>Minutes:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 *             <i>Digit</i> <i>Digit</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
 *     <i>Digit:</i> one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
 *             <code>0 1 2 3 4 5 6 7 8 9</code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
 *     <i>Hours</i> must be between 0 and 23, and <i>Minutes</i> must be between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
 *     00 and 59. The format is locale independent and digits must be taken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
 *     from the Basic Latin block of the Unicode standard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
 *     <p>For parsing, <a href="#rfc822timezone">RFC 822 time zones</a> are also
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   320
 *     accepted.<br><br></li>
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 43011
diff changeset
   321
 * <li><strong><a id="rfc822timezone">RFC 822 time zone:</a></strong>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
 *     For formatting, the RFC 822 4-digit time zone format is used:
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   323
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
 *     <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
 *     <i>RFC822TimeZone:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
 *             <i>Sign</i> <i>TwoDigitHours</i> <i>Minutes</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
 *     <i>TwoDigitHours:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 *             <i>Digit Digit</i></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 *     <i>TwoDigitHours</i> must be between 00 and 23. Other definitions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
 *     are as for <a href="#timezone">general time zones</a>.
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   331
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 *     <p>For parsing, <a href="#timezone">general time zones</a> are also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 *     accepted.
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 43011
diff changeset
   334
 * <li><strong><a id="iso8601timezone">ISO 8601 Time zone:</a></strong>
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   335
 *     The number of pattern letters designates the format for both formatting
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   336
 *     and parsing as follows:
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   337
 *     <pre>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   338
 *     <i>ISO8601TimeZone:</i>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   339
 *             <i>OneLetterISO8601TimeZone</i>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   340
 *             <i>TwoLetterISO8601TimeZone</i>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   341
 *             <i>ThreeLetterISO8601TimeZone</i>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   342
 *     <i>OneLetterISO8601TimeZone:</i>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   343
 *             <i>Sign</i> <i>TwoDigitHours</i>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   344
 *             {@code Z}
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   345
 *     <i>TwoLetterISO8601TimeZone:</i>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   346
 *             <i>Sign</i> <i>TwoDigitHours</i> <i>Minutes</i>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   347
 *             {@code Z}
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   348
 *     <i>ThreeLetterISO8601TimeZone:</i>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   349
 *             <i>Sign</i> <i>TwoDigitHours</i> {@code :} <i>Minutes</i>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   350
 *             {@code Z}</pre>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   351
 *     Other definitions are as for <a href="#timezone">general time zones</a> or
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   352
 *     <a href="#rfc822timezone">RFC 822 time zones</a>.
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   353
 *
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   354
 *     <p>For formatting, if the offset value from GMT is 0, {@code "Z"} is
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   355
 *     produced. If the number of pattern letters is 1, any fraction of an hour
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   356
 *     is ignored. For example, if the pattern is {@code "X"} and the time zone is
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   357
 *     {@code "GMT+05:30"}, {@code "+05"} is produced.
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   358
 *
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   359
 *     <p>For parsing, {@code "Z"} is parsed as the UTC time zone designator.
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   360
 *     <a href="#timezone">General time zones</a> are <em>not</em> accepted.
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   361
 *
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   362
 *     <p>If the number of pattern letters is 4 or more, {@link
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   363
 *     IllegalArgumentException} is thrown when constructing a {@code
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   364
 *     SimpleDateFormat} or {@linkplain #applyPattern(String) applying a
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   365
 *     pattern}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 * <code>SimpleDateFormat</code> also supports <em>localized date and time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 * pattern</em> strings. In these strings, the pattern letters described above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
 * may be replaced with other, locale dependent, pattern letters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
 * <code>SimpleDateFormat</code> does not deal with the localization of text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
 * other than the pattern letters; that's up to the client of the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
 *
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 53431
diff changeset
   373
 * <h3>Examples</h3>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
 * The following examples show how date and time patterns are interpreted in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
 * the U.S. locale. The given date and time are 2001-07-04 12:08:56 local time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
 * in the U.S. Pacific Time time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
 * <blockquote>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   379
 * <table class="striped">
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   380
 * <caption style="display:none">Examples of date and time patterns interpreted in the U.S. locale</caption>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   381
 * <thead>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   382
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   383
 *         <th scope="col" style="text-align:left">Date and Time Pattern
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   384
 *         <th scope="col" style="text-align:left">Result
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   385
 * </thead>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   386
 * <tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   388
 *         <th scope="row"><code>"yyyy.MM.dd G 'at' HH:mm:ss z"</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
 *         <td><code>2001.07.04 AD at 12:08:56 PDT</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   390
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   391
 *         <th scope="row"><code>"EEE, MMM d, ''yy"</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
 *         <td><code>Wed, Jul 4, '01</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   394
 *         <th scope="row"><code>"h:mm a"</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
 *         <td><code>12:08 PM</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   396
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   397
 *         <th scope="row"><code>"hh 'o''clock' a, zzzz"</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
 *         <td><code>12 o'clock PM, Pacific Daylight Time</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   400
 *         <th scope="row"><code>"K:mm a, z"</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
 *         <td><code>0:08 PM, PDT</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   402
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   403
 *         <th scope="row"><code>"yyyyy.MMMMM.dd GGG hh:mm aaa"</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
 *         <td><code>02001.July.04 AD 12:08 PM</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   406
 *         <th scope="row"><code>"EEE, d MMM yyyy HH:mm:ss Z"</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
 *         <td><code>Wed, 4 Jul 2001 12:08:56 -0700</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   408
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   409
 *         <th scope="row"><code>"yyMMddHHmmssZ"</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
 *         <td><code>010704120856-0700</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   412
 *         <th scope="row"><code>"yyyy-MM-dd'T'HH:mm:ss.SSSZ"</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
 *         <td><code>2001-07-04T12:08:56.235-0700</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   414
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   415
 *         <th scope="row"><code>"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"</code>
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   416
 *         <td><code>2001-07-04T12:08:56.235-07:00</code>
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   417
 *     <tr>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45434
diff changeset
   418
 *         <th scope="row"><code>"YYYY-'W'ww-u"</code>
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
   419
 *         <td><code>2001-W27-3</code>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 44846
diff changeset
   420
 * </tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
 *
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 53431
diff changeset
   424
 * <h3><a id="synchronization">Synchronization</a></h3>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
 * Date formats are not synchronized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
 * It is recommended to create separate format instances for each thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
 * If multiple threads access a format concurrently, it must be synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
 * externally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
 *
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 19054
diff changeset
   432
 * @see          <a href="http://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html">Java Tutorial</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
 * @see          java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
 * @see          java.util.TimeZone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
 * @see          DateFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
 * @see          DateFormatSymbols
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
 * @author       Mark Davis, Chen-Lieh Huang, Alan Liu
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 45124
diff changeset
   438
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
public class SimpleDateFormat extends DateFormat {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    // the official serial version ID which says cryptically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    // which version we're compatible with
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 54206
diff changeset
   444
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    static final long serialVersionUID = 4774881970558875024L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    // the internal serial version which says which version was written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    // - 0 (default) for version up to JDK 1.1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    // - 1 for version from JDK 1.1.4, which includes a new field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    static final int currentSerialVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * The version of the serialized data on the stream.  Possible values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * <li><b>0</b> or not present on stream: JDK 1.1.3.  This version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * has no <code>defaultCenturyStart</code> on stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * <li><b>1</b> JDK 1.1.4 or later.  This version adds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * <code>defaultCenturyStart</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * When streaming out this class, the most recent format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * and the highest allowable <code>serialVersionOnStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * is written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @serial
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 21334
diff changeset
   464
     * @since 1.1.4
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    private int serialVersionOnStream = currentSerialVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * The pattern string of this formatter.  This is always a non-localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * pattern.  May not be null.  See class documentation for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    private String pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    /**
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   476
     * Saved numberFormat and pattern.
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   477
     * @see SimpleDateFormat#checkNegativeNumberExpression
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   478
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31061
diff changeset
   479
    private transient NumberFormat originalNumberFormat;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31061
diff changeset
   480
    private transient String originalNumberPattern;
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   481
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   482
    /**
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   483
     * The minus sign to be used with format and parse.
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   484
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31061
diff changeset
   485
    private transient char minusSign = '-';
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   486
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   487
    /**
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   488
     * True when a negative sign follows a number.
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   489
     * (True as default in Arabic.)
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   490
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31061
diff changeset
   491
    private transient boolean hasFollowingMinusSign = false;
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   492
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
   493
    /**
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   494
     * True if standalone form needs to be used.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   495
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31061
diff changeset
   496
    private transient boolean forceStandaloneForm = false;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   497
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   498
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * The compiled pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31061
diff changeset
   501
    private transient char[] compiledPattern;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * Tags for the compiled pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31061
diff changeset
   506
    private static final int TAG_QUOTE_ASCII_CHAR       = 100;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31061
diff changeset
   507
    private static final int TAG_QUOTE_CHARS            = 101;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Locale dependent digit zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @see #zeroPaddingNumber
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @see java.text.DecimalFormatSymbols#getZeroDigit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31061
diff changeset
   514
    private transient char zeroDigit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * The symbols used by this formatter for week names, month names,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * etc.  May not be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @see java.text.DateFormatSymbols
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    private DateFormatSymbols formatData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * We map dates with two-digit years into the century starting at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * <code>defaultCenturyStart</code>, which may be any date.  May
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * not be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @serial
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 21334
diff changeset
   529
     * @since 1.1.4
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    private Date defaultCenturyStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31061
diff changeset
   533
    private transient int defaultCenturyStartYear;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    private static final int MILLIS_PER_MINUTE = 60 * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    // For time zones that have no names, use strings GMT+minutes and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    // GMT-minutes. For instance, in France the time zone is GMT+60.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    private static final String GMT = "GMT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * Cache NumberFormat instances with Locale key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     */
7003
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6497
diff changeset
   544
    private static final ConcurrentMap<Locale, NumberFormat> cachedNumberFormatData
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   545
        = new ConcurrentHashMap<>(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * The Locale used to instantiate this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * <code>SimpleDateFormat</code>. The value may be null if this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * has been created by an older <code>SimpleDateFormat</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * deserialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    private Locale locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * Indicates whether this <code>SimpleDateFormat</code> should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * the DateFormatSymbols. If true, the format and parse methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * use the DateFormatSymbols values. If false, the format and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * parse methods call Calendar.getDisplayName or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * Calendar.getDisplayNames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    transient boolean useDateFormatSymbols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * Constructs a <code>SimpleDateFormat</code> using the default pattern and
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14765
diff changeset
   569
     * date format symbols for the default
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14765
diff changeset
   570
     * {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * <b>Note:</b> This constructor may not support all locales.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * For full coverage, use the factory methods in the {@link DateFormat}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    public SimpleDateFormat() {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   576
        this("", Locale.getDefault(Locale.Category.FORMAT));
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   577
        applyPatternImpl(LocaleProviderAdapter.getResourceBundleBased().getLocaleResources(locale)
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   578
                         .getDateTimePattern(SHORT, SHORT, calendar));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * Constructs a <code>SimpleDateFormat</code> using the given pattern and
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14765
diff changeset
   583
     * the default date format symbols for the default
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14765
diff changeset
   584
     * {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * <b>Note:</b> This constructor may not support all locales.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * For full coverage, use the factory methods in the {@link DateFormat}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * class.
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14765
diff changeset
   588
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14765
diff changeset
   589
     * {@link #SimpleDateFormat(String, Locale)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14765
diff changeset
   590
     *     SimpleDateFormat(pattern, Locale.getDefault(Locale.Category.FORMAT))}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14765
diff changeset
   592
     * @see java.util.Locale#getDefault(java.util.Locale.Category)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14765
diff changeset
   593
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @param pattern the pattern describing the date and time format
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   595
     * @throws    NullPointerException if the given pattern is null
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   596
     * @throws    IllegalArgumentException if the given pattern is invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    public SimpleDateFormat(String pattern)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   600
        this(pattern, Locale.getDefault(Locale.Category.FORMAT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * Constructs a <code>SimpleDateFormat</code> using the given pattern and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * the default date format symbols for the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * <b>Note:</b> This constructor may not support all locales.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * For full coverage, use the factory methods in the {@link DateFormat}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @param pattern the pattern describing the date and time format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @param locale the locale whose date format symbols should be used
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   612
     * @throws    NullPointerException if the given pattern or locale is null
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   613
     * @throws    IllegalArgumentException if the given pattern is invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    public SimpleDateFormat(String pattern, Locale locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        if (pattern == null || locale == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        initializeCalendar(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        this.pattern = pattern;
7003
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6497
diff changeset
   623
        this.formatData = DateFormatSymbols.getInstanceRef(locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        this.locale = locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        initialize(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * Constructs a <code>SimpleDateFormat</code> using the given pattern and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * date format symbols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * @param pattern the pattern describing the date and time format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * @param formatSymbols the date format symbols to be used for formatting
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   634
     * @throws    NullPointerException if the given pattern or formatSymbols is null
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   635
     * @throws    IllegalArgumentException if the given pattern is invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    public SimpleDateFormat(String pattern, DateFormatSymbols formatSymbols)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        if (pattern == null || formatSymbols == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        this.pattern = pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        this.formatData = (DateFormatSymbols) formatSymbols.clone();
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   645
        this.locale = Locale.getDefault(Locale.Category.FORMAT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        initializeCalendar(this.locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        initialize(this.locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        useDateFormatSymbols = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    /* Initialize compiledPattern and numberFormat fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    private void initialize(Locale loc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        // Verify and compile the given pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        compiledPattern = compile(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        /* try the cache first */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        numberFormat = cachedNumberFormatData.get(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        if (numberFormat == null) { /* cache miss */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            numberFormat = NumberFormat.getIntegerInstance(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            numberFormat.setGroupingUsed(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            /* update cache */
7003
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6497
diff changeset
   663
            cachedNumberFormatData.putIfAbsent(loc, numberFormat);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        numberFormat = (NumberFormat) numberFormat.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        initializeDefaultCentury();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    private void initializeCalendar(Locale loc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        if (calendar == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            assert loc != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            // The format object must be constructed using the symbols for this zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            // However, the calendar should use the current default TimeZone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            // If this is not contained in the locale zone strings, then the zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            // will be formatted using generic GMT+/-H:MM nomenclature.
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   677
            calendar = Calendar.getInstance(loc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * Returns the compiled form of the given pattern. The syntax of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * the compiled pattern is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * CompiledPattern:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     *     EntryList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * EntryList:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     *     Entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     *     EntryList Entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * Entry:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     *     TagField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     *     TagField data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * TagField:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *     Tag Length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     *     TaggedData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * Tag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     *     pattern_char_index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     *     TAG_QUOTE_CHARS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Length:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *     short_length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *     long_length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * TaggedData:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     *     TAG_QUOTE_ASCII_CHAR ascii_char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * where `short_length' is an 8-bit unsigned integer between 0 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * 254.  `long_length' is a sequence of an 8-bit integer 255 and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * 32-bit signed integer value which is split into upper and lower
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * 16-bit fields in two char's. `pattern_char_index' is an 8-bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * integer between 0 and 18. `ascii_char' is an 7-bit ASCII
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * character value. `data' depends on its Tag value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * If Length is short_length, Tag and short_length are packed in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * single char, as illustrated below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     *     char[0] = (Tag << 8) | short_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * If Length is long_length, Tag and 255 are packed in the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * char and a 32-bit integer, as illustrated below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *     char[0] = (Tag << 8) | 255;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     *     char[1] = (char) (long_length >>> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     *     char[2] = (char) (long_length & 0xffff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * If Tag is a pattern_char_index, its Length is the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * pattern characters. For example, if the given pattern is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * "yyyy", Tag is 1 and Length is 4, followed by no data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * If Tag is TAG_QUOTE_CHARS, its Length is the number of char's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * following the TagField. For example, if the given pattern is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * "'o''clock'", Length is 7 followed by a char sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * <code>o&nbs;'&nbs;c&nbs;l&nbs;o&nbs;c&nbs;k</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * TAG_QUOTE_ASCII_CHAR is a special tag and has an ASCII
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * character in place of Length. For example, if the given pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * is "'o'", the TaggedData entry is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * <code>((TAG_QUOTE_ASCII_CHAR&nbs;<<&nbs;8)&nbs;|&nbs;'o')</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   742
     * @throws    NullPointerException if the given pattern is null
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   743
     * @throws    IllegalArgumentException if the given pattern is invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    private char[] compile(String pattern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        int length = pattern.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        boolean inQuote = false;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   748
        StringBuilder compiledCode = new StringBuilder(length * 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        StringBuilder tmpBuffer = null;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   750
        int count = 0, tagcount = 0;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   751
        int lastTag = -1, prevTag = -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        for (int i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            char c = pattern.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            if (c == '\'') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                // '' is treated as a single quote regardless of being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                // in a quoted section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                if ((i + 1) < length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                    c = pattern.charAt(i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                    if (c == '\'') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                        if (count != 0) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   764
                            encode(lastTag, count, compiledCode);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   765
                            tagcount++;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   766
                            prevTag = lastTag;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                            lastTag = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                            count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                        if (inQuote) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                            tmpBuffer.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                        } else {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   773
                            compiledCode.append((char)(TAG_QUOTE_ASCII_CHAR << 8 | c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                if (!inQuote) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                    if (count != 0) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   780
                        encode(lastTag, count, compiledCode);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   781
                        tagcount++;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   782
                        prevTag = lastTag;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                        lastTag = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                    if (tmpBuffer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                        tmpBuffer = new StringBuilder(length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                        tmpBuffer.setLength(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                    inQuote = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                    int len = tmpBuffer.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                    if (len == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                        char ch = tmpBuffer.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                        if (ch < 128) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   797
                            compiledCode.append((char)(TAG_QUOTE_ASCII_CHAR << 8 | ch));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                        } else {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   799
                            compiledCode.append((char)(TAG_QUOTE_CHARS << 8 | 1));
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   800
                            compiledCode.append(ch);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                    } else {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   803
                        encode(TAG_QUOTE_CHARS, len, compiledCode);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   804
                        compiledCode.append(tmpBuffer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                    inQuote = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            if (inQuote) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                tmpBuffer.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            if (!(c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                if (count != 0) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   816
                    encode(lastTag, count, compiledCode);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   817
                    tagcount++;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   818
                    prevTag = lastTag;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                    lastTag = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                    count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                if (c < 128) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                    // In most cases, c would be a delimiter, such as ':'.
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   824
                    compiledCode.append((char)(TAG_QUOTE_ASCII_CHAR << 8 | c));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                    // Take any contiguous non-ASCII alphabet characters and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                    // put them in a single TAG_QUOTE_CHARS.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                    int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                    for (j = i + 1; j < length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                        char d = pattern.charAt(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                        if (d == '\'' || (d >= 'a' && d <= 'z' || d >= 'A' && d <= 'Z')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                    }
51054
147b20e60274 8193444: SimpleDateFormat throws ArrayIndexOutOfBoundsException when format contains long sequences of unicode characters
nishjain
parents: 49904
diff changeset
   835
                    encode(TAG_QUOTE_CHARS, j - i, compiledCode);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    for (; i < j; i++) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   837
                        compiledCode.append(pattern.charAt(i));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                    i--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            int tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            if ((tag = DateFormatSymbols.patternChars.indexOf(c)) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                throw new IllegalArgumentException("Illegal pattern character " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                                                   "'" + c + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            if (lastTag == -1 || lastTag == tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                lastTag = tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   854
            encode(lastTag, count, compiledCode);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   855
            tagcount++;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   856
            prevTag = lastTag;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            lastTag = tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            count = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        if (inQuote) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            throw new IllegalArgumentException("Unterminated quote");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        if (count != 0) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   866
            encode(lastTag, count, compiledCode);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   867
            tagcount++;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   868
            prevTag = lastTag;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   871
        forceStandaloneForm = (tagcount == 1 && prevTag == PATTERN_MONTH);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   872
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        // Copy the compiled pattern to a char array
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   874
        int len = compiledCode.length();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        char[] r = new char[len];
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   876
        compiledCode.getChars(0, len, r, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * Encodes the given tag and length and puts encoded char(s) into buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   883
    private static void encode(int tag, int length, StringBuilder buffer) {
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   884
        if (tag == PATTERN_ISO_ZONE && length >= 4) {
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   885
            throw new IllegalArgumentException("invalid ISO 8601 format: length=" + length);
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
   886
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        if (length < 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            buffer.append((char)(tag << 8 | length));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            buffer.append((char)((tag << 8) | 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            buffer.append((char)(length >>> 16));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            buffer.append((char)(length & 0xffff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    /* Initialize the fields we use to disambiguate ambiguous years. Separate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * so we can call it from readObject().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    private void initializeDefaultCentury() {
7003
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6497
diff changeset
   900
        calendar.setTimeInMillis(System.currentTimeMillis());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        calendar.add( Calendar.YEAR, -80 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        parseAmbiguousDatesAsAfter(calendar.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    /* Define one-century window into which to disambiguate dates using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * two-digit years.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    private void parseAmbiguousDatesAsAfter(Date startDate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        defaultCenturyStart = startDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        calendar.setTime(startDate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        defaultCenturyStartYear = calendar.get(Calendar.YEAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * Sets the 100-year period 2-digit years will be interpreted as being in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * to begin on the date the user specifies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @param startDate During parsing, two digit years will be placed in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * <code>startDate</code> to <code>startDate + 100 years</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * @see #get2DigitYearStart
43011
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 39490
diff changeset
   921
     * @throws NullPointerException if {@code startDate} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    public void set2DigitYearStart(Date startDate) {
7003
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6497
diff changeset
   925
        parseAmbiguousDatesAsAfter(new Date(startDate.getTime()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * Returns the beginning date of the 100-year period 2-digit years are interpreted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * as being within.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * @return the start of the 100-year period into which two digit years are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * @see #set2DigitYearStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    public Date get2DigitYearStart() {
7003
7d8d9506b4ee 6991380: (cal) Calendar.cachedLocaleData should be transitioned from Hashtable to ConcurrentHashMap
okutsu
parents: 6497
diff changeset
   938
        return (Date) defaultCenturyStart.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * Formats the given <code>Date</code> into a date/time string and appends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * the result to the given <code>StringBuffer</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * @param date the date-time value to be formatted into a date-time string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * @param toAppendTo where the new date-time text is to be appended.
48026
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   947
     * @param pos keeps track on the position of the field within
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   948
     * the returned string. For example, given a date-time text
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   949
     * {@code "1996.07.10 AD at 15:08:56 PDT"}, if the given {@code fieldPosition}
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   950
     * is {@link DateFormat#YEAR_FIELD}, the begin index and end index of
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   951
     * {@code fieldPosition} will be set to 0 and 4, respectively.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   952
     * Notice that if the same date-time field appears more than once in a
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   953
     * pattern, the {@code fieldPosition} will be set for the first occurrence
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   954
     * of that date-time field. For instance, formatting a {@code Date} to the
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   955
     * date-time string {@code "1 PM PDT (Pacific Daylight Time)"} using the
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   956
     * pattern {@code "h a z (zzzz)"} and the alignment field
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   957
     * {@link DateFormat#TIMEZONE_FIELD}, the begin index and end index of
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   958
     * {@code fieldPosition} will be set to 5 and 8, respectively, for the
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   959
     * first occurrence of the timezone pattern character {@code 'z'}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @return the formatted date-time string.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   961
     * @throws    NullPointerException if any of the parameters is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
   963
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    public StringBuffer format(Date date, StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                               FieldPosition pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        pos.beginIndex = pos.endIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        return format(date, toAppendTo, pos.getFieldDelegate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    // Called from Format after creating a FieldDelegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    private StringBuffer format(Date date, StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                                FieldDelegate delegate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        // Convert input date to time field list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        calendar.setTime(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        boolean useDateFormatSymbols = useDateFormatSymbols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        for (int i = 0; i < compiledPattern.length; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            int tag = compiledPattern[i] >>> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            int count = compiledPattern[i++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            if (count == 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                count = compiledPattern[i++] << 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                count |= compiledPattern[i++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            case TAG_QUOTE_ASCII_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                toAppendTo.append((char)count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            case TAG_QUOTE_CHARS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                toAppendTo.append(compiledPattern, i, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                i += count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                subFormat(tag, count, delegate, toAppendTo, useDateFormatSymbols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        return toAppendTo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * Formats an Object producing an <code>AttributedCharacterIterator</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * You can use the returned <code>AttributedCharacterIterator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * to build the resulting String, as well as to determine information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * about the resulting String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * Each attribute key of the AttributedCharacterIterator will be of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * <code>DateFormat.Field</code>, with the corresponding attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * being the same as the attribute key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
  1015
     * @throws    NullPointerException if obj is null.
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
  1016
     * @throws    IllegalArgumentException if the Format cannot format the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     *            given object, or if the Format's pattern string is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * @param obj The object to format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * @return AttributedCharacterIterator describing the formatted value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1022
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    public AttributedCharacterIterator formatToCharacterIterator(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        CharacterIteratorFieldDelegate delegate = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                         CharacterIteratorFieldDelegate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        if (obj instanceof Date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            format((Date)obj, sb, delegate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        else if (obj instanceof Number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            format(new Date(((Number)obj).longValue()), sb, delegate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        else if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            throw new NullPointerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                   "formatToCharacterIterator must be passed non-null object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                             "Cannot format given Object as a Date");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        return delegate.getIterator(sb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    // Map index into pattern character string to Calendar field number
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1046
    private static final int[] PATTERN_INDEX_TO_CALENDAR_FIELD = {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1047
        Calendar.ERA,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1048
        Calendar.YEAR,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1049
        Calendar.MONTH,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1050
        Calendar.DATE,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1051
        Calendar.HOUR_OF_DAY,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1052
        Calendar.HOUR_OF_DAY,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1053
        Calendar.MINUTE,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1054
        Calendar.SECOND,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1055
        Calendar.MILLISECOND,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1056
        Calendar.DAY_OF_WEEK,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1057
        Calendar.DAY_OF_YEAR,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1058
        Calendar.DAY_OF_WEEK_IN_MONTH,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1059
        Calendar.WEEK_OF_YEAR,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1060
        Calendar.WEEK_OF_MONTH,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1061
        Calendar.AM_PM,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1062
        Calendar.HOUR,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1063
        Calendar.HOUR,
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1064
        Calendar.ZONE_OFFSET,
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1065
        Calendar.ZONE_OFFSET,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1066
        CalendarBuilder.WEEK_YEAR,         // Pseudo Calendar field
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1067
        CalendarBuilder.ISO_DAY_OF_WEEK,   // Pseudo Calendar field
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1068
        Calendar.ZONE_OFFSET,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1069
        Calendar.MONTH
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    // Map index into pattern character string to DateFormat field number
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    private static final int[] PATTERN_INDEX_TO_DATE_FORMAT_FIELD = {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1074
        DateFormat.ERA_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1075
        DateFormat.YEAR_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1076
        DateFormat.MONTH_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1077
        DateFormat.DATE_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1078
        DateFormat.HOUR_OF_DAY1_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1079
        DateFormat.HOUR_OF_DAY0_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1080
        DateFormat.MINUTE_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1081
        DateFormat.SECOND_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1082
        DateFormat.MILLISECOND_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1083
        DateFormat.DAY_OF_WEEK_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1084
        DateFormat.DAY_OF_YEAR_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1085
        DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1086
        DateFormat.WEEK_OF_YEAR_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1087
        DateFormat.WEEK_OF_MONTH_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1088
        DateFormat.AM_PM_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1089
        DateFormat.HOUR1_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1090
        DateFormat.HOUR0_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1091
        DateFormat.TIMEZONE_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1092
        DateFormat.TIMEZONE_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1093
        DateFormat.YEAR_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1094
        DateFormat.DAY_OF_WEEK_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1095
        DateFormat.TIMEZONE_FIELD,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1096
        DateFormat.MONTH_FIELD
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    // Maps from DecimalFormatSymbols index to Field constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    private static final Field[] PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID = {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1101
        Field.ERA,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1102
        Field.YEAR,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1103
        Field.MONTH,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1104
        Field.DAY_OF_MONTH,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1105
        Field.HOUR_OF_DAY1,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1106
        Field.HOUR_OF_DAY0,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1107
        Field.MINUTE,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1108
        Field.SECOND,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1109
        Field.MILLISECOND,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1110
        Field.DAY_OF_WEEK,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1111
        Field.DAY_OF_YEAR,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1112
        Field.DAY_OF_WEEK_IN_MONTH,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1113
        Field.WEEK_OF_YEAR,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1114
        Field.WEEK_OF_MONTH,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1115
        Field.AM_PM,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1116
        Field.HOUR1,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1117
        Field.HOUR0,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        Field.TIME_ZONE,
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1119
        Field.TIME_ZONE,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1120
        Field.YEAR,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1121
        Field.DAY_OF_WEEK,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1122
        Field.TIME_ZONE,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1123
        Field.MONTH
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * Private member function that does the real date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    private void subFormat(int patternCharIndex, int count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                           FieldDelegate delegate, StringBuffer buffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                           boolean useDateFormatSymbols)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        int     maxIntCount = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        String  current = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        int     beginOffset = buffer.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        int field = PATTERN_INDEX_TO_CALENDAR_FIELD[patternCharIndex];
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1138
        int value;
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1139
        if (field == CalendarBuilder.WEEK_YEAR) {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1140
            if (calendar.isWeekDateSupported()) {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1141
                value = calendar.getWeekYear();
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1142
            } else {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1143
                // use calendar year 'y' instead
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1144
                patternCharIndex = PATTERN_YEAR;
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1145
                field = PATTERN_INDEX_TO_CALENDAR_FIELD[patternCharIndex];
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1146
                value = calendar.get(field);
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1147
            }
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1148
        } else if (field == CalendarBuilder.ISO_DAY_OF_WEEK) {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1149
            value = CalendarBuilder.toISODayOfWeek(calendar.get(Calendar.DAY_OF_WEEK));
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1150
        } else {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1151
            value = calendar.get(field);
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1152
        }
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1153
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        int style = (count >= 4) ? Calendar.LONG : Calendar.SHORT;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1155
        if (!useDateFormatSymbols && field < Calendar.ZONE_OFFSET
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1156
            && patternCharIndex != PATTERN_MONTH_STANDALONE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            current = calendar.getDisplayName(field, style, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        // Note: zeroPaddingNumber() assumes that maxDigits is either
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        // 2 or maxIntCount. If we make any changes to this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        // zeroPaddingNumber() must be fixed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        switch (patternCharIndex) {
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1165
        case PATTERN_ERA: // 'G'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            if (useDateFormatSymbols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                String[] eras = formatData.getEras();
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1168
                if (value < eras.length) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                    current = eras[value];
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1170
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1172
            if (current == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                current = "";
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1174
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1177
        case PATTERN_WEEK_YEAR: // 'Y'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1178
        case PATTERN_YEAR:      // 'y'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            if (calendar instanceof GregorianCalendar) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1180
                if (count != 2) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                    zeroPaddingNumber(value, count, maxIntCount, buffer);
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1182
                } else {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1183
                    zeroPaddingNumber(value, 2, 2, buffer);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1184
                } // clip 1996 to 96
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                if (current == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                    zeroPaddingNumber(value, style == Calendar.LONG ? 1 : count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                                      maxIntCount, buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
53431
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  1193
        case PATTERN_MONTH:            // 'M' (context sensitive)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            if (useDateFormatSymbols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                String[] months;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                if (count >= 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                    months = formatData.getMonths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                    current = months[value];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                } else if (count == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                    months = formatData.getShortMonths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                    current = months[value];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                if (count < 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                    current = null;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1206
                } else if (forceStandaloneForm) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1207
                    current = calendar.getDisplayName(field, style | 0x8000, locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1208
                    if (current == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1209
                        current = calendar.getDisplayName(field, style, locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1210
                    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1211
                }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1212
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1213
            if (current == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1214
                zeroPaddingNumber(value+1, count, maxIntCount, buffer);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1215
            }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1216
            break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1217
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1218
        case PATTERN_MONTH_STANDALONE: // 'L'
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1219
            assert current == null;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1220
            if (locale == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1221
                String[] months;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1222
                if (count >= 4) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1223
                    months = formatData.getMonths();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1224
                    current = months[value];
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1225
                } else if (count == 3) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1226
                    months = formatData.getShortMonths();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1227
                    current = months[value];
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1228
                }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1229
            } else {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1230
                if (count >= 3) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1231
                    current = calendar.getDisplayName(field, style | 0x8000, locale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            if (current == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                zeroPaddingNumber(value+1, count, maxIntCount, buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1239
        case PATTERN_HOUR_OF_DAY1: // 'k' 1-based.  eg, 23:59 + 1 hour =>> 24:59
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            if (current == null) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1241
                if (value == 0) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1242
                    zeroPaddingNumber(calendar.getMaximum(Calendar.HOUR_OF_DAY) + 1,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                                      count, maxIntCount, buffer);
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1244
                } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                    zeroPaddingNumber(value, count, maxIntCount, buffer);
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1246
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1250
        case PATTERN_DAY_OF_WEEK: // 'E'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            if (useDateFormatSymbols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                String[] weekdays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                if (count >= 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                    weekdays = formatData.getWeekdays();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                    current = weekdays[value];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                } else { // count < 4, use abbreviated form if exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                    weekdays = formatData.getShortWeekdays();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                    current = weekdays[value];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1263
        case PATTERN_AM_PM:    // 'a'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            if (useDateFormatSymbols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                String[] ampm = formatData.getAmPmStrings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                current = ampm[value];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1270
        case PATTERN_HOUR1:    // 'h' 1-based.  eg, 11PM + 1 hour =>> 12 AM
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            if (current == null) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1272
                if (value == 0) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1273
                    zeroPaddingNumber(calendar.getLeastMaximum(Calendar.HOUR) + 1,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                                      count, maxIntCount, buffer);
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1275
                } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                    zeroPaddingNumber(value, count, maxIntCount, buffer);
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1277
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1281
        case PATTERN_ZONE_NAME: // 'z'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            if (current == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                if (formatData.locale == null || formatData.isZoneStringsSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                    int zoneIndex =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                        formatData.getZoneIndex(calendar.getTimeZone().getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                    if (zoneIndex == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                        value = calendar.get(Calendar.ZONE_OFFSET) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                            calendar.get(Calendar.DST_OFFSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                        buffer.append(ZoneInfoFile.toCustomID(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                        int index = (calendar.get(Calendar.DST_OFFSET) == 0) ? 1: 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                        if (count < 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                            // Use the short name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                            index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                        String[][] zoneStrings = formatData.getZoneStringsWrapper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                        buffer.append(zoneStrings[zoneIndex][index]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                    TimeZone tz = calendar.getTimeZone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                    boolean daylight = (calendar.get(Calendar.DST_OFFSET) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                    int tzstyle = (count < 4 ? TimeZone.SHORT : TimeZone.LONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                    buffer.append(tz.getDisplayName(daylight, tzstyle, formatData.locale));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1308
        case PATTERN_ZONE_VALUE: // 'Z' ("-/+hhmm" form)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            value = (calendar.get(Calendar.ZONE_OFFSET) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                     calendar.get(Calendar.DST_OFFSET)) / 60000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            int width = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            if (value >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                buffer.append('+');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                width++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
            int num = (value / 60) * 100 + (value % 60);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            CalendarUtils.sprintf0d(buffer, num, width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1323
        case PATTERN_ISO_ZONE:   // 'X'
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1324
            value = calendar.get(Calendar.ZONE_OFFSET)
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1325
                    + calendar.get(Calendar.DST_OFFSET);
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1326
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1327
            if (value == 0) {
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1328
                buffer.append('Z');
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1329
                break;
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1330
            }
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1331
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1332
            value /=  60000;
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1333
            if (value >= 0) {
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1334
                buffer.append('+');
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1335
            } else {
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1336
                buffer.append('-');
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1337
                value = -value;
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1338
            }
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1339
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1340
            CalendarUtils.sprintf0d(buffer, value / 60, 2);
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1341
            if (count == 1) {
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1342
                break;
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1343
            }
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1344
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1345
            if (count == 3) {
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1346
                buffer.append(':');
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1347
            }
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1348
            CalendarUtils.sprintf0d(buffer, value % 60, 2);
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1349
            break;
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  1350
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        default:
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1352
     // case PATTERN_DAY_OF_MONTH:         // 'd'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1353
     // case PATTERN_HOUR_OF_DAY0:         // 'H' 0-based.  eg, 23:59 + 1 hour =>> 00:59
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1354
     // case PATTERN_MINUTE:               // 'm'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1355
     // case PATTERN_SECOND:               // 's'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1356
     // case PATTERN_MILLISECOND:          // 'S'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1357
     // case PATTERN_DAY_OF_YEAR:          // 'D'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1358
     // case PATTERN_DAY_OF_WEEK_IN_MONTH: // 'F'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1359
     // case PATTERN_WEEK_OF_YEAR:         // 'w'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1360
     // case PATTERN_WEEK_OF_MONTH:        // 'W'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1361
     // case PATTERN_HOUR0:                // 'K' eg, 11PM + 1 hour =>> 0 AM
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1362
     // case PATTERN_ISO_DAY_OF_WEEK:      // 'u' pseudo field, Monday = 1, ..., Sunday = 7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            if (current == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                zeroPaddingNumber(value, count, maxIntCount, buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        } // switch (patternCharIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        if (current != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            buffer.append(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        int fieldID = PATTERN_INDEX_TO_DATE_FORMAT_FIELD[patternCharIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        Field f = PATTERN_INDEX_TO_DATE_FORMAT_FIELD_ID[patternCharIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        delegate.formatted(fieldID, f, f, beginOffset, buffer.length(), buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     * Formats a number with the specified minimum and maximum number of digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1382
    private void zeroPaddingNumber(int value, int minDigits, int maxDigits, StringBuffer buffer)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        // Optimization for 1, 2 and 4 digit numbers. This should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        // cover most cases of formatting date/time related items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        // Note: This optimization code assumes that maxDigits is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        // either 2 or Integer.MAX_VALUE (maxIntCount in format()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            if (zeroDigit == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                zeroDigit = ((DecimalFormat)numberFormat).getDecimalFormatSymbols().getZeroDigit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
            if (value >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                if (value < 100 && minDigits >= 1 && minDigits <= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                    if (value < 10) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                        if (minDigits == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                            buffer.append(zeroDigit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                        buffer.append((char)(zeroDigit + value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                        buffer.append((char)(zeroDigit + value / 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                        buffer.append((char)(zeroDigit + value % 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                } else if (value >= 1000 && value < 10000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                    if (minDigits == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                        buffer.append((char)(zeroDigit + value / 1000));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                        value %= 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                        buffer.append((char)(zeroDigit + value / 100));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                        value %= 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                        buffer.append((char)(zeroDigit + value / 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                        buffer.append((char)(zeroDigit + value % 10));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                    if (minDigits == 2 && maxDigits == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                        zeroPaddingNumber(value % 100, 2, 2, buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        numberFormat.setMinimumIntegerDigits(minDigits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        numberFormat.setMaximumIntegerDigits(maxDigits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        numberFormat.format((long)value, buffer, DontCareFieldPosition.INSTANCE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * Parses text from a string to produce a <code>Date</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * The method attempts to parse text starting at the index given by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     * <code>pos</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     * If parsing succeeds, then the index of <code>pos</code> is updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * to the index after the last character used (parsing does not necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     * use all characters up to the end of the string), and the parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * date is returned. The updated <code>pos</code> can be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * indicate the starting point for the next call to this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * If an error occurs, then the index of <code>pos</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * changed, the error index of <code>pos</code> is set to the index of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * the character where the error occurred, and null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     *
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1443
     * <p>This parsing operation uses the {@link DateFormat#calendar
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1444
     * calendar} to produce a {@code Date}. All of the {@code
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1445
     * calendar}'s date-time fields are {@linkplain Calendar#clear()
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1446
     * cleared} before parsing, and the {@code calendar}'s default
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1447
     * values of the date-time fields are used for any missing
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1448
     * date-time information. For example, the year value of the
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1449
     * parsed {@code Date} is 1970 with {@link GregorianCalendar} if
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1450
     * no year value is given from the parsing operation.  The {@code
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1451
     * TimeZone} value may be overwritten, depending on the given
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1452
     * pattern and the time zone value in {@code text}. Any {@code
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1453
     * TimeZone} value that has previously been set by a call to
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1454
     * {@link #setTimeZone(java.util.TimeZone) setTimeZone} may need
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1455
     * to be restored for further operations.
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 3098
diff changeset
  1456
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     * @param text  A <code>String</code>, part of which should be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     * @param pos   A <code>ParsePosition</code> object with index and error
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     *              index information as described above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     * @return A <code>Date</code> parsed from the string. In case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     *         error, returns null.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
  1462
     * @throws    NullPointerException if <code>text</code> or <code>pos</code> is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1464
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    public Date parse(String text, ParsePosition pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    {
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1467
        checkNegativeNumberExpression();
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1468
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        int start = pos.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        int oldStart = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        int textLength = text.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        boolean[] ambiguousYear = {false};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1475
        CalendarBuilder calb = new CalendarBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        for (int i = 0; i < compiledPattern.length; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            int tag = compiledPattern[i] >>> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            int count = compiledPattern[i++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            if (count == 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                count = compiledPattern[i++] << 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                count |= compiledPattern[i++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
            switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            case TAG_QUOTE_ASCII_CHAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                if (start >= textLength || text.charAt(start) != (char)count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                    pos.index = oldStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                    pos.errorIndex = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                start++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            case TAG_QUOTE_CHARS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                while (count-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                    if (start >= textLength || text.charAt(start) != compiledPattern[i++]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                        pos.index = oldStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                        pos.errorIndex = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                    start++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                // Peek the next pattern to determine if we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                // obey the number of pattern letters for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                // parsing. It's required when parsing contiguous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                // digit text (e.g., "20010704") with a pattern which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                // has no delimiters between fields, like "yyyyMMdd".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                boolean obeyCount = false;
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1513
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1514
                // In Arabic, a minus sign for a negative number is put after
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1515
                // the number. Even in another locale, a minus sign can be
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1516
                // put after a number using DateFormat.setNumberFormat().
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1517
                // If both the minus sign and the field-delimiter are '-',
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1518
                // subParse() needs to determine whether a '-' after a number
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1519
                // in the given text is a delimiter or is a minus sign for the
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1520
                // preceding number. We give subParse() a clue based on the
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1521
                // information in compiledPattern.
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1522
                boolean useFollowingMinusSignAsDelimiter = false;
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1523
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                if (i < compiledPattern.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                    int nextTag = compiledPattern[i] >>> 8;
38750
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1526
                    int nextCount = compiledPattern[i] & 0xff;
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1527
                    obeyCount = shouldObeyCount(nextTag, nextCount);
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1528
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1529
                    if (hasFollowingMinusSign &&
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1530
                        (nextTag == TAG_QUOTE_ASCII_CHAR ||
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1531
                         nextTag == TAG_QUOTE_CHARS)) {
38750
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1532
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1533
                        if (nextTag != TAG_QUOTE_ASCII_CHAR) {
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1534
                            nextCount = compiledPattern[i+1];
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1535
                        }
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1536
38750
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1537
                        if (nextCount == minusSign) {
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1538
                            useFollowingMinusSignAsDelimiter = true;
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1539
                        }
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1540
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                start = subParse(text, start, tag, count, obeyCount,
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1543
                                 ambiguousYear, pos,
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1544
                                 useFollowingMinusSignAsDelimiter, calb);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                if (start < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                    pos.index = oldStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        // At this point the fields of Calendar have been set.  Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        // will fill in default values for missing fields when the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        // is computed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        pos.index = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        Date parsedDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
        try {
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1560
            parsedDate = calb.establish(calendar).getTime();
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1561
            // If the year value is ambiguous,
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1562
            // then the two-digit year == the default start year
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1563
            if (ambiguousYear[0]) {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1564
                if (parsedDate.before(defaultCenturyStart)) {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1565
                    parsedDate = calb.addYear(100).establish(calendar).getTime();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
        // An IllegalArgumentException will be thrown by Calendar.getTime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        // if any fields are out of range, e.g., MONTH == 17.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
            pos.errorIndex = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            pos.index = oldStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        return parsedDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
38750
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1580
    /* If the next tag/pattern is a <Numeric_Field> then the parser
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1581
     * should consider the count of digits while parsing the contigous digits
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1582
     * for the current tag/pattern
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1583
     */
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1584
    private boolean shouldObeyCount(int tag, int count) {
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1585
        switch (tag) {
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1586
            case PATTERN_MONTH:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1587
            case PATTERN_MONTH_STANDALONE:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1588
                return count <= 2;
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1589
            case PATTERN_YEAR:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1590
            case PATTERN_DAY_OF_MONTH:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1591
            case PATTERN_HOUR_OF_DAY1:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1592
            case PATTERN_HOUR_OF_DAY0:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1593
            case PATTERN_MINUTE:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1594
            case PATTERN_SECOND:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1595
            case PATTERN_MILLISECOND:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1596
            case PATTERN_DAY_OF_YEAR:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1597
            case PATTERN_DAY_OF_WEEK_IN_MONTH:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1598
            case PATTERN_WEEK_OF_YEAR:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1599
            case PATTERN_WEEK_OF_MONTH:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1600
            case PATTERN_HOUR1:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1601
            case PATTERN_HOUR0:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1602
            case PATTERN_WEEK_YEAR:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1603
            case PATTERN_ISO_DAY_OF_WEEK:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1604
                return true;
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1605
            default:
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1606
                return false;
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1607
        }
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1608
    }
b03431b3516b 8072099: Format "ha" is unable to parse hours 10-12
nishjain
parents: 34690
diff changeset
  1609
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
     * Private code-size reduction function used by subParse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     * @param text the time text being parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     * @param start where to start parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     * @param field the date field being parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
     * @param data the string array to parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
     * @return the new start position if matching succeeded; a negative number
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
     * indicating matching failure, otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     */
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1619
    private int matchString(String text, int start, int field, String[] data, CalendarBuilder calb)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        int count = data.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1624
        if (field == Calendar.DAY_OF_WEEK) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1625
            i = 1;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1626
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        // There may be multiple strings in the data[] array which begin with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        // the same prefix (e.g., Cerven and Cervenec (June and July) in Czech).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
        // We keep track of the longest match, and return that.  Note that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
        // unfortunately requires us to test all array elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        int bestMatchLength = 0, bestMatch = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        for (; i<count; ++i)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
            int length = data[i].length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
            // Always compare if we have no match yet; otherwise only compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
            // against potentially better matches (longer strings).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
            if (length > bestMatchLength &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                text.regionMatches(true, start, data[i], 0, length))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                bestMatch = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                bestMatchLength = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        if (bestMatch >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        {
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1647
            calb.set(field, bestMatch);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
            return start + bestMatchLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        return -start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
     * Performs the same thing as matchString(String, int, int,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
     * String[]). This method takes a Map<String, Integer> instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
     * String[].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
     */
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1658
    private int matchString(String text, int start, int field,
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1659
                            Map<String,Integer> data, CalendarBuilder calb) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
        if (data != null) {
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1661
            // TODO: make this default when it's in the spec.
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1662
            if (data instanceof SortedMap) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1663
                for (String name : data.keySet()) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1664
                    if (text.regionMatches(true, start, name, 0, name.length())) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1665
                        calb.set(field, data.get(name));
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1666
                        return start + name.length();
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1667
                    }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1668
                }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1669
                return -start;
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1670
            }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1671
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
            String bestMatch = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
            for (String name : data.keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                int length = name.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                if (bestMatch == null || length > bestMatch.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                    if (text.regionMatches(true, start, name, 0, length)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                        bestMatch = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            if (bestMatch != null) {
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1684
                calb.set(field, data.get(bestMatch));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                return start + bestMatch.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        return -start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    private int matchZoneString(String text, int start, String[] zoneNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
        for (int i = 1; i <= 4; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
            // Checking long and short zones [1 & 2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
            // and long and short daylight [3 & 4].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            String zoneName = zoneNames[i];
49904
cadca99d52e7 8181157: CLDR Timezone name fallback implementation
naoto
parents: 48251
diff changeset
  1696
            if (zoneName.isEmpty()) {
cadca99d52e7 8181157: CLDR Timezone name fallback implementation
naoto
parents: 48251
diff changeset
  1697
                // fill in by retrieving single name
cadca99d52e7 8181157: CLDR Timezone name fallback implementation
naoto
parents: 48251
diff changeset
  1698
                zoneName = TimeZoneNameUtility.retrieveDisplayName(
cadca99d52e7 8181157: CLDR Timezone name fallback implementation
naoto
parents: 48251
diff changeset
  1699
                                zoneNames[0], i >= 3, i % 2, locale);
cadca99d52e7 8181157: CLDR Timezone name fallback implementation
naoto
parents: 48251
diff changeset
  1700
                zoneNames[i] = zoneName;
cadca99d52e7 8181157: CLDR Timezone name fallback implementation
naoto
parents: 48251
diff changeset
  1701
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            if (text.regionMatches(true, start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                                   zoneName, 0, zoneName.length())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1710
    private boolean matchDSTString(String text, int start, int zoneIndex, int standardIndex,
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1711
                                   String[][] zoneStrings) {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1712
        int index = standardIndex + 2;
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1713
        String zoneName  = zoneStrings[zoneIndex][index];
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1714
        if (text.regionMatches(true, start,
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1715
                               zoneName, 0, zoneName.length())) {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1716
            return true;
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1717
        }
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1718
        return false;
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1719
    }
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1720
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     * find time zone 'text' matched zoneStrings and set to internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * calendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     */
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1725
    private int subParseZoneString(String text, int start, CalendarBuilder calb) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        boolean useSameName = false; // true if standard and daylight time use the same abbreviation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
        TimeZone currentTimeZone = getTimeZone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        // At this point, check for named time zones by looking through
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
        // the locale data from the TimeZoneNames strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        // Want to be able to parse both short and long forms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        int zoneIndex = formatData.getZoneIndex(currentTimeZone.getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
        TimeZone tz = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
        String[][] zoneStrings = formatData.getZoneStringsWrapper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        String[] zoneNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        int nameIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        if (zoneIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            zoneNames = zoneStrings[zoneIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
                if (nameIndex <= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                    // Check if the standard name (abbr) and the daylight name are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                    useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                tz = TimeZone.getTimeZone(zoneNames[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
        if (tz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            zoneIndex = formatData.getZoneIndex(TimeZone.getDefault().getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
            if (zoneIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                zoneNames = zoneStrings[zoneIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
                if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                    if (nameIndex <= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                        useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                    tz = TimeZone.getTimeZone(zoneNames[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        }
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1759
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
        if (tz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
            int len = zoneStrings.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
            for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                zoneNames = zoneStrings[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                    if (nameIndex <= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                        useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                    tz = TimeZone.getTimeZone(zoneNames[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        if (tz != null) { // Matched any ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
            if (!tz.equals(currentTimeZone)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                setTimeZone(tz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
            // If the time zone matched uses the same name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
            // (abbreviation) for both standard and daylight time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            // let the time zone in the Calendar decide which one.
1312
880799c54c4d 6645292: [Fmt-Da] Timezone Western Summer Time (Australia) is parsed incorrectly
peytoia
parents: 2
diff changeset
  1780
            //
880799c54c4d 6645292: [Fmt-Da] Timezone Western Summer Time (Australia) is parsed incorrectly
peytoia
parents: 2
diff changeset
  1781
            // Also if tz.getDSTSaving() returns 0 for DST, use tz to
880799c54c4d 6645292: [Fmt-Da] Timezone Western Summer Time (Australia) is parsed incorrectly
peytoia
parents: 2
diff changeset
  1782
            // determine the local time. (6645292)
880799c54c4d 6645292: [Fmt-Da] Timezone Western Summer Time (Australia) is parsed incorrectly
peytoia
parents: 2
diff changeset
  1783
            int dstAmount = (nameIndex >= 3) ? tz.getDSTSavings() : 0;
880799c54c4d 6645292: [Fmt-Da] Timezone Western Summer Time (Australia) is parsed incorrectly
peytoia
parents: 2
diff changeset
  1784
            if (!(useSameName || (nameIndex >= 3 && dstAmount == 0))) {
17178
bf3ea41ef154 8000529: Regression: SimpleDateFormat incorrectly parses dates formatted with Z and z pattern letters
coffeys
parents: 16010
diff changeset
  1785
                calb.clear(Calendar.ZONE_OFFSET).set(Calendar.DST_OFFSET, dstAmount);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            return (start + zoneNames[nameIndex].length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
        }
32847
9409488183a6 8081794: ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
okutsu
parents: 32649
diff changeset
  1789
        return -start;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
    /**
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1793
     * Parses numeric forms of time zone offset, such as "hh:mm", and
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1794
     * sets calb to the parsed value.
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1795
     *
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1796
     * @param text  the text to be parsed
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1797
     * @param start the character position to start parsing
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1798
     * @param sign  1: positive; -1: negative
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1799
     * @param count 0: 'Z' or "GMT+hh:mm" parsing; 1 - 3: the number of 'X's
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1800
     * @param colon true - colon required between hh and mm; false - no colon required
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1801
     * @param calb  a CalendarBuilder in which the parsed value is stored
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1802
     * @return updated parsed position, or its negative value to indicate a parsing error
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1803
     */
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1804
    private int subParseNumericZone(String text, int start, int sign, int count,
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1805
                                    boolean colon, CalendarBuilder calb) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1806
        int index = start;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1807
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1808
      parse:
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1809
        try {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1810
            char c = text.charAt(index++);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1811
            // Parse hh
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1812
            int hours;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1813
            if (!isDigit(c)) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1814
                break parse;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1815
            }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1816
            hours = c - '0';
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1817
            c = text.charAt(index++);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1818
            if (isDigit(c)) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1819
                hours = hours * 10 + (c - '0');
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1820
            } else {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1821
                // If no colon in RFC 822 or 'X' (ISO), two digits are
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1822
                // required.
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1823
                if (count > 0 || !colon) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1824
                    break parse;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1825
                }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1826
                --index;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1827
            }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1828
            if (hours > 23) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1829
                break parse;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1830
            }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1831
            int minutes = 0;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1832
            if (count != 1) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1833
                // Proceed with parsing mm
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1834
                c = text.charAt(index++);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1835
                if (colon) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1836
                    if (c != ':') {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1837
                        break parse;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1838
                    }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1839
                    c = text.charAt(index++);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1840
                }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1841
                if (!isDigit(c)) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1842
                    break parse;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1843
                }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1844
                minutes = c - '0';
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1845
                c = text.charAt(index++);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1846
                if (!isDigit(c)) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1847
                    break parse;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1848
                }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1849
                minutes = minutes * 10 + (c - '0');
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1850
                if (minutes > 59) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1851
                    break parse;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1852
                }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1853
            }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1854
            minutes += hours * 60;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1855
            calb.set(Calendar.ZONE_OFFSET, minutes * MILLIS_PER_MINUTE * sign)
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1856
                .set(Calendar.DST_OFFSET, 0);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1857
            return index;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1858
        } catch (IndexOutOfBoundsException e) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1859
        }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1860
        return  1 - index; // -(index - 1)
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1861
    }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1862
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1863
    private boolean isDigit(char c) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1864
        return c >= '0' && c <= '9';
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1865
    }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1866
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  1867
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     * Private member function that converts the parsed date strings into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     * timeFields. Returns -start (for ParsePosition) if failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     * @param text the time text to be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     * @param start where to start parsing.
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 13583
diff changeset
  1872
     * @param patternCharIndex the index of the pattern character.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     * @param count the count of a pattern character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
     * @param obeyCount if true, then the next field directly abuts this one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
     * and we should use the count to know when to stop parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
     * @param ambiguousYear return parameter; upon return, if ambiguousYear[0]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
     * is true, then a two-digit year was parsed and may need to be readjusted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
     * @param origPos origPos.errorIndex is used to return an error index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
     * at which a parse error occurred, if matching failure occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
     * @return the new start position if matching succeeded; -1 indicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
     * matching failure, otherwise. In case matching failure occurred,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
     * an error index is set to origPos.errorIndex.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
    private int subParse(String text, int start, int patternCharIndex, int count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                         boolean obeyCount, boolean[] ambiguousYear,
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1886
                         ParsePosition origPos,
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1887
                         boolean useFollowingMinusSignAsDelimiter, CalendarBuilder calb) {
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1888
        Number number;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
        int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
        ParsePosition pos = new ParsePosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        pos.index = start;
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1892
        if (patternCharIndex == PATTERN_WEEK_YEAR && !calendar.isWeekDateSupported()) {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1893
            // use calendar year 'y' instead
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1894
            patternCharIndex = PATTERN_YEAR;
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1895
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
        int field = PATTERN_INDEX_TO_CALENDAR_FIELD[patternCharIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
        // If there are any spaces here, skip over them.  If we hit the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
        // of the string, then fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
            if (pos.index >= text.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                origPos.errorIndex = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
            char c = text.charAt(pos.index);
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1906
            if (c != ' ' && c != '\t') {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1907
                break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  1908
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
            ++pos.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
        }
18146
47760e45a1dd 7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents: 17178
diff changeset
  1911
        // Remember the actual start index
47760e45a1dd 7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents: 17178
diff changeset
  1912
        int actualStart = pos.index;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
      parsing:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
            // We handle a few special cases here where we need to parse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            // a number value.  We handle further, more generic cases below.  We need
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
            // to handle some of them here because some fields require extra processing on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            // the parsed value.
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1920
            if (patternCharIndex == PATTERN_HOUR_OF_DAY1 ||
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1921
                patternCharIndex == PATTERN_HOUR1 ||
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1922
                (patternCharIndex == PATTERN_MONTH && count <= 2) ||
34690
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  1923
                (patternCharIndex == PATTERN_MONTH_STANDALONE && count <= 2) ||
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1924
                patternCharIndex == PATTERN_YEAR ||
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1925
                patternCharIndex == PATTERN_WEEK_YEAR) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                // It would be good to unify this with the obeyCount logic below,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                // but that's going to be difficult.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
                if (obeyCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
                    if ((start+count) > text.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
                        break parsing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
                    number = numberFormat.parse(text.substring(0, start+count), pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
                    number = numberFormat.parse(text, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
                if (number == null) {
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1937
                    if (patternCharIndex != PATTERN_YEAR || calendar instanceof GregorianCalendar) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                        break parsing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                    value = number.intValue();
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1942
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1943
                    if (useFollowingMinusSignAsDelimiter && (value < 0) &&
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1944
                        (((pos.index < text.length()) &&
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1945
                         (text.charAt(pos.index) != minusSign)) ||
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1946
                         ((pos.index == text.length()) &&
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1947
                          (text.charAt(pos.index-1) == minusSign)))) {
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1948
                        value = -value;
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1949
                        pos.index--;
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  1950
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
            boolean useDateFormatSymbols = useDateFormatSymbols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
            int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
            switch (patternCharIndex) {
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1958
            case PATTERN_ERA: // 'G'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
                if (useDateFormatSymbols) {
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1960
                    if ((index = matchString(text, start, Calendar.ERA, formatData.getEras(), calb)) > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
                        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                } else {
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  1964
                    Map<String, Integer> map = getDisplayNamesMap(field, locale);
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1965
                    if ((index = matchString(text, start, field, map, calb)) > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
                        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
                break parsing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1971
            case PATTERN_WEEK_YEAR: // 'Y'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1972
            case PATTERN_YEAR:      // 'y'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
                if (!(calendar instanceof GregorianCalendar)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
                    // calendar might have text representations for year values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                    // such as "\u5143" in JapaneseImperialCalendar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
                    int style = (count >= 4) ? Calendar.LONG : Calendar.SHORT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
                    Map<String, Integer> map = calendar.getDisplayNames(field, style, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
                    if (map != null) {
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1979
                        if ((index = matchString(text, start, field, map, calb)) > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                            return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                    }
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  1983
                    calb.set(field, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                    return pos.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
                // If there are 3 or more YEAR pattern characters, this indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                // that the year value is to be treated literally, without any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
                // two-digit year adjustments (e.g., from "01" to 2001).  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
                // we made adjustments to place the 2-digit year in the proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                // century, for parsed strings from "00" to "99".  Any other string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
                // is treated literally:  "2250", "-1", "1", "002".
18146
47760e45a1dd 7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents: 17178
diff changeset
  1993
                if (count <= 2 && (pos.index - actualStart) == 2
47760e45a1dd 7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents: 17178
diff changeset
  1994
                    && Character.isDigit(text.charAt(actualStart))
47760e45a1dd 7177315: SimpleDateFormat parses wrong 2-digit year if input contains spaces
okutsu
parents: 17178
diff changeset
  1995
                    && Character.isDigit(text.charAt(actualStart + 1))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                    // Assume for example that the defaultCenturyStart is 6/18/1903.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                    // This means that two-digit years will be forced into the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                    // 6/18/1903 to 6/17/2003.  As a result, years 00, 01, and 02
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
                    // correspond to 2000, 2001, and 2002.  Years 04, 05, etc. correspond
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                    // to 1904, 1905, etc.  If the year is 03, then it is 2003 if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                    // other fields specify a date before 6/18, or 1903 if they specify a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                    // date afterwards.  As a result, 03 is an ambiguous year.  All other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                    // two-digit years are unambiguous.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
                    int ambiguousTwoDigitYear = defaultCenturyStartYear % 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
                    ambiguousYear[0] = value == ambiguousTwoDigitYear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                    value += (defaultCenturyStartYear/100)*100 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                        (value < ambiguousTwoDigitYear ? 100 : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                }
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2009
                calb.set(field, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
                return pos.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2012
            case PATTERN_MONTH: // 'M'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
                if (count <= 2) // i.e., M or MM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
                    // Don't want to parse the month if it is a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
                    // while pattern uses numeric style: M or MM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
                    // [We computed 'value' above.]
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2018
                    calb.set(Calendar.MONTH, value - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
                    return pos.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
                if (useDateFormatSymbols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                    // count >= 3 // i.e., MMM or MMMM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
                    // Want to be able to parse both short and long forms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
                    // Try count == 4 first:
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2026
                    int newStart;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
                    if ((newStart = matchString(text, start, Calendar.MONTH,
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2028
                                                formatData.getMonths(), calb)) > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
                        return newStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
                    // count == 4 failed, now try count == 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
                    if ((index = matchString(text, start, Calendar.MONTH,
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2033
                                             formatData.getShortMonths(), calb)) > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
                        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
                } else {
53431
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2037
                    Map<String, Integer> map = getDisplayContextNamesMap(field, locale);
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2038
                    if ((index = matchString(text, start, field, map, calb)) > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
                        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                break parsing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
34690
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2044
            case PATTERN_MONTH_STANDALONE: // 'L'
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2045
                if (count <= 2) {
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2046
                    // Don't want to parse the month if it is a string
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2047
                    // while pattern uses numeric style: L or LL
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2048
                    //[we computed 'value' above.]
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2049
                    calb.set(Calendar.MONTH, value - 1);
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2050
                    return pos.index;
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2051
                }
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2052
                Map<String, Integer> maps = getDisplayNamesMap(field, locale);
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2053
                if ((index = matchString(text, start, field, maps, calb)) > 0) {
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2054
                    return index;
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2055
                }
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2056
                break parsing;
48ccec8b0e75 8139572: SimpleDateFormat parse month stand-alone format bug
okutsu
parents: 32847
diff changeset
  2057
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2058
            case PATTERN_HOUR_OF_DAY1: // 'k' 1-based.  eg, 23:59 + 1 hour =>> 24:59
7502
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2059
                if (!isLenient()) {
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2060
                    // Validate the hour value in non-lenient
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2061
                    if (value < 1 || value > 24) {
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2062
                        break parsing;
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2063
                    }
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2064
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                // [We computed 'value' above.]
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2066
                if (value == calendar.getMaximum(Calendar.HOUR_OF_DAY) + 1) {
7502
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2067
                    value = 0;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2068
                }
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2069
                calb.set(Calendar.HOUR_OF_DAY, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                return pos.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2072
            case PATTERN_DAY_OF_WEEK:  // 'E'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2073
                {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
                    if (useDateFormatSymbols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
                        // Want to be able to parse both short and long forms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                        // Try count == 4 (DDDD) first:
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2077
                        int newStart;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
                        if ((newStart=matchString(text, start, Calendar.DAY_OF_WEEK,
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2079
                                                  formatData.getWeekdays(), calb)) > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                            return newStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
                        // DDDD failed, now try DDD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
                        if ((index = matchString(text, start, Calendar.DAY_OF_WEEK,
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2084
                                                 formatData.getShortWeekdays(), calb)) > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                            return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
                        int[] styles = { Calendar.LONG, Calendar.SHORT };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
                        for (int style : styles) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
                            Map<String,Integer> map = calendar.getDisplayNames(field, style, locale);
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2091
                            if ((index = matchString(text, start, field, map, calb)) > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                                return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                break parsing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2099
            case PATTERN_AM_PM:    // 'a'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                if (useDateFormatSymbols) {
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2101
                    if ((index = matchString(text, start, Calendar.AM_PM,
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2102
                                             formatData.getAmPmStrings(), calb)) > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
                        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
                } else {
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2106
                    Map<String,Integer> map = getDisplayNamesMap(field, locale);
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2107
                    if ((index = matchString(text, start, field, map, calb)) > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
                break parsing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2113
            case PATTERN_HOUR1: // 'h' 1-based.  eg, 11PM + 1 hour =>> 12 AM
7502
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2114
                if (!isLenient()) {
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2115
                    // Validate the hour value in non-lenient
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2116
                    if (value < 1 || value > 12) {
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2117
                        break parsing;
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2118
                    }
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2119
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
                // [We computed 'value' above.]
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2121
                if (value == calendar.getLeastMaximum(Calendar.HOUR) + 1) {
7502
fa582c544d55 4396385: [Fmt-Da] SimpleDateFormat too lenient when parsing 1-based hours
okutsu
parents: 7003
diff changeset
  2122
                    value = 0;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2123
                }
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2124
                calb.set(Calendar.HOUR, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
                return pos.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2127
            case PATTERN_ZONE_NAME:  // 'z'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2128
            case PATTERN_ZONE_VALUE: // 'Z'
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
                    int sign = 0;
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2131
                    try {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2132
                        char c = text.charAt(pos.index);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2133
                        if (c == '+') {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2134
                            sign = 1;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2135
                        } else if (c == '-') {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2136
                            sign = -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                        }
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2138
                        if (sign == 0) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2139
                            // Try parsing a custom time zone "GMT+hh:mm" or "GMT".
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2140
                            if ((c == 'G' || c == 'g')
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2141
                                && (text.length() - start) >= GMT.length()
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2142
                                && text.regionMatches(true, start, GMT, 0, GMT.length())) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2143
                                pos.index = start + GMT.length();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2145
                                if ((text.length() - pos.index) > 0) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2146
                                    c = text.charAt(pos.index);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2147
                                    if (c == '+') {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2148
                                        sign = 1;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2149
                                    } else if (c == '-') {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2150
                                        sign = -1;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2151
                                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2154
                                if (sign == 0) {    /* "GMT" without offset */
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2155
                                    calb.set(Calendar.ZONE_OFFSET, 0)
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2156
                                        .set(Calendar.DST_OFFSET, 0);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2157
                                    return pos.index;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2158
                                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2160
                                // Parse the rest as "hh:mm"
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2161
                                int i = subParseNumericZone(text, ++pos.index,
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2162
                                                            sign, 0, true, calb);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2163
                                if (i > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
                                    return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
                                }
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2166
                                pos.index = -i;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2167
                            } else {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2168
                                // Try parsing the text as a time zone
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2169
                                // name or abbreviation.
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2170
                                int i = subParseZoneString(text, pos.index, calb);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2171
                                if (i > 0) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2172
                                    return i;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2173
                                }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2174
                                pos.index = -i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
                            }
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2176
                        } else {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2177
                            // Parse the rest as "hhmm" (RFC 822)
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2178
                            int i = subParseNumericZone(text, ++pos.index,
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2179
                                                        sign, 0, false, calb);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2180
                            if (i > 0) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2181
                                return i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
                            }
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2183
                            pos.index = -i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
                        }
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2185
                    } catch (IndexOutOfBoundsException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
                break parsing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  2190
            case PATTERN_ISO_ZONE:   // 'X'
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  2191
                {
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2192
                    if ((text.length() - pos.index) <= 0) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2193
                        break parsing;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2194
                    }
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  2195
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2196
                    int sign;
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2197
                    char c = text.charAt(pos.index);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2198
                    if (c == 'Z') {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2199
                        calb.set(Calendar.ZONE_OFFSET, 0).set(Calendar.DST_OFFSET, 0);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2200
                        return ++pos.index;
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  2201
                    }
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  2202
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2203
                    // parse text as "+/-hh[[:]mm]" based on count
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2204
                    if (c == '+') {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2205
                        sign = 1;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2206
                    } else if (c == '-') {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2207
                        sign = -1;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2208
                    } else {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2209
                        ++pos.index;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2210
                        break parsing;
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  2211
                    }
7779
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2212
                    int i = subParseNumericZone(text, ++pos.index, sign, count,
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2213
                                                count == 3, calb);
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2214
                    if (i > 0) {
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2215
                        return i;
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2216
                    }
50fa5dbf83e6 6644493: [Fmt-Da] SimpleDateFormat parsing RFC822 time offset is slow
okutsu
parents: 7502
diff changeset
  2217
                    pos.index = -i;
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  2218
                }
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  2219
                break parsing;
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  2220
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
            default:
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2222
         // case PATTERN_DAY_OF_MONTH:         // 'd'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2223
         // case PATTERN_HOUR_OF_DAY0:         // 'H' 0-based.  eg, 23:59 + 1 hour =>> 00:59
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2224
         // case PATTERN_MINUTE:               // 'm'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2225
         // case PATTERN_SECOND:               // 's'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2226
         // case PATTERN_MILLISECOND:          // 'S'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2227
         // case PATTERN_DAY_OF_YEAR:          // 'D'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2228
         // case PATTERN_DAY_OF_WEEK_IN_MONTH: // 'F'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2229
         // case PATTERN_WEEK_OF_YEAR:         // 'w'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2230
         // case PATTERN_WEEK_OF_MONTH:        // 'W'
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2231
         // case PATTERN_HOUR0:                // 'K' 0-based.  eg, 11PM + 1 hour =>> 0 AM
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2232
         // case PATTERN_ISO_DAY_OF_WEEK:      // 'u' (pseudo field);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
                // Handle "generic" fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
                if (obeyCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
                    if ((start+count) > text.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
                        break parsing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
                    number = numberFormat.parse(text.substring(0, start+count), pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
                    number = numberFormat.parse(text, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
                if (number != null) {
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2244
                    value = number.intValue();
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2245
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2246
                    if (useFollowingMinusSignAsDelimiter && (value < 0) &&
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2247
                        (((pos.index < text.length()) &&
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2248
                         (text.charAt(pos.index) != minusSign)) ||
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2249
                         ((pos.index == text.length()) &&
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2250
                          (text.charAt(pos.index-1) == minusSign)))) {
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2251
                        value = -value;
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2252
                        pos.index--;
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2253
                    }
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2254
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2255
                    calb.set(field, value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
                    return pos.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
                break parsing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
        // Parsing failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
        origPos.errorIndex = pos.index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2267
    /**
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2268
     * Returns true if the DateFormatSymbols has been set explicitly or locale
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2269
     * is null.
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2270
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
    private boolean useDateFormatSymbols() {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2272
        return useDateFormatSymbols || locale == null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
     * Translates a pattern, mapping each character in the from string to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
     * corresponding character in the to string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
  2279
     * @throws    IllegalArgumentException if the given pattern is invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
    private String translatePattern(String pattern, String from, String to) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
        StringBuilder result = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
        boolean inQuote = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
        for (int i = 0; i < pattern.length(); ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
            char c = pattern.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
            if (inQuote) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2287
                if (c == '\'') {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
                    inQuote = false;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2289
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
            else {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2292
                if (c == '\'') {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
                    inQuote = true;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2294
                } else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
                    int ci = from.indexOf(c);
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2296
                    if (ci >= 0) {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2297
                        // patternChars is longer than localPatternChars due
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2298
                        // to serialization compatibility. The pattern letters
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2299
                        // unsupported by localPatternChars pass through.
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2300
                        if (ci < to.length()) {
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2301
                            c = to.charAt(ci);
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2302
                        }
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2303
                    } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
                        throw new IllegalArgumentException("Illegal pattern " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
                                                           " character '" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
                                                           c + "'");
6491
cd1bcc5057f4 4267450: (cal) API: Need public API to calculate, format and parse "year of week"
okutsu
parents: 6489
diff changeset
  2307
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
            result.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
        }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2312
        if (inQuote) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
            throw new IllegalArgumentException("Unfinished quote in pattern");
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2314
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
        return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
     * Returns a pattern string describing this date format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     * @return a pattern string describing this date format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
    public String toPattern() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
        return pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
     * Returns a localized pattern string describing this date format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
     * @return a localized pattern string describing this date format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
    public String toLocalizedPattern() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
        return translatePattern(pattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
                                DateFormatSymbols.patternChars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
                                formatData.getLocalPatternChars());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
     * Applies the given pattern string to this date format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
     * @param pattern the new date and time pattern for this date format
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
  2342
     * @throws    NullPointerException if the given pattern is null
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
  2343
     * @throws    IllegalArgumentException if the given pattern is invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
     */
6497
22752a2b3413 4919632: RFE: SimpleDateFormat should fully support ISO8601 standard for timezone
okutsu
parents: 6491
diff changeset
  2345
    public void applyPattern(String pattern)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
    {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2347
        applyPatternImpl(pattern);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2348
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2349
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2350
    private void applyPatternImpl(String pattern) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
        compiledPattern = compile(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
        this.pattern = pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
     * Applies the given localized pattern string to this date format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
     * @param pattern a String to be mapped to the new date and time format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
     *        pattern for this format
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
  2360
     * @throws    NullPointerException if the given pattern is null
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
  2361
     * @throws    IllegalArgumentException if the given pattern is invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
    public void applyLocalizedPattern(String pattern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
         String p = translatePattern(pattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
                                     formatData.getLocalPatternChars(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
                                     DateFormatSymbols.patternChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
         compiledPattern = compile(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
         this.pattern = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
     * Gets a copy of the date and time format symbols of this date format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
     * @return the date and time format symbols of this date format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
     * @see #setDateFormatSymbols
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
    public DateFormatSymbols getDateFormatSymbols()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
        return (DateFormatSymbols)formatData.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
     * Sets the date and time format symbols of this date format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
     * @param newFormatSymbols the new date and time format symbols
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
  2386
     * @throws    NullPointerException if the given newFormatSymbols is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
     * @see #getDateFormatSymbols
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
    public void setDateFormatSymbols(DateFormatSymbols newFormatSymbols)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
        this.formatData = (DateFormatSymbols)newFormatSymbols.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
        useDateFormatSymbols = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
     * Creates a copy of this <code>SimpleDateFormat</code>. This also
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
     * clones the format's date format symbols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
     * @return a clone of this <code>SimpleDateFormat</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2401
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
        SimpleDateFormat other = (SimpleDateFormat) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
        other.formatData = (DateFormatSymbols) formatData.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
        return other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
     * Returns the hash code value for this <code>SimpleDateFormat</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
     * @return the hash code value for this <code>SimpleDateFormat</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2413
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
    public int hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
        return pattern.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
        // just enough fields for a reasonable distribution
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
     * Compares the given object with this <code>SimpleDateFormat</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
     * equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
     * @return true if the given object is equal to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
     * <code>SimpleDateFormat</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2427
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
    public boolean equals(Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
    {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2430
        if (!super.equals(obj)) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2431
            return false; // super does class check
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 11685
diff changeset
  2432
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        SimpleDateFormat that = (SimpleDateFormat) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
        return (pattern.equals(that.pattern)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
                && formatData.equals(that.formatData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
14765
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2438
    private static final int[] REST_OF_STYLES = {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2439
        Calendar.SHORT_STANDALONE, Calendar.LONG_FORMAT, Calendar.LONG_STANDALONE,
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2440
    };
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2441
    private Map<String, Integer> getDisplayNamesMap(int field, Locale locale) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2442
        Map<String, Integer> map = calendar.getDisplayNames(field, Calendar.SHORT_FORMAT, locale);
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2443
        // Get all SHORT and LONG styles (avoid NARROW styles).
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2444
        for (int style : REST_OF_STYLES) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2445
            Map<String, Integer> m = calendar.getDisplayNames(field, style, locale);
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2446
            if (m != null) {
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2447
                map.putAll(m);
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2448
            }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2449
        }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2450
        return map;
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2451
    }
0987999ed367 8000983: Support narrow display names for calendar fields
okutsu
parents: 14014
diff changeset
  2452
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
    /**
53431
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2454
     * Obtains display names map, taking the context into account. Currently only
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2455
     * the month name pattern 'M' is context dependent.
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2456
     */
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2457
    private Map<String, Integer> getDisplayContextNamesMap(int field, Locale locale) {
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2458
        Map<String, Integer> map = calendar.getDisplayNames(field,
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2459
            forceStandaloneForm ? Calendar.SHORT_STANDALONE : Calendar.SHORT_FORMAT, locale);
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2460
        // Get the LONG style
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2461
        Map<String, Integer> m = calendar.getDisplayNames(field,
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2462
            forceStandaloneForm ? Calendar.LONG_STANDALONE : Calendar.LONG_FORMAT, locale);
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2463
        if (m != null) {
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2464
            map.putAll(m);
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2465
        }
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2466
        return map;
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2467
    }
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2468
5abf1da9e9ad 8216969: ParseException thrown for certain months with russian locale
naoto
parents: 51054
diff changeset
  2469
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
     * After reading an object from the input stream, the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
     * pattern in the object is verified.
31061
fead7d86d75f 8081517: minor cleanup for docs
avstepan
parents: 25859
diff changeset
  2472
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
  2473
     * @throws    InvalidObjectException if the pattern is invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
     */
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 54206
diff changeset
  2475
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
    private void readObject(ObjectInputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
                         throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
        stream.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
            compiledPattern = compile(pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
            throw new InvalidObjectException("invalid pattern");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
        if (serialVersionOnStream < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
            // didn't have defaultCenturyStart field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
            initializeDefaultCentury();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
            // fill in dependent transient field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
            parseAmbiguousDatesAsAfter(defaultCenturyStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
        serialVersionOnStream = currentSerialVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
        // If the deserialized object has a SimpleTimeZone, try
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
        // to replace it with a ZoneInfo equivalent in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
        // be compatible with the SimpleTimeZone-based
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
        // implementation as much as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
        TimeZone tz = getTimeZone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
        if (tz instanceof SimpleTimeZone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
            String id = tz.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
            TimeZone zi = TimeZone.getTimeZone(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
            if (zi != null && zi.hasSameRules(tz) && zi.getID().equals(id)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
                setTimeZone(zi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
    }
1313
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2509
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2510
    /**
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2511
     * Analyze the negative subpattern of DecimalFormat and set/update values
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2512
     * as necessary.
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2513
     */
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2514
    private void checkNegativeNumberExpression() {
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2515
        if ((numberFormat instanceof DecimalFormat) &&
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2516
            !numberFormat.equals(originalNumberFormat)) {
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2517
            String numberPattern = ((DecimalFormat)numberFormat).toPattern();
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2518
            if (!numberPattern.equals(originalNumberPattern)) {
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2519
                hasFollowingMinusSign = false;
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2520
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2521
                int separatorIndex = numberPattern.indexOf(';');
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2522
                // If the negative subpattern is not absent, we have to analayze
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2523
                // it in order to check if it has a following minus sign.
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2524
                if (separatorIndex > -1) {
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2525
                    int minusIndex = numberPattern.indexOf('-', separatorIndex);
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2526
                    if ((minusIndex > numberPattern.lastIndexOf('0')) &&
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2527
                        (minusIndex > numberPattern.lastIndexOf('#'))) {
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2528
                        hasFollowingMinusSign = true;
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2529
                        minusSign = ((DecimalFormat)numberFormat).getDecimalFormatSymbols().getMinusSign();
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2530
                    }
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2531
                }
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2532
                originalNumberPattern = numberPattern;
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2533
            }
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2534
            originalNumberFormat = numberFormat;
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2535
        }
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2536
    }
f9151e9e2f50 4823811: [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
peytoia
parents: 1312
diff changeset
  2537
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
}