3261N/A * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved 0N/A * (C) Copyright IBM Corp. 1996 - All Rights Reserved 0N/A * The original version of this source code and documentation is copyrighted 0N/A * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These 0N/A * materials are provided under terms of a License Agreement between Taligent 0N/A * and Sun. This technology is protected by multiple US and International 0N/A * patents. This notice and attribution to Taligent may not be removed. 0N/A * Taligent is a registered trademark of Taligent, Inc. 2293N/A * {@code DateFormat} is an abstract class for date/time formatting subclasses which 0N/A * formats and parses dates or time in a language-independent manner. 2293N/A * The date/time formatting subclass, such as {@link SimpleDateFormat}, allows for 0N/A * formatting (i.e., date -> text), parsing (text -> date), and 0N/A * normalization. The date is represented as a <code>Date</code> object or 0N/A * as the milliseconds since January 1, 1970, 00:00:00 GMT. 2293N/A * <p>{@code DateFormat} provides many class methods for obtaining default date/time 0N/A * formatters based on the default or a given locale and a number of formatting 2293N/A * styles. The formatting styles include {@link #FULL}, {@link #LONG}, {@link #MEDIUM}, and {@link #SHORT}. More 0N/A * detail and examples of using these styles are provided in the method 2293N/A * <p>{@code DateFormat} helps you to format and parse dates for any locale. 0N/A * Your code can be completely independent of the locale conventions for 0N/A * months, days of the week, or even the calendar format: lunar vs. solar. 0N/A * <p>To format a date for the current Locale, use one of the 0N/A * static factory methods: 0N/A * myString = DateFormat.getDateInstance().format(myDate); 0N/A * <p>If you are formatting multiple dates, it is 0N/A * more efficient to get the format and use it multiple times so that 0N/A * the system doesn't have to fetch the information about the local 0N/A * language and country conventions multiple times. 0N/A * DateFormat df = DateFormat.getDateInstance(); 0N/A * for (int i = 0; i < myDate.length; ++i) { 0N/A * output.println(df.format(myDate[i]) + "; "); 0N/A * <p>To format a date for a different Locale, specify it in the 2293N/A * call to {@link #getDateInstance(int, Locale) getDateInstance()}. 0N/A * DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE); 0N/A * <p>You can use a DateFormat to parse also. 0N/A * myDate = df.parse(myString); 2293N/A * <p>Use {@code getDateInstance} to get the normal date format for that country. 0N/A * There are other static factory methods available. 2293N/A * Use {@code getTimeInstance} to get the time format for that country. 2293N/A * Use {@code getDateTimeInstance} to get a date and time format. You can pass in 0N/A * different options to these factory methods to control the length of the 2293N/A * result; from {@link #SHORT} to {@link #MEDIUM} to {@link #LONG} to {@link #FULL}. The exact result depends 0N/A * on the locale, but generally: 2293N/A * <ul><li>{@link #SHORT} is completely numeric, such as {@code 12.13.52} or {@code 3:30pm} 2293N/A * <li>{@link #MEDIUM} is longer, such as {@code Jan 12, 1952} 2293N/A * <li>{@link #LONG} is longer, such as {@code January 12, 1952} or {@code 3:30:32pm} 2293N/A * <li>{@link #FULL} is pretty completely specified, such as 2293N/A * {@code Tuesday, April 12, 1952 AD or 3:30:42pm PST}. 0N/A * <p>You can also set the time zone on the format if you wish. 0N/A * If you want even more control over the format or parsing, 0N/A * (or want to give your users more control), 2293N/A * you can try casting the {@code DateFormat} you get from the factory methods 2293N/A * to a {@link SimpleDateFormat}. This will work for the majority 2293N/A * of countries; just remember to put it in a {@code try} block in case you 0N/A * encounter an unusual one. 0N/A * <p>You can also use forms of the parse and format methods with 2293N/A * {@link ParsePosition} and {@link FieldPosition} to 0N/A * <ul><li>progressively parse through pieces of a string. 0N/A * <li>align any particular field, or find out where it is for selection 0N/A * <h4><a name="synchronization">Synchronization</a></h4> 0N/A * Date formats are not synchronized. 0N/A * It is recommended to create separate format instances for each thread. 0N/A * If multiple threads access a format concurrently, it must be synchronized 0N/A * @see SimpleDateFormat 0N/A * @see java.util.Calendar 0N/A * @see java.util.GregorianCalendar 0N/A * @see java.util.TimeZone 0N/A * @author Mark Davis, Chen-Lieh Huang, Alan Liu 2293N/A * The {@link Calendar} instance used for calculating the date-time fields 2293N/A * and the instant of time. This field is used for both formatting and 2293N/A * <p>Subclasses should initialize this field to a {@link Calendar} 2293N/A * appropriate for the {@link Locale} associated with this 0N/A * The number formatter that <code>DateFormat</code> uses to format numbers 0N/A * in dates and times. Subclasses should initialize this to a number format 0N/A * appropriate for the locale associated with this <code>DateFormat</code>. 0N/A * Useful constant for ERA field alignment. 0N/A * Useful constant for YEAR field alignment. 0N/A * Useful constant for MONTH field alignment. 0N/A * Useful constant for DATE field alignment. 0N/A * Useful constant for one-based HOUR_OF_DAY field alignment. 0N/A * HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock. 0N/A * For example, 23:59 + 01:00 results in 24:59. 0N/A * Useful constant for zero-based HOUR_OF_DAY field alignment. 0N/A * HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock. 0N/A * For example, 23:59 + 01:00 results in 00:59. 0N/A * Useful constant for MINUTE field alignment. 0N/A * Useful constant for SECOND field alignment. 0N/A * Useful constant for MILLISECOND field alignment. 0N/A * Useful constant for DAY_OF_WEEK field alignment. 0N/A * Useful constant for DAY_OF_YEAR field alignment. 0N/A * Useful constant for DAY_OF_WEEK_IN_MONTH field alignment. 0N/A * Useful constant for WEEK_OF_YEAR field alignment. 0N/A * Useful constant for WEEK_OF_MONTH field alignment. 0N/A * Useful constant for AM_PM field alignment. 0N/A * Useful constant for one-based HOUR field alignment. 0N/A * HOUR1_FIELD is used for the one-based 12-hour clock. 0N/A * For example, 11:30 PM + 1 hour results in 12:30 AM. 0N/A * Useful constant for zero-based HOUR field alignment. 0N/A * HOUR0_FIELD is used for the zero-based 12-hour clock. 0N/A * For example, 11:30 PM + 1 hour results in 00:30 AM. 0N/A * Useful constant for TIMEZONE field alignment. 0N/A // Proclaim serial compatibility with 1.1 FCS 0N/A * Formats a time object into a time string. Examples of time objects 0N/A * are a time value expressed in milliseconds and a Date object. 0N/A * @param obj must be a Number or a Date. 0N/A * @param toAppendTo the string buffer for the returning time string. 0N/A * @return the string buffer passed in as toAppendTo, with formatted text appended. 0N/A * @param fieldPosition keeps track of the position of the field 0N/A * within the returned string. 0N/A * On input: an alignment field, 0N/A * if desired. On output: the offsets of the alignment field. For 0N/A * example, given a time text "1996.07.10 AD at 15:08:56 PDT", 0N/A * if the given fieldPosition is DateFormat.YEAR_FIELD, the 0N/A * begin index and end index of fieldPosition will be set to 0N/A * 0 and 4, respectively. 0N/A * Notice that if the same time field appears 0N/A * more than once in a pattern, the fieldPosition will be set for the first 0N/A * occurrence of that time field. For instance, formatting a Date to 0N/A * the time string "1 PM PDT (Pacific Daylight Time)" using the pattern 0N/A * "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD, 0N/A * the begin index and end index of fieldPosition will be set to 0N/A * 5 and 8, respectively, for the first occurrence of the timezone 0N/A * pattern character 'z'. 0N/A * @see java.text.Format 0N/A * @param date a Date to be formatted into a date/time string. 0N/A * @param toAppendTo the string buffer for the returning date/time string. 0N/A * @param fieldPosition keeps track of the position of the field 0N/A * within the returned string. 0N/A * On input: an alignment field, 0N/A * if desired. On output: the offsets of the alignment field. For 0N/A * example, given a time text "1996.07.10 AD at 15:08:56 PDT", 0N/A * if the given fieldPosition is DateFormat.YEAR_FIELD, the 0N/A * begin index and end index of fieldPosition will be set to 0N/A * 0 and 4, respectively. 0N/A * Notice that if the same time field appears 0N/A * more than once in a pattern, the fieldPosition will be set for the first 0N/A * occurrence of that time field. For instance, formatting a Date to 0N/A * the time string "1 PM PDT (Pacific Daylight Time)" using the pattern 0N/A * "h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD, 0N/A * the begin index and end index of fieldPosition will be set to 0N/A * 5 and 8, respectively, for the first occurrence of the timezone 0N/A * pattern character 'z'. 0N/A * @return the string buffer passed in as toAppendTo, with formatted text appended. 0N/A * @param date the time value to be formatted into a time string. 0N/A * @return the formatted time string. 0N/A * Parses text from the beginning of the given string to produce a date. 0N/A * The method may not use the entire text of the given string. 0N/A * See the {@link #parse(String, ParsePosition)} method for more information 0N/A * @param source A <code>String</code> whose beginning should be parsed. 0N/A * @return A <code>Date</code> parsed from the string. 0N/A * @exception ParseException if the beginning of the specified string 0N/A * Parse a date/time string according to the given parse position. For 2293N/A * example, a time text {@code "07/10/96 4:5 PM, PDT"} will be parsed into a {@code Date} 2293N/A * that is equivalent to {@code Date(837039900000L)}. 0N/A * <p> By default, parsing is lenient: If the input is not in the form used 0N/A * by this object's format method but can still be parsed as a date, then 0N/A * the parse succeeds. Clients may insist on strict adherence to the 2293N/A * format by calling {@link #setLenient(boolean) setLenient(false)}. 2293N/A * <p>This parsing operation uses the {@link #calendar} to produce 2293N/A * a {@code Date}. As a result, the {@code calendar}'s date-time 2293N/A * fields and the {@code TimeZone} value may have been 2293N/A * overwritten, depending on subclass implementations. Any {@code 2293N/A * TimeZone} value that has previously been set by a call to 2293N/A * {@link #setTimeZone(java.util.TimeZone) setTimeZone} may need 2293N/A * to be restored for further operations. 0N/A * @param pos On input, the position at which to start parsing; on 0N/A * output, the position at which parsing terminated, or the 0N/A * start position if the parse failed. 2293N/A * @return A {@code Date}, or {@code null} if the input could not be parsed 0N/A * Parses text from a string to produce a <code>Date</code>. 0N/A * The method attempts to parse text starting at the index given by 0N/A * If parsing succeeds, then the index of <code>pos</code> is updated 0N/A * to the index after the last character used (parsing does not necessarily 0N/A * use all characters up to the end of the string), and the parsed 0N/A * date is returned. The updated <code>pos</code> can be used to 0N/A * indicate the starting point for the next call to this method. 0N/A * If an error occurs, then the index of <code>pos</code> is not 0N/A * changed, the error index of <code>pos</code> is set to the index of 0N/A * the character where the error occurred, and null is returned. 0N/A * See the {@link #parse(String, ParsePosition)} method for more information 0N/A * @param source A <code>String</code>, part of which should be parsed. 0N/A * @param pos A <code>ParsePosition</code> object with index and error 0N/A * index information as described above. 0N/A * @return A <code>Date</code> parsed from the string. In case of 0N/A * error, returns null. 0N/A * @exception NullPointerException if <code>pos</code> is null. 0N/A * Constant for full style pattern. 0N/A * Constant for long style pattern. 0N/A * Constant for medium style pattern. 0N/A * Constant for short style pattern. 0N/A * Constant for default style pattern. Its value is MEDIUM. 0N/A * Gets the time formatter with the default formatting style 0N/A * for the default locale. 0N/A * @return a time formatter. 0N/A * Gets the time formatter with the given formatting style 0N/A * for the default locale. 0N/A * @param style the given formatting style. For example, 0N/A * SHORT for "h:mm a" in the US locale. 0N/A * @return a time formatter. 0N/A * Gets the time formatter with the given formatting style 0N/A * for the given locale. 0N/A * @param style the given formatting style. For example, 0N/A * SHORT for "h:mm a" in the US locale. 0N/A * @param aLocale the given locale. 0N/A * @return a time formatter. 0N/A * Gets the date formatter with the default formatting style 0N/A * for the default locale. 0N/A * @return a date formatter. 0N/A * Gets the date formatter with the given formatting style 0N/A * for the default locale. 0N/A * @param style the given formatting style. For example, 0N/A * SHORT for "M/d/yy" in the US locale. 0N/A * @return a date formatter. 0N/A * Gets the date formatter with the given formatting style 0N/A * for the given locale. 0N/A * @param style the given formatting style. For example, 0N/A * SHORT for "M/d/yy" in the US locale. 0N/A * @param aLocale the given locale. 0N/A * @return a date formatter. 0N/A * Gets the date/time formatter with the default formatting style 0N/A * for the default locale. 0N/A * Gets the date/time formatter with the given date and time 0N/A * formatting styles for the default locale. 0N/A * @param dateStyle the given date formatting style. For example, 0N/A * SHORT for "M/d/yy" in the US locale. 0N/A * @param timeStyle the given time formatting style. For example, 0N/A * SHORT for "h:mm a" in the US locale. 0N/A * Gets the date/time formatter with the given formatting styles 0N/A * for the given locale. 0N/A * @param dateStyle the given date formatting style. 0N/A * @param timeStyle the given time formatting style. 0N/A * @param aLocale the given locale. 0N/A * Get a default date/time formatter that uses the SHORT style for both the 0N/A * date and the time. 0N/A * Returns an array of all locales for which the 0N/A * <code>get*Instance</code> methods of this class can return 0N/A * localized instances. 0N/A * The returned array represents the union of locales supported by the Java 0N/A * runtime and by installed 0N/A * {@link java.text.spi.DateFormatProvider DateFormatProvider} implementations. 0N/A * It must contain at least a <code>Locale</code> instance equal to 0N/A * {@link java.util.Locale#US Locale.US}. 0N/A * @return An array of locales for which localized 0N/A * <code>DateFormat</code> instances are available. 0N/A * Set the calendar to be used by this date format. Initially, the default 0N/A * calendar for the specified or default locale is used. 2293N/A * <p>Any {@link java.util.TimeZone TimeZone} and {@linkplain 2293N/A * #isLenient() leniency} values that have previously been set are 2293N/A * overwritten by {@code newCalendar}'s values. 2293N/A * @param newCalendar the new {@code Calendar} to be used by the date format 0N/A * Gets the calendar associated with this date/time formatter. 0N/A * @return the calendar associated with this date/time formatter. 0N/A * Allows you to set the number formatter. 0N/A * @param newNumberFormat the given new NumberFormat. 0N/A * Gets the number formatter which this date/time formatter uses to 0N/A * format and parse a time. 0N/A * @return the number formatter which this date/time formatter uses. 2293N/A * Sets the time zone for the calendar of this {@code DateFormat} object. 2293N/A * This method is equivalent to the following call. 2293N/A * getCalendar().setTimeZone(zone) 2293N/A * <p>The {@code TimeZone} set by this method is overwritten by a 2293N/A * {@link #setCalendar(java.util.Calendar) setCalendar} call. 2293N/A * <p>The {@code TimeZone} set by this method may be overwritten as 2293N/A * a result of a call to the parse method. 0N/A * @param zone the given new time zone. 0N/A * Gets the time zone. 2293N/A * This method is equivalent to the following call. 2293N/A * getCalendar().getTimeZone() 0N/A * @return the time zone associated with the calendar of DateFormat. 0N/A * Specify whether or not date/time parsing is to be lenient. With 0N/A * lenient parsing, the parser may use heuristics to interpret inputs that 0N/A * do not precisely match this object's format. With strict parsing, 0N/A * inputs must match this object's format. 2293N/A * <p>This method is equivalent to the following call. 2293N/A * getCalendar().setLenient(lenient) 2293N/A * <p>This leniency value is overwritten by a call to {@link 2293N/A * #setCalendar(java.util.Calendar) setCalendar()}. 2293N/A * @param lenient when {@code true}, parsing is lenient 2293N/A * @see java.util.Calendar#setLenient(boolean) 2293N/A * This method is equivalent to the following call. 2293N/A * getCalendar().isLenient() 2293N/A * @return {@code true} if the {@link #calendar} is lenient; 2293N/A * @see java.util.Calendar#isLenient() 0N/A * Overrides hashCode 0N/A // just enough fields for a reasonable distribution 0N/A return (
// calendar.equivalentTo(other.calendar) // THIS API DOESN'T EXIST YET! 0N/A * Overrides Cloneable 0N/A * Creates a DateFormat with the given time and/or date style in the given 0N/A * @param timeStyle a value from 0 to 3 indicating the time format, 0N/A * ignored if flags is 2 0N/A * @param dateStyle a value from 0 to 3 indicating the time format, 0N/A * ignored if flags is 1 0N/A * @param flags either 1 for a time format, 2 for a date format, 0N/A * @param loc the locale for the format 0N/A // Check whether a provider can provide an implementation that's closer 0N/A // to the requested locale than what the Java runtime itself can provide. 0N/A * Create a new date format. 0N/A * Defines constants that are used as attribute keys in the 0N/A * <code>AttributedCharacterIterator</code> returned 0N/A * from <code>DateFormat.formatToCharacterIterator</code> and as 0N/A * field identifiers in <code>FieldPosition</code>. 0N/A * The class also provides two methods to map 0N/A * between its constants and the corresponding Calendar constants. 0N/A * @see java.util.Calendar 0N/A // Proclaim serial compatibility with 1.4 FCS 0N/A // table of all instances in this class, used by readResolve 0N/A // Maps from Calendar constant (such as Calendar.ERA) to Field 0N/A // constant (such as Field.ERA). 0N/A /** Calendar field. */ 0N/A * Returns the <code>Field</code> constant that corresponds to 0N/A * the <code>Calendar</code> constant <code>calendarField</code>. 0N/A * If there is no direct mapping between the <code>Calendar</code> 0N/A * constant and a <code>Field</code>, null is returned. 0N/A * @throws IllegalArgumentException if <code>calendarField</code> is 0N/A * not the value of a <code>Calendar</code> field constant. 0N/A * @param calendarField Calendar field constant 0N/A * @return Field instance representing calendarField. 0N/A * @see java.util.Calendar 0N/A * Creates a <code>Field</code>. 0N/A * @param name the name of the <code>Field</code> 0N/A * @param calendarField the <code>Calendar</code> constant this 0N/A * <code>Field</code> corresponds to; any value, even one 0N/A * outside the range of legal <code>Calendar</code> values may 0N/A * be used, but <code>-1</code> should be used for values 0N/A * that don't correspond to legal <code>Calendar</code> values 0N/A // assert(calendarField < Calendar.FIELD_COUNT); 0N/A * Returns the <code>Calendar</code> field associated with this 0N/A * attribute. For example, if this represents the hours field of 0N/A * a <code>Calendar</code>, this would return 0N/A * <code>Calendar.HOUR</code>. If there is no corresponding 0N/A * <code>Calendar</code> constant, this will return -1. 0N/A * @return Calendar constant for this field 0N/A * @see java.util.Calendar 0N/A * Resolves instances being deserialized to the predefined constants. 0N/A * @throws InvalidObjectException if the constant could not be 0N/A * @return resolved DateFormat.Field constant 0N/A * Constant identifying the era field. 0N/A * Constant identifying the year field. 0N/A * Constant identifying the month field. 0N/A * Constant identifying the day of month field. 0N/A * Constant identifying the hour of day field, where the legal values 0N/A * Constant identifying the hour of day field, where the legal values 0N/A * Constant identifying the minute field. 0N/A * Constant identifying the second field. 0N/A * Constant identifying the millisecond field. 0N/A * Constant identifying the day of week field. 0N/A * Constant identifying the day of year field. 0N/A * Constant identifying the day of week field. 0N/A * Constant identifying the week of year field. 0N/A * Constant identifying the week of month field. 0N/A * Constant identifying the time of day indicator 0N/A * (e.g. "a.m." or "p.m.") field. 0N/A * Constant identifying the hour field, where the legal values are 0N/A * Constant identifying the hour field, where the legal values are 0N/A * Constant identifying the time zone field. 0N/A * Obtains a DateFormat instance from a DateFormatProvider 0N/A assert false :
"should not happen";