src/java.base/share/classes/java/text/DateFormat.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
/*
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 48251
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 - 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.InvalidObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.text.spi.DateFormatProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.Calendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.GregorianCalendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.TimeZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.spi.LocaleServiceProvider;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
    53
import sun.util.locale.provider.LocaleProviderAdapter;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
    54
import sun.util.locale.provider.LocaleServiceProviderPool;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/**
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
    57
 * {@code DateFormat} is an abstract class for date/time formatting subclasses which
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * formats and parses dates or time in a language-independent manner.
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
    59
 * The date/time formatting subclass, such as {@link SimpleDateFormat}, allows for
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    60
 * formatting (i.e., date → text), parsing (text → date), and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * normalization.  The date is represented as a <code>Date</code> object or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * as the milliseconds since January 1, 1970, 00:00:00 GMT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
    64
 * <p>{@code DateFormat} provides many class methods for obtaining default date/time
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * formatters based on the default or a given locale and a number of formatting
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
    66
 * styles. The formatting styles include {@link #FULL}, {@link #LONG}, {@link #MEDIUM}, and {@link #SHORT}. More
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * detail and examples of using these styles are provided in the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * descriptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
    70
 * <p>{@code DateFormat} helps you to format and parse dates for any locale.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Your code can be completely independent of the locale conventions for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * months, days of the week, or even the calendar format: lunar vs. solar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p>To format a date for the current Locale, use one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * static factory methods:
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    76
 * <blockquote>
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    77
 * <pre>{@code
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    78
 * myString = DateFormat.getDateInstance().format(myDate);
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    79
 * }</pre>
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    80
 * </blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <p>If you are formatting multiple dates, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * more efficient to get the format and use it multiple times so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * the system doesn't have to fetch the information about the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * language and country conventions multiple times.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    85
 * <blockquote>
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    86
 * <pre>{@code
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    87
 * DateFormat df = DateFormat.getDateInstance();
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    88
 * for (int i = 0; i < myDate.length; ++i) {
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    89
 *     output.println(df.format(myDate[i]) + "; ");
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    90
 * }
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    91
 * }</pre>
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    92
 * </blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * <p>To format a date for a different Locale, specify it in the
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
    94
 * call to {@link #getDateInstance(int, Locale) getDateInstance()}.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    95
 * <blockquote>
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    96
 * <pre>{@code
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    97
 * DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    98
 * }</pre>
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    99
 * </blockquote>
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   100
 *
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   101
 * <p>If the specified locale contains "ca" (calendar), "rg" (region override),
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   102
 * and/or "tz" (timezone) <a href="../util/Locale.html#def_locale_extension">Unicode
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   103
 * extensions</a>, the calendar, the country and/or the time zone for formatting
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   104
 * are overridden. If both "ca" and "rg" are specified, the calendar from the "ca"
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   105
 * extension supersedes the implicit one from the "rg" extension.
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   106
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <p>You can use a DateFormat to parse also.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   108
 * <blockquote>
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   109
 * <pre>{@code
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   110
 * myDate = df.parse(myString);
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   111
 * }</pre>
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   112
 * </blockquote>
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   113
 * <p>Use {@code getDateInstance} to get the normal date format for that country.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * There are other static factory methods available.
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   115
 * Use {@code getTimeInstance} to get the time format for that country.
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   116
 * Use {@code getDateTimeInstance} to get a date and time format. You can pass in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * different options to these factory methods to control the length of the
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   118
 * result; from {@link #SHORT} to {@link #MEDIUM} to {@link #LONG} to {@link #FULL}. The exact result depends
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * on the locale, but generally:
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   120
 * <ul><li>{@link #SHORT} is completely numeric, such as {@code 12.13.52} or {@code 3:30pm}
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   121
 * <li>{@link #MEDIUM} is longer, such as {@code Jan 12, 1952}
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   122
 * <li>{@link #LONG} is longer, such as {@code January 12, 1952} or {@code 3:30:32pm}
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   123
 * <li>{@link #FULL} is pretty completely specified, such as
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   124
 * {@code Tuesday, April 12, 1952 AD or 3:30:42pm PST}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * <p>You can also set the time zone on the format if you wish.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * If you want even more control over the format or parsing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * (or want to give your users more control),
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   130
 * you can try casting the {@code DateFormat} you get from the factory methods
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   131
 * to a {@link SimpleDateFormat}. This will work for the majority
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   132
 * of countries; just remember to put it in a {@code try} block in case you
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * encounter an unusual one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * <p>You can also use forms of the parse and format methods with
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   136
 * {@link ParsePosition} and {@link FieldPosition} to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * allow you to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * <ul><li>progressively parse through pieces of a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * <li>align any particular field, or find out where it is for selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 *
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 48251
diff changeset
   143
 * <h2><a id="synchronization">Synchronization</a></h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * Date formats are not synchronized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * It is recommended to create separate format instances for each thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * If multiple threads access a format concurrently, it must be synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * externally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *
43011
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   151
 * @implSpec
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   152
 * <ul><li>The {@link #format(Date, StringBuffer, FieldPosition)} and
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   153
 * {@link #parse(String, ParsePosition)} methods may throw
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   154
 * {@code NullPointerException}, if any of their parameter is {@code null}.
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   155
 * The subclass may provide its own implementation and specification about
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   156
 * {@code NullPointerException}.</li>
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   157
 * <li>The {@link #setCalendar(Calendar)}, {@link
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   158
 * #setNumberFormat(NumberFormat)} and {@link #setTimeZone(TimeZone)} methods
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   159
 * do not throw {@code NullPointerException} when their parameter is
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   160
 * {@code null}, but any subsequent operations on the same instance may throw
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   161
 * {@code NullPointerException}.</li>
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   162
 * <li>The {@link #getCalendar()}, {@link #getNumberFormat()} and
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   163
 * {@link getTimeZone()} methods may return {@code null}, if the respective
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   164
 * values of this instance is set to {@code null} through the corresponding
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   165
 * setter methods. For Example: {@link #getTimeZone()} may return {@code null},
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   166
 * if the {@code TimeZone} value of this instance is set as
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   167
 * {@link #setTimeZone(java.util.TimeZone) setTimeZone(null)}.</li>
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   168
 * </ul>
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   169
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * @see          Format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * @see          NumberFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * @see          SimpleDateFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * @see          java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * @see          java.util.GregorianCalendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * @see          java.util.TimeZone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * @author       Mark Davis, Chen-Lieh Huang, Alan Liu
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 44844
diff changeset
   177
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
public abstract class DateFormat extends Format {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   182
     * The {@link Calendar} instance used for calculating the date-time fields
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   183
     * and the instant of time. This field is used for both formatting and
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   184
     * parsing.
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   185
     *
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   186
     * <p>Subclasses should initialize this field to a {@link Calendar}
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   187
     * appropriate for the {@link Locale} associated with this
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   188
     * <code>DateFormat</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    protected Calendar calendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * The number formatter that <code>DateFormat</code> uses to format numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * in dates and times.  Subclasses should initialize this to a number format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * appropriate for the locale associated with this <code>DateFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    protected NumberFormat numberFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Useful constant for ERA field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   205
    public static final int ERA_FIELD = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Useful constant for YEAR field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   210
    public static final int YEAR_FIELD = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Useful constant for MONTH field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   215
    public static final int MONTH_FIELD = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Useful constant for DATE field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   220
    public static final int DATE_FIELD = 3;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Useful constant for one-based HOUR_OF_DAY field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * For example, 23:59 + 01:00 results in 24:59.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   227
    public static final int HOUR_OF_DAY1_FIELD = 4;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Useful constant for zero-based HOUR_OF_DAY field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * For example, 23:59 + 01:00 results in 00:59.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   234
    public static final int HOUR_OF_DAY0_FIELD = 5;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Useful constant for MINUTE field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   239
    public static final int MINUTE_FIELD = 6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Useful constant for SECOND field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   244
    public static final int SECOND_FIELD = 7;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Useful constant for MILLISECOND field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   249
    public static final int MILLISECOND_FIELD = 8;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Useful constant for DAY_OF_WEEK field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   254
    public static final int DAY_OF_WEEK_FIELD = 9;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Useful constant for DAY_OF_YEAR field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   259
    public static final int DAY_OF_YEAR_FIELD = 10;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Useful constant for DAY_OF_WEEK_IN_MONTH field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   264
    public static final int DAY_OF_WEEK_IN_MONTH_FIELD = 11;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Useful constant for WEEK_OF_YEAR field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   269
    public static final int WEEK_OF_YEAR_FIELD = 12;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Useful constant for WEEK_OF_MONTH field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   274
    public static final int WEEK_OF_MONTH_FIELD = 13;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Useful constant for AM_PM field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   279
    public static final int AM_PM_FIELD = 14;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Useful constant for one-based HOUR field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * HOUR1_FIELD is used for the one-based 12-hour clock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * For example, 11:30 PM + 1 hour results in 12:30 AM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   286
    public static final int HOUR1_FIELD = 15;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Useful constant for zero-based HOUR field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * HOUR0_FIELD is used for the zero-based 12-hour clock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * For example, 11:30 PM + 1 hour results in 00:30 AM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   293
    public static final int HOUR0_FIELD = 16;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Useful constant for TIMEZONE field alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Used in FieldPosition of date/time formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   298
    public static final int TIMEZONE_FIELD = 17;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    // Proclaim serial compatibility with 1.1 FCS
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 54206
diff changeset
   301
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    private static final long serialVersionUID = 7218322306649953788L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
48026
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   305
     * Formats the given {@code Object} into a date-time string. The formatted
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   306
     * string is appended to the given {@code StringBuffer}.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   307
     *
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   308
     * @param obj Must be a {@code Date} or a {@code Number} representing a
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   309
     * millisecond offset from the <a href="../util/Calendar.html#Epoch">Epoch</a>.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   310
     * @param toAppendTo The string buffer for the returning date-time string.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   311
     * @param fieldPosition keeps track on the position of the field within
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   312
     * the returned string. For example, given a date-time text
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   313
     * {@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
   314
     * 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
   315
     * {@code fieldPosition} will be set to 0 and 4, respectively.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   316
     * 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
   317
     * 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
   318
     * 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
   319
     * 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
   320
     * pattern {@code "h a z (zzzz)"} and the alignment field
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   321
     * {@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
   322
     * {@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
   323
     * first occurrence of the timezone pattern character {@code 'z'}.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   324
     * @return the string buffer passed in as {@code toAppendTo},
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   325
     *         with formatted text appended.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   326
     * @throws    IllegalArgumentException if the {@code Format} cannot format
43011
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   327
     *            the given {@code obj}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @see java.text.Format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public final StringBuffer format(Object obj, StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                                     FieldPosition fieldPosition)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (obj instanceof Date)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            return format( (Date)obj, toAppendTo, fieldPosition );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        else if (obj instanceof Number)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            return format( new Date(((Number)obj).longValue()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                          toAppendTo, fieldPosition );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            throw new IllegalArgumentException("Cannot format given Object as a Date");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
48026
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   343
     * Formats a {@link Date} into a date-time string. The formatted
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   344
     * string is appended to the given {@code StringBuffer}.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   345
     *
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   346
     * @param date a Date to be formatted into a date-time string.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   347
     * @param toAppendTo the string buffer for the returning date-time string.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   348
     * @param fieldPosition keeps track on the position of the field within
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   349
     * the returned string. For example, given a date-time text
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   350
     * {@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
   351
     * 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
   352
     * {@code fieldPosition} will be set to 0 and 4, respectively.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   353
     * 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
   354
     * 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
   355
     * 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
   356
     * 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
   357
     * pattern {@code "h a z (zzzz)"} and the alignment field
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   358
     * {@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
   359
     * {@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
   360
     * first occurrence of the timezone pattern character {@code 'z'}.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   361
     * @return the string buffer passed in as {@code toAppendTo}, with formatted
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   362
     * text appended.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public abstract StringBuffer format(Date date, StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                        FieldPosition fieldPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /**
48026
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   368
      * Formats a {@link Date} into a date-time string.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   369
      *
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   370
      * @param date the time value to be formatted into a date-time string.
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   371
      * @return the formatted date-time string.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public final String format(Date date)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return format(date, new StringBuffer(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                      DontCareFieldPosition.INSTANCE).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * Parses text from the beginning of the given string to produce a date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * The method may not use the entire text of the given string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * See the {@link #parse(String, ParsePosition)} method for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * on date parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @param source A <code>String</code> whose beginning should be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @return A <code>Date</code> parsed from the string.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   388
     * @throws    ParseException if the beginning of the specified string
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *            cannot be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public Date parse(String source) throws ParseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        ParsePosition pos = new ParsePosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        Date result = parse(source, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (pos.index == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            throw new ParseException("Unparseable date: \"" + source + "\"" ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                pos.errorIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Parse a date/time string according to the given parse position.  For
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   403
     * example, a time text {@code "07/10/96 4:5 PM, PDT"} will be parsed into a {@code Date}
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   404
     * that is equivalent to {@code Date(837039900000L)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * <p> By default, parsing is lenient: If the input is not in the form used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * by this object's format method but can still be parsed as a date, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * the parse succeeds.  Clients may insist on strict adherence to the
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   409
     * format by calling {@link #setLenient(boolean) setLenient(false)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   411
     * <p>This parsing operation uses the {@link #calendar} to produce
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   412
     * a {@code Date}. As a result, the {@code calendar}'s date-time
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   413
     * fields and the {@code TimeZone} value may have been
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   414
     * overwritten, depending on subclass implementations. Any {@code
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   415
     * 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: 2
diff changeset
   416
     * {@link #setTimeZone(java.util.TimeZone) setTimeZone} may need
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   417
     * to be restored for further operations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @param source  The date/time string to be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @param pos   On input, the position at which to start parsing; on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *              output, the position at which parsing terminated, or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *              start position if the parse failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   425
     * @return      A {@code Date}, or {@code null} if the input could not be parsed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    public abstract Date parse(String source, ParsePosition pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * Parses text from a string to produce a <code>Date</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * The method attempts to parse text starting at the index given by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * <code>pos</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * If parsing succeeds, then the index of <code>pos</code> is updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * to the index after the last character used (parsing does not necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * use all characters up to the end of the string), and the parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * date is returned. The updated <code>pos</code> can be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * indicate the starting point for the next call to this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * If an error occurs, then the index of <code>pos</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * changed, the error index of <code>pos</code> is set to the index of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * the character where the error occurred, and null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * See the {@link #parse(String, ParsePosition)} method for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * on date parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @param source A <code>String</code>, part of which should be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param pos A <code>ParsePosition</code> object with index and error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *            index information as described above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @return A <code>Date</code> parsed from the string. In case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *         error, returns null.
34328
0534cb944d0e 8073211: javadoc of Format parseObject methods should specify NullPointerExceptions
okutsu
parents: 32649
diff changeset
   451
     * @throws NullPointerException if {@code source} or {@code pos} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    public Object parseObject(String source, ParsePosition pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        return parse(source, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * Constant for full style pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public static final int FULL = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * Constant for long style pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public static final int LONG = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * Constant for medium style pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    public static final int MEDIUM = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * Constant for short style pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public static final int SHORT = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Constant for default style pattern.  Its value is MEDIUM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public static final int DEFAULT = MEDIUM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * Gets the time formatter with the default formatting style
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   480
     * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   481
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   482
     * {@link #getTimeInstance(int, Locale) getTimeInstance(DEFAULT,
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   483
     *     Locale.getDefault(Locale.Category.FORMAT))}.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   484
     * @see java.util.Locale#getDefault(java.util.Locale.Category)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   485
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @return a time formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   488
    public static final DateFormat getTimeInstance()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   490
        return get(DEFAULT, 0, 1, Locale.getDefault(Locale.Category.FORMAT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * Gets the time formatter with the given formatting style
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   495
     * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   496
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   497
     * {@link #getTimeInstance(int, Locale) getTimeInstance(style,
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   498
     *     Locale.getDefault(Locale.Category.FORMAT))}.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   499
     * @see java.util.Locale#getDefault(java.util.Locale.Category)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   500
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @param style the given formatting style. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * SHORT for "h:mm a" in the US locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @return a time formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   505
    public static final DateFormat getTimeInstance(int style)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   507
        return get(style, 0, 1, Locale.getDefault(Locale.Category.FORMAT));
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Gets the time formatter with the given formatting style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * for the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @param style the given formatting style. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * SHORT for "h:mm a" in the US locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @param aLocale the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @return a time formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   518
    public static final DateFormat getTimeInstance(int style,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                                                 Locale aLocale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        return get(style, 0, 1, aLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * Gets the date formatter with the default formatting style
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   526
     * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   527
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   528
     * {@link #getDateInstance(int, Locale) getDateInstance(DEFAULT,
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   529
     *     Locale.getDefault(Locale.Category.FORMAT))}.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   530
     * @see java.util.Locale#getDefault(java.util.Locale.Category)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   531
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @return a date formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   534
    public static final DateFormat getDateInstance()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   536
        return get(0, DEFAULT, 2, Locale.getDefault(Locale.Category.FORMAT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * Gets the date formatter with the given formatting style
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   541
     * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   542
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   543
     * {@link #getDateInstance(int, Locale) getDateInstance(style,
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   544
     *     Locale.getDefault(Locale.Category.FORMAT))}.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   545
     * @see java.util.Locale#getDefault(java.util.Locale.Category)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   546
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @param style the given formatting style. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * SHORT for "M/d/yy" in the US locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @return a date formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   551
    public static final DateFormat getDateInstance(int style)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   553
        return get(0, style, 2, Locale.getDefault(Locale.Category.FORMAT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * Gets the date formatter with the given formatting style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * for the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @param style the given formatting style. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * SHORT for "M/d/yy" in the US locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @param aLocale the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @return a date formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   564
    public static final DateFormat getDateInstance(int style,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                                                 Locale aLocale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        return get(0, style, 2, aLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * Gets the date/time formatter with the default formatting style
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   572
     * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   573
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   574
     * {@link #getDateTimeInstance(int, int, Locale) getDateTimeInstance(DEFAULT,
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   575
     *     DEFAULT, Locale.getDefault(Locale.Category.FORMAT))}.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   576
     * @see java.util.Locale#getDefault(java.util.Locale.Category)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   577
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @return a date/time formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   580
    public static final DateFormat getDateTimeInstance()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   582
        return get(DEFAULT, DEFAULT, 3, Locale.getDefault(Locale.Category.FORMAT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * Gets the date/time formatter with the given date and time
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   587
     * formatting styles for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   588
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   589
     * {@link #getDateTimeInstance(int, int, Locale) getDateTimeInstance(dateStyle,
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   590
     *     timeStyle, Locale.getDefault(Locale.Category.FORMAT))}.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   591
     * @see java.util.Locale#getDefault(java.util.Locale.Category)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 14342
diff changeset
   592
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @param dateStyle the given date formatting style. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * SHORT for "M/d/yy" in the US locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * @param timeStyle the given time formatting style. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * SHORT for "h:mm a" in the US locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @return a date/time formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   599
    public static final DateFormat getDateTimeInstance(int dateStyle,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                                                       int timeStyle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   602
        return get(timeStyle, dateStyle, 3, Locale.getDefault(Locale.Category.FORMAT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * Gets the date/time formatter with the given formatting styles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * for the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @param dateStyle the given date formatting style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @param timeStyle the given time formatting style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @param aLocale the given locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @return a date/time formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   613
    public static final DateFormat
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        return get(timeStyle, dateStyle, 3, aLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * Get a default date/time formatter that uses the SHORT style for both the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * date and the time.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   622
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   623
     * @return a date/time formatter
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   625
    public static final DateFormat getInstance() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        return getDateTimeInstance(SHORT, SHORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * Returns an array of all locales for which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * <code>get*Instance</code> methods of this class can return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * localized instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * The returned array represents the union of locales supported by the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * runtime and by installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * {@link java.text.spi.DateFormatProvider DateFormatProvider} implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * It must contain at least a <code>Locale</code> instance equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * {@link java.util.Locale#US Locale.US}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @return An array of locales for which localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *         <code>DateFormat</code> instances are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public static Locale[] getAvailableLocales()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        LocaleServiceProviderPool pool =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            LocaleServiceProviderPool.getPool(DateFormatProvider.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        return pool.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * Set the calendar to be used by this date format.  Initially, the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * calendar for the specified or default locale is used.
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   652
     *
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   653
     * <p>Any {@link java.util.TimeZone TimeZone} and {@linkplain
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   654
     * #isLenient() leniency} values that have previously been set are
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   655
     * overwritten by {@code newCalendar}'s values.
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   656
     *
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   657
     * @param newCalendar the new {@code Calendar} to be used by the date format
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    public void setCalendar(Calendar newCalendar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        this.calendar = newCalendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * Gets the calendar associated with this date/time formatter.
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   666
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * @return the calendar associated with this date/time formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    public Calendar getCalendar()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        return calendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * Allows you to set the number formatter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @param newNumberFormat the given new NumberFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    public void setNumberFormat(NumberFormat newNumberFormat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        this.numberFormat = newNumberFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * Gets the number formatter which this date/time formatter uses to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * format and parse a time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @return the number formatter which this date/time formatter uses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    public NumberFormat getNumberFormat()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        return numberFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    /**
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   694
     * Sets the time zone for the calendar of this {@code DateFormat} object.
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   695
     * This method is equivalent to the following call.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   696
     * <blockquote><pre>{@code
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   697
     * getCalendar().setTimeZone(zone)
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   698
     * }</pre></blockquote>
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   699
     *
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   700
     * <p>The {@code TimeZone} set by this method is overwritten by a
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   701
     * {@link #setCalendar(java.util.Calendar) setCalendar} call.
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   702
     *
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   703
     * <p>The {@code TimeZone} set by this method may be overwritten as
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   704
     * a result of a call to the parse method.
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   705
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @param zone the given new time zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    public void setTimeZone(TimeZone zone)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        calendar.setTimeZone(zone);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * Gets the time zone.
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   715
     * This method is equivalent to the following call.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   716
     * <blockquote><pre>{@code
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   717
     * getCalendar().getTimeZone()
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   718
     * }</pre></blockquote>
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   719
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * @return the time zone associated with the calendar of DateFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    public TimeZone getTimeZone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        return calendar.getTimeZone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * Specify whether or not date/time parsing is to be lenient.  With
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * lenient parsing, the parser may use heuristics to interpret inputs that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * do not precisely match this object's format.  With strict parsing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * inputs must match this object's format.
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   732
     *
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   733
     * <p>This method is equivalent to the following call.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   734
     * <blockquote><pre>{@code
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   735
     * getCalendar().setLenient(lenient)
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   736
     * }</pre></blockquote>
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   737
     *
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   738
     * <p>This leniency value is overwritten by a call to {@link
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   739
     * #setCalendar(java.util.Calendar) setCalendar()}.
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   740
     *
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   741
     * @param lenient when {@code true}, parsing is lenient
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   742
     * @see java.util.Calendar#setLenient(boolean)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    public void setLenient(boolean lenient)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        calendar.setLenient(lenient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * Tell whether date/time parsing is to be lenient.
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   751
     * This method is equivalent to the following call.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   752
     * <blockquote><pre>{@code
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   753
     * getCalendar().isLenient()
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   754
     * }</pre></blockquote>
5283
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   755
     *
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   756
     * @return {@code true} if the {@link #calendar} is lenient;
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   757
     *         {@code false} otherwise.
c440afed922d 6609675: [Fmt-Da] DateFormat.parse() on a timezone changes its calendar's timezone
okutsu
parents: 2
diff changeset
   758
     * @see java.util.Calendar#isLenient()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    public boolean isLenient()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        return calendar.isLenient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * Overrides hashCode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        return numberFormat.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        // just enough fields for a reasonable distribution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * Overrides equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        if (this == obj) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        if (obj == null || getClass() != obj.getClass()) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        DateFormat other = (DateFormat) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        return (// calendar.equivalentTo(other.calendar) // THIS API DOESN'T EXIST YET!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                calendar.getFirstDayOfWeek() == other.calendar.getFirstDayOfWeek() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                calendar.getMinimalDaysInFirstWeek() == other.calendar.getMinimalDaysInFirstWeek() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                calendar.isLenient() == other.calendar.isLenient() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                calendar.getTimeZone().equals(other.calendar.getTimeZone()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                numberFormat.equals(other.numberFormat));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * Overrides Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    public Object clone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        DateFormat other = (DateFormat) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        other.calendar = (Calendar) calendar.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        other.numberFormat = (NumberFormat) numberFormat.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        return other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * Creates a DateFormat with the given time and/or date style in the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @param timeStyle a value from 0 to 3 indicating the time format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * ignored if flags is 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * @param dateStyle a value from 0 to 3 indicating the time format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * ignored if flags is 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * @param flags either 1 for a time format, 2 for a date format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * or 3 for a date/time format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * @param loc the locale for the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    private static DateFormat get(int timeStyle, int dateStyle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                                  int flags, Locale loc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        if ((flags & 1) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            if (timeStyle < 0 || timeStyle > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                throw new IllegalArgumentException("Illegal time style " + timeStyle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            timeStyle = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        if ((flags & 2) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            if (dateStyle < 0 || dateStyle > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                throw new IllegalArgumentException("Illegal date style " + dateStyle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            dateStyle = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   826
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   827
        LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, loc);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   828
        DateFormat dateFormat = get(adapter, timeStyle, dateStyle, loc);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   829
        if (dateFormat == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   830
            dateFormat = get(LocaleProviderAdapter.forJRE(), timeStyle, dateStyle, loc);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   831
        }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   832
        return dateFormat;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   833
    }
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   834
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   835
    private static DateFormat get(LocaleProviderAdapter adapter, int timeStyle, int dateStyle, Locale loc) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   836
        DateFormatProvider provider = adapter.getDateFormatProvider();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   837
        DateFormat dateFormat;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   838
        if (timeStyle == -1) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   839
            dateFormat = provider.getDateInstance(dateStyle, loc);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   840
        } else {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   841
            if (dateStyle == -1) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   842
                dateFormat = provider.getTimeInstance(timeStyle, loc);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   843
            } else {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   844
                dateFormat = provider.getDateTimeInstance(dateStyle, timeStyle, loc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   847
        return dateFormat;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * Create a new date format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    protected DateFormat() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * Defines constants that are used as attribute keys in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * <code>AttributedCharacterIterator</code> returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * from <code>DateFormat.formatToCharacterIterator</code> and as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * field identifiers in <code>FieldPosition</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * The class also provides two methods to map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * between its constants and the corresponding Calendar constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @see java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    public static class Field extends Format.Field {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        // Proclaim serial compatibility with 1.4 FCS
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 54206
diff changeset
   870
        @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        private static final long serialVersionUID = 7441350119349544720L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        // table of all instances in this class, used by readResolve
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
   874
        private static final Map<String, Field> instanceMap = new HashMap<>(18);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        // Maps from Calendar constant (such as Calendar.ERA) to Field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        // constant (such as Field.ERA).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        private static final Field[] calendarToFieldMapping =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                                             new Field[Calendar.FIELD_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        /** Calendar field. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        private int calendarField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         * Returns the <code>Field</code> constant that corresponds to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
         * the <code>Calendar</code> constant <code>calendarField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
         * If there is no direct mapping between the <code>Calendar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
         * constant and a <code>Field</code>, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
         * @throws IllegalArgumentException if <code>calendarField</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
         *         not the value of a <code>Calendar</code> field constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
         * @param calendarField Calendar field constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
         * @return Field instance representing calendarField.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
         * @see java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        public static Field ofCalendarField(int calendarField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            if (calendarField < 0 || calendarField >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                        calendarToFieldMapping.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                throw new IllegalArgumentException("Unknown Calendar constant "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                                                   + calendarField);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            return calendarToFieldMapping[calendarField];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
         * Creates a <code>Field</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
         * @param name the name of the <code>Field</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
         * @param calendarField the <code>Calendar</code> constant this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
         *        <code>Field</code> corresponds to; any value, even one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
         *        outside the range of legal <code>Calendar</code> values may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
         *        be used, but <code>-1</code> should be used for values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
         *        that don't correspond to legal <code>Calendar</code> values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        protected Field(String name, int calendarField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            this.calendarField = calendarField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            if (this.getClass() == DateFormat.Field.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                instanceMap.put(name, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                if (calendarField >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                    // assert(calendarField < Calendar.FIELD_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                    calendarToFieldMapping[calendarField] = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
         * Returns the <code>Calendar</code> field associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
         * attribute. For example, if this represents the hours field of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
         * a <code>Calendar</code>, this would return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
         * <code>Calendar.HOUR</code>. If there is no corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
         * <code>Calendar</code> constant, this will return -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
         * @return Calendar constant for this field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
         * @see java.util.Calendar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        public int getCalendarField() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            return calendarField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
         * Resolves instances being deserialized to the predefined constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
         * @throws InvalidObjectException if the constant could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
         *         resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
         * @return resolved DateFormat.Field constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
         */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   947
        @Override
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 54206
diff changeset
   948
        @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        protected Object readResolve() throws InvalidObjectException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            if (this.getClass() != DateFormat.Field.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                throw new InvalidObjectException("subclass didn't correctly implement readResolve");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            Object instance = instanceMap.get(getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            if (instance != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                return instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                throw new InvalidObjectException("unknown attribute name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        // The constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
         * Constant identifying the era field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   969
        public static final Field ERA = new Field("era", Calendar.ERA);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
         * Constant identifying the year field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   974
        public static final Field YEAR = new Field("year", Calendar.YEAR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
         * Constant identifying the month field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   979
        public static final Field MONTH = new Field("month", Calendar.MONTH);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
         * Constant identifying the day of month field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   984
        public static final Field DAY_OF_MONTH = new
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                            Field("day of month", Calendar.DAY_OF_MONTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
         * Constant identifying the hour of day field, where the legal values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
         * are 1 to 24.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   991
        public static final Field HOUR_OF_DAY1 = new Field("hour of day 1",-1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
         * Constant identifying the hour of day field, where the legal values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
         * are 0 to 23.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   997
        public static final Field HOUR_OF_DAY0 = new
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
               Field("hour of day", Calendar.HOUR_OF_DAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
         * Constant identifying the minute field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1003
        public static final Field MINUTE =new Field("minute", Calendar.MINUTE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
         * Constant identifying the second field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1008
        public static final Field SECOND =new Field("second", Calendar.SECOND);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
         * Constant identifying the millisecond field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1013
        public static final Field MILLISECOND = new
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                Field("millisecond", Calendar.MILLISECOND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
         * Constant identifying the day of week field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1019
        public static final Field DAY_OF_WEEK = new
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                Field("day of week", Calendar.DAY_OF_WEEK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
         * Constant identifying the day of year field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1025
        public static final Field DAY_OF_YEAR = new
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                Field("day of year", Calendar.DAY_OF_YEAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
         * Constant identifying the day of week field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1031
        public static final Field DAY_OF_WEEK_IN_MONTH =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                     new Field("day of week in month",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                                            Calendar.DAY_OF_WEEK_IN_MONTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
         * Constant identifying the week of year field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1038
        public static final Field WEEK_OF_YEAR = new
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
              Field("week of year", Calendar.WEEK_OF_YEAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
         * Constant identifying the week of month field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1044
        public static final Field WEEK_OF_MONTH = new
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            Field("week of month", Calendar.WEEK_OF_MONTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
         * Constant identifying the time of day indicator
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
         * (e.g. "a.m." or "p.m.") field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1051
        public static final Field AM_PM = new
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                            Field("am pm", Calendar.AM_PM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
         * Constant identifying the hour field, where the legal values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
         * 1 to 12.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1058
        public static final Field HOUR1 = new Field("hour 1", -1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
         * Constant identifying the hour field, where the legal values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
         * 0 to 11.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1064
        public static final Field HOUR0 = new
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                            Field("hour", Calendar.HOUR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
         * Constant identifying the time zone field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
         */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
  1070
        public static final Field TIME_ZONE = new Field("time zone", -1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
}