2 * Copyright (C) {1997-2004}, International Business Machines Corporation and others. All Rights Reserved.
3 *******************************************************************************
7 * Modification History:
9 * Date Name Description
10 * 02/19/97 aliu Converted from java.
11 * 07/09/97 helena Make ParsePosition into a class.
12 * 07/21/98 stephen Added GMT_PLUS, GMT_MINUS
13 * Changed setTwoDigitStartDate to set2DigitYearStart
14 * Changed getTwoDigitStartDate to get2DigitYearStart
15 * Removed subParseLong
16 * Removed getZoneIndex (added in DateFormatSymbols)
17 * 06/14/99 stephen Removed fgTimeZoneDataSuffix
18 * 10/14/99 aliu Updated class doc to describe 2-digit year parsing
20 *******************************************************************************
26 #include "unicode/utypes.h"
28 #if !UCONFIG_NO_FORMATTING
30 #include "unicode/datefmt.h"
34 class DateFormatSymbols
;
38 * SimpleDateFormat is a concrete class for formatting and parsing dates in a
39 * language-independent manner. It allows for formatting (millis -> text),
40 * parsing (text -> millis), and normalization. Formats/Parses a date or time,
41 * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970.
43 * Clients are encouraged to create a date-time formatter using DateFormat::getInstance(),
44 * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than
45 * explicitly constructing an instance of SimpleDateFormat. This way, the client
46 * is guaranteed to get an appropriate formatting pattern for whatever locale the
47 * program is running in. However, if the client needs something more unusual than
48 * the default patterns in the locales, he can construct a SimpleDateFormat directly
49 * and give it an appropriate pattern (or use one of the factory methods on DateFormat
50 * and modify the pattern after the fact with toPattern() and applyPattern().
52 * Date/Time format syntax:
54 * The date/time format is specified by means of a string time pattern. In this
55 * pattern, all ASCII letters are reserved as pattern letters, which are defined
59 * Symbol Meaning Presentation Example
60 * ------ ------- ------------ -------
61 * G era designator (Text) AD
62 * y year (Number) 1996
63 * Y year (week of year) (Number) 1997
64 * u extended year (Number) 4601
65 * M month in year (Text & Number) July & 07
66 * d day in month (Number) 10
67 * h hour in am/pm (1~12) (Number) 12
68 * H hour in day (0~23) (Number) 0
69 * m minute in hour (Number) 30
70 * s second in minute (Number) 55
71 * S fractional second (Number) 978
72 * E day of week (Text) Tuesday
73 * e day of week (local 1~7) (Number) 2
74 * D day in year (Number) 189
75 * F day of week in month (Number) 2 (2nd Wed in July)
76 * w week in year (Number) 27
77 * W week in month (Number) 2
78 * a am/pm marker (Text) PM
79 * k hour in day (1~24) (Number) 24
80 * K hour in am/pm (0~11) (Number) 0
81 * z time zone (Text) Pacific Standard Time
82 * Z time zone (RFC 822) (Number) -0800
83 * g Julian day (Number) 2451334
84 * A milliseconds in day (Number) 69540000
85 * ' escape for text (Delimiter) 'Date='
86 * '' single quote (Literal) 'o''clock'
89 * The count of pattern letters determine the format.
91 * (Text): 4 or more, use full form, <4, use short or abbreviated form if it
92 * exists. (e.g., "EEEE" produces "Monday", "EEE" produces "Mon")
94 * (Number): the minimum number of digits. Shorter numbers are zero-padded to
95 * this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled
96 * specially; that is, if the count of 'y' is 2, the Year will be truncated to 2 digits.
97 * (e.g., if "yyyy" produces "1997", "yy" produces "97".)
98 * Unlike other fields, fractional seconds are padded on the right with zero.
100 * (Text & Number): 3 or over, use text, otherwise use number. (e.g., "M" produces "1",
101 * "MM" produces "01", "MMM" produces "Jan", and "MMMM" produces "January".)
103 * Any characters in the pattern that are not in the ranges of ['a'..'z'] and
104 * ['A'..'Z'] will be treated as quoted text. For instance, characters
105 * like ':', '.', ' ', '#' and '@' will appear in the resulting time text
106 * even they are not embraced within single quotes.
108 * A pattern containing any invalid pattern letter will result in a failing
109 * UErrorCode result during formatting or parsing.
111 * Examples using the US locale:
114 * Format Pattern Result
115 * -------------- -------
116 * "yyyy.MM.dd G 'at' HH:mm:ss z" ->> 1996.07.10 AD at 15:08:56 PDT
117 * "EEE, MMM d, ''yy" ->> Wed, July 10, '96
118 * "h:mm a" ->> 12:08 PM
119 * "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time
120 * "K:mm a, z" ->> 0:00 PM, PST
121 * "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 1996.July.10 AD 12:08 PM
127 * UErrorCode success = U_ZERO_ERROR;
128 * SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST");
129 * pdt->setStartRule( Calendar::APRIL, 1, Calendar::SUNDAY, 2*60*60*1000);
130 * pdt->setEndRule( Calendar::OCTOBER, -1, Calendar::SUNDAY, 2*60*60*1000);
132 * // Format the current time.
133 * SimpleDateFormat* formatter
134 * = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz", success );
135 * GregorianCalendar cal(success);
136 * UDate currentTime_1 = cal.getTime(success);
137 * FieldPosition fp(0);
138 * UnicodeString dateString;
139 * formatter->format( currentTime_1, dateString, fp );
140 * cout << "result: " << dateString << endl;
142 * // Parse the previous string back into a Date.
143 * ParsePosition pp(0);
144 * UDate currentTime_2 = formatter->parse(dateString, pp );
147 * In the above example, the time value "currentTime_2" obtained from parsing
148 * will be equal to currentTime_1. However, they may not be equal if the am/pm
149 * marker 'a' is left out from the format pattern while the "hour in am/pm"
150 * pattern symbol is used. This information loss can happen when formatting the
154 * When parsing a date string using the abbreviated year pattern ("y" or "yy"),
155 * SimpleDateFormat must interpret the abbreviated year
156 * relative to some century. It does this by adjusting dates to be
157 * within 80 years before and 20 years after the time the SimpleDateFormat
158 * instance is created. For example, using a pattern of "MM/dd/yy" and a
159 * SimpleDateFormat instance created on Jan 1, 1997, the string
160 * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64"
161 * would be interpreted as May 4, 1964.
162 * During parsing, only strings consisting of exactly two digits, as defined by
163 * <code>Unicode::isDigit()</code>, will be parsed into the default century.
164 * Any other numeric string, such as a one digit string, a three or more digit
165 * string, or a two digit string that isn't all digits (for example, "-1"), is
166 * interpreted literally. So "01/02/3" or "01/02/003" are parsed, using the
167 * same pattern, as Jan 2, 3 AD. Likewise, "01/02/-3" is parsed as Jan 2, 4 BC.
170 * If the year pattern has more than two 'y' characters, the year is
171 * interpreted literally, regardless of the number of digits. So using the
172 * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
175 * When numeric fields abut one another directly, with no intervening delimiter
176 * characters, they constitute a run of abutting numeric fields. Such runs are
177 * parsed specially. For example, the format "HHmmss" parses the input text
178 * "123456" to 12:34:56, parses the input text "12345" to 1:23:45, and fails to
179 * parse "1234". In other words, the leftmost field of the run is flexible,
180 * while the others keep a fixed width. If the parse fails anywhere in the run,
181 * then the leftmost field is shortened by one character, and the entire run is
182 * parsed again. This is repeated until either the parse succeeds or the
183 * leftmost field is one character in length. If the parse still fails at that
184 * point, the parse of the run fails.
187 * For time zones that have no names, SimpleDateFormat uses strings GMT+hours:minutes or
190 * The calendar defines what is the first day of the week, the first week of the
191 * year, whether hours are zero based or not (0 vs 12 or 24), and the timezone.
192 * There is one common number format to handle all the numbers; the digit count
193 * is handled programmatically according to the pattern.
195 * <p><em>User subclasses are not supported.</em> While clients may write
196 * subclasses, such code will not necessarily work and will not be
197 * guaranteed to work stably from release to release.
199 class U_I18N_API SimpleDateFormat
: public DateFormat
{
202 * Construct a SimpleDateFormat using the default pattern for the default
205 * [Note:] Not all locales support SimpleDateFormat; for full generality,
206 * use the factory methods in the DateFormat class.
207 * @param status Output param set to success/failure code.
210 SimpleDateFormat(UErrorCode
& status
);
213 * Construct a SimpleDateFormat using the given pattern and the default locale.
214 * The locale is used to obtain the symbols used in formatting (e.g., the
215 * names of the months), but not to provide the pattern.
217 * [Note:] Not all locales support SimpleDateFormat; for full generality,
218 * use the factory methods in the DateFormat class.
219 * @param pattern the pattern for the format.
220 * @param status Output param set to success/failure code.
223 SimpleDateFormat(const UnicodeString
& pattern
,
227 * Construct a SimpleDateFormat using the given pattern and locale.
228 * The locale is used to obtain the symbols used in formatting (e.g., the
229 * names of the months), but not to provide the pattern.
231 * [Note:] Not all locales support SimpleDateFormat; for full generality,
232 * use the factory methods in the DateFormat class.
233 * @param pattern the pattern for the format.
234 * @param locale the given locale.
235 * @param status Output param set to success/failure code.
238 SimpleDateFormat(const UnicodeString
& pattern
,
239 const Locale
& locale
,
243 * Construct a SimpleDateFormat using the given pattern and locale-specific
244 * symbol data. The formatter takes ownership of the DateFormatSymbols object;
245 * the caller is no longer responsible for deleting it.
246 * @param pattern the given pattern for the format.
247 * @param formatDataToAdopt the symbols to be adopted.
248 * @param status Output param set to success/faulure code.
251 SimpleDateFormat(const UnicodeString
& pattern
,
252 DateFormatSymbols
* formatDataToAdopt
,
256 * Construct a SimpleDateFormat using the given pattern and locale-specific
257 * symbol data. The DateFormatSymbols object is NOT adopted; the caller
258 * remains responsible for deleting it.
259 * @param pattern the given pattern for the format.
260 * @param formatData the formatting symbols to be use.
261 * @param status Output param set to success/faulure code.
264 SimpleDateFormat(const UnicodeString
& pattern
,
265 const DateFormatSymbols
& formatData
,
272 SimpleDateFormat(const SimpleDateFormat
&);
275 * Assignment operator.
278 SimpleDateFormat
& operator=(const SimpleDateFormat
&);
284 virtual ~SimpleDateFormat();
287 * Clone this Format object polymorphically. The caller owns the result and
288 * should delete it when done.
289 * @return A copy of the object.
292 virtual Format
* clone(void) const;
295 * Return true if the given Format objects are semantically equal. Objects
296 * of different subclasses are considered unequal.
297 * @param other the object to be compared with.
298 * @return true if the given Format objects are semantically equal.
301 virtual UBool
operator==(const Format
& other
) const;
304 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
305 * 1, 1970. Overrides DateFormat pure virtual method.
307 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
308 * 1996.07.10 AD at 15:08:56 PDT
310 * @param cal Calendar set to the date and time to be formatted
311 * into a date/time string.
312 * @param appendTo Output parameter to receive result.
313 * Result is appended to existing contents.
314 * @param pos The formatting position. On input: an alignment field,
315 * if desired. On output: the offsets of the alignment field.
316 * @return Reference to 'appendTo' parameter.
319 virtual UnicodeString
& format( Calendar
& cal
,
320 UnicodeString
& appendTo
,
321 FieldPosition
& pos
) const;
324 * Format a date or time, which is the standard millis since 24:00 GMT, Jan
325 * 1, 1970. Overrides DateFormat pure virtual method.
327 * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
328 * 1996.07.10 AD at 15:08:56 PDT
330 * @param obj A Formattable containing the date-time value to be formatted
331 * into a date-time string. If the type of the Formattable
332 * is a numeric type, it is treated as if it were an
334 * @param appendTo Output parameter to receive result.
335 * Result is appended to existing contents.
336 * @param pos The formatting position. On input: an alignment field,
337 * if desired. On output: the offsets of the alignment field.
338 * @param status Output param set to success/faulure code.
339 * @return Reference to 'appendTo' parameter.
342 virtual UnicodeString
& format( const Formattable
& obj
,
343 UnicodeString
& appendTo
,
345 UErrorCode
& status
) const;
348 * Redeclared DateFormat method.
349 * @param date the Date value to be formatted.
350 * @param appendTo Output parameter to receive result.
351 * Result is appended to existing contents.
352 * @param fieldPosition The formatting position. On input: an alignment field,
353 * if desired. On output: the offsets of the alignment field.
354 * @return Reference to 'appendTo' parameter.
357 UnicodeString
& format(UDate date
,
358 UnicodeString
& appendTo
,
359 FieldPosition
& fieldPosition
) const;
362 * Redeclared DateFormat method.
363 * @param obj Object to be formatted.
364 * @param appendTo Output parameter to receive result.
365 * Result is appended to existing contents.
366 * @param status Input/output success/failure code.
367 * @return Reference to 'appendTo' parameter.
370 UnicodeString
& format(const Formattable
& obj
,
371 UnicodeString
& appendTo
,
372 UErrorCode
& status
) const;
375 * Redeclared DateFormat method.
376 * @param date Date value to be formatted.
377 * @param appendTo Output parameter to receive result.
378 * Result is appended to existing contents.
379 * @return Reference to 'appendTo' parameter.
382 UnicodeString
& format(UDate date
, UnicodeString
& appendTo
) const;
385 * Parse a date/time string beginning at the given parse position. For
386 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
387 * that is equivalent to Date(837039928046).
389 * By default, parsing is lenient: If the input is not in the form used by
390 * this object's format method but can still be parsed as a date, then the
391 * parse succeeds. Clients may insist on strict adherence to the format by
392 * calling setLenient(false).
394 * @param text The date/time string to be parsed
395 * @param cal a Calendar set to the date and time to be formatted
396 * into a date/time string.
397 * @param pos On input, the position at which to start parsing; on
398 * output, the position at which parsing terminated, or the
399 * start position if the parse failed.
400 * @return A valid UDate if the input could be parsed.
403 virtual void parse( const UnicodeString
& text
,
405 ParsePosition
& pos
) const;
408 * Parse a date/time string starting at the given parse position. For
409 * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
410 * that is equivalent to Date(837039928046).
412 * By default, parsing is lenient: If the input is not in the form used by
413 * this object's format method but can still be parsed as a date, then the
414 * parse succeeds. Clients may insist on strict adherence to the format by
415 * calling setLenient(false).
417 * @see DateFormat::setLenient(boolean)
419 * @param text The date/time string to be parsed
420 * @param pos On input, the position at which to start parsing; on
421 * output, the position at which parsing terminated, or the
422 * start position if the parse failed.
423 * @return A valid UDate if the input could be parsed.
426 UDate
parse( const UnicodeString
& text
,
427 ParsePosition
& pos
) const;
431 * Parse a date/time string. For example, a time text "07/10/96 4:5 PM, PDT"
432 * will be parsed into a UDate that is equivalent to Date(837039928046).
433 * Parsing begins at the beginning of the string and proceeds as far as
434 * possible. Assuming no parse errors were encountered, this function
435 * doesn't return any information about how much of the string was consumed
436 * by the parsing. If you need that information, use the version of
437 * parse() that takes a ParsePosition.
439 * @param text The date/time string to be parsed
440 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
441 * an error value if there was a parse error.
442 * @return A valid UDate if the input could be parsed.
445 virtual UDate
parse( const UnicodeString
& text
,
446 UErrorCode
& status
) const;
449 * Set the start UDate used to interpret two-digit year strings.
450 * When dates are parsed having 2-digit year strings, they are placed within
451 * a assumed range of 100 years starting on the two digit start date. For
452 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
453 * some other year. SimpleDateFormat chooses a year so that the resultant
454 * date is on or after the two digit start date and within 100 years of the
455 * two digit start date.
457 * By default, the two digit start date is set to 80 years before the current
458 * time at which a SimpleDateFormat object is created.
459 * @param d start UDate used to interpret two-digit year strings.
460 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
461 * an error value if there was a parse error.
464 virtual void set2DigitYearStart(UDate d
, UErrorCode
& status
);
467 * Get the start UDate used to interpret two-digit year strings.
468 * When dates are parsed having 2-digit year strings, they are placed within
469 * a assumed range of 100 years starting on the two digit start date. For
470 * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
471 * some other year. SimpleDateFormat chooses a year so that the resultant
472 * date is on or after the two digit start date and within 100 years of the
473 * two digit start date.
475 * By default, the two digit start date is set to 80 years before the current
476 * time at which a SimpleDateFormat object is created.
477 * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
478 * an error value if there was a parse error.
481 UDate
get2DigitYearStart(UErrorCode
& status
) const;
484 * Return a pattern string describing this date format.
485 * @param result Output param to receive the pattern.
486 * @return A reference to 'result'.
489 virtual UnicodeString
& toPattern(UnicodeString
& result
) const;
492 * Return a localized pattern string describing this date format.
493 * In most cases, this will return the same thing as toPattern(),
494 * but a locale can specify characters to use in pattern descriptions
495 * in place of the ones described in this class's class documentation.
496 * (Presumably, letters that would be more mnemonic in that locale's
497 * language.) This function would produce a pattern using those
500 * @param result Receives the localized pattern.
501 * @param status Output param set to success/failure code on
502 * exit. If the pattern is invalid, this will be
503 * set to a failure result.
504 * @return A reference to 'result'.
507 virtual UnicodeString
& toLocalizedPattern(UnicodeString
& result
,
508 UErrorCode
& status
) const;
511 * Apply the given unlocalized pattern string to this date format.
512 * (i.e., after this call, this formatter will format dates according to
515 * @param pattern The pattern to be applied.
518 virtual void applyPattern(const UnicodeString
& pattern
);
521 * Apply the given localized pattern string to this date format.
522 * (see toLocalizedPattern() for more information on localized patterns.)
524 * @param pattern The localized pattern to be applied.
525 * @param status Output param set to success/failure code on
526 * exit. If the pattern is invalid, this will be
527 * set to a failure result.
530 virtual void applyLocalizedPattern(const UnicodeString
& pattern
,
534 * Gets the date/time formatting symbols (this is an object carrying
535 * the various strings and other symbols used in formatting: e.g., month
536 * names and abbreviations, time zone names, AM/PM strings, etc.)
537 * @return a copy of the date-time formatting data associated
538 * with this date-time formatter.
541 virtual const DateFormatSymbols
* getDateFormatSymbols(void) const;
544 * Set the date/time formatting symbols. The caller no longer owns the
545 * DateFormatSymbols object and should not delete it after making this call.
546 * @param newFormatSymbols the given date-time formatting symbols to copy.
549 virtual void adoptDateFormatSymbols(DateFormatSymbols
* newFormatSymbols
);
552 * Set the date/time formatting data.
553 * @param newFormatSymbols the given date-time formatting symbols to copy.
556 virtual void setDateFormatSymbols(const DateFormatSymbols
& newFormatSymbols
);
559 * Return the class ID for this class. This is useful only for comparing to
560 * a return value from getDynamicClassID(). For example:
562 * . Base* polymorphic_pointer = createPolymorphicObject();
563 * . if (polymorphic_pointer->getDynamicClassID() ==
564 * . erived::getStaticClassID()) ...
566 * @return The class ID for all objects of this class.
569 static UClassID U_EXPORT2
getStaticClassID(void);
572 * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
573 * method is to implement a simple version of RTTI, since not all C++
574 * compilers support genuine RTTI. Polymorphic operator==() and clone()
575 * methods call this method.
577 * @return The class ID for this object. All objects of a
578 * given class have the same class ID. Objects of
579 * other classes have different class IDs.
582 virtual UClassID
getDynamicClassID(void) const;
585 * Set the calendar to be used by this date format. Initially, the default
586 * calendar for the specified or default locale is used. The caller should
587 * not delete the Calendar object after it is adopted by this call.
588 * Adopting a new calendar will change to the default symbols.
590 * @param calendarToAdopt Calendar object to be adopted.
593 virtual void adoptCalendar(Calendar
* calendarToAdopt
);
596 friend class DateFormat
;
598 void initializeDefaultCentury(void);
600 SimpleDateFormat(); // default constructor not implemented
603 * Used by the DateFormat factory methods to construct a SimpleDateFormat.
604 * @param timeStyle the time style.
605 * @param dateStyle the date style.
606 * @param locale the given locale.
607 * @param status Output param set to success/failure code on
610 SimpleDateFormat(EStyle timeStyle
, EStyle dateStyle
, const Locale
& locale
, UErrorCode
& status
);
613 * Construct a SimpleDateFormat for the given locale. If no resource data
614 * is available, create an object of last resort, using hard-coded strings.
615 * This is an internal method, called by DateFormat. It should never fail.
616 * @param locale the given locale.
617 * @param status Output param set to success/failure code on
620 SimpleDateFormat(const Locale
& locale
, UErrorCode
& status
); // Use default pattern
623 * Called by format() to format a single field.
625 * @param appendTo Output parameter to receive result.
626 * Result is appended to existing contents.
627 * @param ch The format character we encountered in the pattern.
628 * @param count Number of characters in the current pattern symbol (e.g.,
629 * "yyyy" in the pattern would result in a call to this function
630 * with ch equal to 'y' and count equal to 4)
631 * @param pos The FieldPosition being filled in by the format() call. If
632 * this function is formatting the field specfied by pos, it
633 * will fill in pos with the beginning and ending offsets of the
635 * @param status Receives a status code, which will be U_ZERO_ERROR if the operation
638 void subFormat( UnicodeString
&appendTo
,
643 UErrorCode
& status
) const; // in case of illegal argument
646 * Used by subFormat() to format a numeric value.
647 * Appends to toAppendTo a string representation of "value"
648 * having a number of digits between "minDigits" and
649 * "maxDigits". Uses the DateFormat's NumberFormat.
651 * @param appendTo Output parameter to receive result.
652 * Formatted number is appended to existing contents.
653 * @param value Value to format.
654 * @param minDigits Minimum number of digits the result should have
655 * @param maxDigits Maximum number of digits the result should have
657 void zeroPaddingNumber( UnicodeString
&appendTo
,
660 int32_t maxDigits
) const;
663 * Return true if the given format character, occuring count
664 * times, represents a numeric field.
666 static UBool
isNumeric(UChar formatChar
, int32_t count
);
669 * initializes fCalendar from parameters. Returns fCalendar as a convenience.
670 * @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault().
671 * @param locale Locale of the calendar
672 * @param status Error code
673 * @return the newly constructed fCalendar
675 Calendar
*initializeCalendar(TimeZone
* adoptZone
, const Locale
& locale
, UErrorCode
& status
);
678 * initializes fSymbols from parameters.
679 * @param locale Locale of the symbols
680 * @param calendar Alias to Calendar that will be used.
681 * @param status Error code
683 void initializeSymbols(const Locale
& locale
, Calendar
* calendar
, UErrorCode
& status
);
686 * Called by several of the constructors to load pattern data and formatting symbols
687 * out of a resource bundle and initialize the locale based on it.
688 * @param timeStyle The time style, as passed to DateFormat::createDateInstance().
689 * @param dateStyle The date style, as passed to DateFormat::createTimeInstance().
690 * @param locale The locale to load the patterns from.
691 * @param status Filled in with an error code if loading the data from the
694 void construct(EStyle timeStyle
, EStyle dateStyle
, const Locale
& locale
, UErrorCode
& status
);
697 * Called by construct() and the various constructors to set up the SimpleDateFormat's
698 * Calendar and NumberFormat objects.
699 * @param locale The locale for which we want a Calendar and a NumberFormat.
700 * @param statuc Filled in with an error code if creating either subobject fails.
702 void initialize(const Locale
& locale
, UErrorCode
& status
);
705 * Private code-size reduction function used by subParse.
706 * @param text the time text being parsed.
707 * @param start where to start parsing.
708 * @param field the date field being parsed.
709 * @param stringArray the string array to parsed.
710 * @param stringArrayCount the size of the array.
711 * @param cal a Calendar set to the date and time to be formatted
712 * into a date/time string.
713 * @return the new start position if matching succeeded; a negative number
714 * indicating matching failure, otherwise.
716 int32_t matchString(const UnicodeString
& text
, int32_t start
, UCalendarDateFields field
,
717 const UnicodeString
* stringArray
, int32_t stringArrayCount
, Calendar
& cal
) const;
720 * Private member function that converts the parsed date strings into
721 * timeFields. Returns -start (for ParsePosition) if failed.
722 * @param text the time text to be parsed.
723 * @param start where to start parsing.
724 * @param ch the pattern character for the date field text to be parsed.
725 * @param count the count of a pattern character.
726 * @param obeyCount if true then the count is strictly obeyed.
727 * @param ambiguousYear If true then the two-digit year == the default start year.
728 * @param cal a Calendar set to the date and time to be formatted
729 * into a date/time string.
730 * @return the new start position if matching succeeded; a negative number
731 * indicating matching failure, otherwise.
733 int32_t subParse(const UnicodeString
& text
, int32_t& start
, UChar ch
, int32_t count
,
734 UBool obeyCount
, UBool allowNegative
, UBool ambiguousYear
[], Calendar
& cal
) const;
736 void parseInt(const UnicodeString
& text
,
739 UBool allowNegative
) const;
742 * Translate a pattern, mapping each character in the from string to the
743 * corresponding character in the to string. Return an error if the original
744 * pattern contains an unmapped character, or if a quote is unmatched.
745 * Quoted (single quotes only) material is not translated.
746 * @param originalPattern the original pattern.
747 * @param translatedPattern Output param to receive the translited pattern.
748 * @param from the characters to be translited from.
749 * @param to the characters to be translited to.
750 * @param status Receives a status code, which will be U_ZERO_ERROR
751 * if the operation succeeds.
753 static void translatePattern(const UnicodeString
& originalPattern
,
754 UnicodeString
& translatedPattern
,
755 const UnicodeString
& from
,
756 const UnicodeString
& to
,
760 * Sets the starting date of the 100-year window that dates with 2-digit years
761 * are considered to fall within.
762 * @param startDate the start date
763 * @param status Receives a status code, which will be U_ZERO_ERROR
764 * if the operation succeeds.
766 void parseAmbiguousDatesAsAfter(UDate startDate
, UErrorCode
& status
);
769 * Used to map pattern characters to Calendar field identifiers.
771 static const UCalendarDateFields fgPatternIndexToCalendarField
[];
774 * Map index into pattern character string to DateFormat field number
776 static const UDateFormatField fgPatternIndexToDateFormatField
[];
779 * The formatting pattern for this formatter.
781 UnicodeString fPattern
;
784 * The original locale used (for reloading symbols)
789 * A pointer to an object containing the strings to use in formatting (e.g.,
790 * month and day names, AM and PM strings, time zone names, etc.)
792 DateFormatSymbols
* fSymbols
; // Owned
795 * If dates have ambiguous years, we map them into the century starting
796 * at defaultCenturyStart, which may be any date. If defaultCenturyStart is
797 * set to SYSTEM_DEFAULT_CENTURY, which it is by default, then the system
798 * values are used. The instance values defaultCenturyStart and
799 * defaultCenturyStartYear are only used if explicitly set by the user
800 * through the API method parseAmbiguousDatesAsAfter().
802 UDate fDefaultCenturyStart
;
805 * See documentation for defaultCenturyStart.
807 /*transient*/ int32_t fDefaultCenturyStartYear
;
809 UBool fHaveDefaultCentury
;
813 SimpleDateFormat::get2DigitYearStart(UErrorCode
& /*status*/) const
815 return fDefaultCenturyStart
;
818 inline UnicodeString
&
819 SimpleDateFormat::format(const Formattable
& obj
,
820 UnicodeString
& appendTo
,
821 UErrorCode
& status
) const {
822 // Don't use Format:: - use immediate base class only,
823 // in case immediate base modifies behavior later.
824 return DateFormat::format(obj
, appendTo
, status
);
827 inline UnicodeString
&
828 SimpleDateFormat::format(UDate date
,
829 UnicodeString
& appendTo
,
830 FieldPosition
& fieldPosition
) const {
831 // Don't use Format:: - use immediate base class only,
832 // in case immediate base modifies behavior later.
833 return DateFormat::format(date
, appendTo
, fieldPosition
);
836 inline UnicodeString
&
837 SimpleDateFormat::format(UDate date
, UnicodeString
& appendTo
) const {
838 return DateFormat::format(date
, appendTo
);
843 #endif /* #if !UCONFIG_NO_FORMATTING */