home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / include / smpdtfmt.h < prev    next >
C/C++ Source or Header  |  1999-11-12  |  34KB  |  740 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright Taligent, Inc.,  1997                                       *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1999     *
  7. *   Copyright (C) 1999 Alan Liu and others. All rights reserved.               *
  8. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  9. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  10. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  11. *                                                                             *
  12. *******************************************************************************
  13. *
  14. * File SMPDTFMT.H
  15. *
  16. * Modification History:
  17. *
  18. *   Date        Name        Description
  19. *   02/19/97    aliu        Converted from java.
  20. *   07/09/97    helena      Make ParsePosition into a class.
  21. *   07/21/98    stephen     Added GMT_PLUS, GMT_MINUS
  22. *                            Changed setTwoDigitStartDate to set2DigitYearStart
  23. *                            Changed getTwoDigitStartDate to get2DigitYearStart
  24. *                            Removed subParseLong
  25. *                            Removed getZoneIndex (added in DateFormatSymbols)
  26. *   06/14/99    stephen     Removed fgTimeZoneDataSuffix
  27. *   10/14/99    aliu        Updated class doc to describe 2-digit year parsing
  28. *                           {j28 4182066}.
  29. *******************************************************************************
  30. */
  31.  
  32. #ifndef SMPDTFMT_H
  33. #define SMPDTFMT_H
  34.  
  35. #include "utypes.h"
  36. #include "datefmt.h"
  37. class DateFormatSymbols;
  38.  
  39. /**
  40.  * SimpleDateFormat is a concrete class for formatting and parsing dates in a
  41.  * language-independent manner. It allows for formatting (millis -> text),
  42.  * parsing (text -> millis), and normalization. Formats/Parses a date or time,
  43.  * which is the standard milliseconds since 24:00 GMT, Jan 1, 1970.
  44.  * <P>
  45.  * Clients are encouraged to create a date-time formatter using DateFormat::getInstance(),
  46.  * getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than
  47.  * explicitly constructing an instance of SimpleDateFormat.  This way, the client
  48.  * is guaranteed to get an appropriate formatting pattern for whatever locale the
  49.  * program is running in.  However, if the client needs something more unusual than
  50.  * the default patterns in the locales, he can construct a SimpleDateFormat directly
  51.  * and give it an appropriate pattern (or use one of the factory methods on DateFormat
  52.  * and modify the pattern after the fact with toPattern() and applyPattern().
  53.  * <P>
  54.  * Date/Time format syntax:
  55.  * <P>
  56.  * The date/time format is specified by means of a string time pattern. In this
  57.  * pattern, all ASCII letters are reserved as pattern letters, which are defined
  58.  * as the following:
  59.  * <pre>
  60.  * .   Symbol   Meaning                 Presentation       Example
  61.  * .   ------   -------                 ------------       -------
  62.  * .   G        era designator          (Text)             AD
  63.  * .   y        year                    (Number)           1996
  64.  * .   M        month in year           (Text & Number)    July & 07
  65.  * .   d        day in month            (Number)           10
  66.  * .   h        hour in am/pm (1~12)    (Number)           12
  67.  * .   H        hour in day (0~23)      (Number)           0
  68.  * .   m        minute in hour          (Number)           30
  69.  * .   s        second in minute        (Number)           55
  70.  * .   S        millisecond             (Number)           978
  71.  * .   E        day in week             (Text)             Tuesday
  72.  * .   D        day in year             (Number)           189
  73.  * .   F        day of week in month    (Number)           2 (2nd Wed in July)
  74.  * .   w        week in year            (Number)           27
  75.  * .   W        week in month           (Number)           2
  76.  * .   a        am/pm marker            (Text)             PM
  77.  * .   k        hour in day (1~24)      (Number)           24
  78.  * .   K        hour in am/pm (0~11)    (Number)           0
  79.  * .   z        time zone               (Text)             Pacific Standard Time
  80.  * .   '        escape for text
  81.  * .   ''       single quote                               '
  82.  * </pre>
  83.  * The count of pattern letters determine the format.
  84.  * <P>
  85.  * (Text): 4 or more, use full form, <4, use short or abbreviated form if it
  86.  * exists. (e.g., "EEEE" produces "Monday", "EEE" produces "Mon")
  87.  * <P>
  88.  * (Number): the minimum number of digits. Shorter numbers are zero-padded to
  89.  * this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled
  90.  * specially; that is, if the count of 'y' is 2, the Year will be truncated to 2 digits.
  91.  * (e.g., if "yyyy" produces "1997", "yy" produces "97".)
  92.  * <P>
  93.  * (Text & Number): 3 or over, use text, otherwise use number.  (e.g., "M" produces "1",
  94.  * "MM" produces "01", "MMM" produces "Jan", and "MMMM" produces "January".)
  95.  * <P>
  96.  * Any characters in the pattern that are not in the ranges of ['a'..'z'] and
  97.  * ['A'..'Z'] will be treated as quoted text. For instance, characters
  98.  * like ':', '.', ' ', '#' and '@' will appear in the resulting time text
  99.  * even they are not embraced within single quotes.
  100.  * <P>
  101.  * A pattern containing any invalid pattern letter will result in a failing
  102.  * UErrorCode result during formatting or parsing.
  103.  * <P>
  104.  * Examples using the US locale:
  105.  * <pre>
  106.  * .   Format Pattern                         Result
  107.  * .   --------------                         -------
  108.  * .   "yyyy.MM.dd G 'at' HH:mm:ss z"    ->>  1996.07.10 AD at 15:08:56 PDT
  109.  * .   "EEE, MMM d, ''yy"                ->>  Wed, July 10, '96
  110.  * .   "h:mm a"                          ->>  12:08 PM
  111.  * .   "hh 'o''clock' a, zzzz"           ->>  12 o'clock PM, Pacific Daylight Time
  112.  * .   "K:mm a, z"                       ->>  0:00 PM, PST
  113.  * .   "yyyyy.MMMMM.dd GGG hh:mm aaa"    ->>  1996.July.10 AD 12:08 PM
  114.  * </pre>
  115.  * Code Sample:
  116.  * <pre>
  117.  * .    UErrorCode success = U_ZERO_ERROR;
  118.  * .    SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST");
  119.  * .    pdt->setStartRule( Calendar::APRIL, 1, Calendar::SUNDAY, 2*60*60*1000);
  120.  * .    pdt->setEndRule( Calendar::OCTOBER, -1, Calendar::SUNDAY, 2*60*60*1000);
  121.  * .    
  122.  * .    // Format the current time.
  123.  * .    SimpleDateFormat* formatter
  124.  * .        = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz", success );
  125.  * .    GregorianCalendar cal(success);
  126.  * .    UDate currentTime_1 = cal.getTime(success);
  127.  * .    FieldPosition fp(0);
  128.  * .    UnicodeString dateString;
  129.  * .    formatter->format( currentTime_1, dateString, fp );
  130.  * .    cout << "result: " << dateString << endl;
  131.  * .    
  132.  * .    // Parse the previous string back into a Date.
  133.  * .    ParsePosition pp(0);
  134.  * .    UDate currentTime_2 = formatter->parse(dateString, pp );
  135.  * </pre>
  136.  * In the above example, the time value "currentTime_2" obtained from parsing
  137.  * will be equal to currentTime_1. However, they may not be equal if the am/pm
  138.  * marker 'a' is left out from the format pattern while the "hour in am/pm"
  139.  * pattern symbol is used. This information loss can happen when formatting the
  140.  * time in PM.
  141.  *
  142.  * <p>
  143.  * When parsing a date string using the abbreviated year pattern ("y" or "yy"),
  144.  * SimpleDateFormat must interpret the abbreviated year
  145.  * relative to some century.  It does this by adjusting dates to be
  146.  * within 80 years before and 20 years after the time the SimpleDateFormat
  147.  * instance is created. For example, using a pattern of "MM/dd/yy" and a
  148.  * SimpleDateFormat instance created on Jan 1, 1997,  the string
  149.  * "01/11/12" would be interpreted as Jan 11, 2012 while the string "05/04/64"
  150.  * would be interpreted as May 4, 1964.
  151.  * During parsing, only strings consisting of exactly two digits, as defined by
  152.  * <code>Unicode::isDigit()</code>, will be parsed into the default century.
  153.  * Any other numeric string, such as a one digit string, a three or more digit
  154.  * string, or a two digit string that isn't all digits (for example, "-1"), is
  155.  * interpreted literally.  So "01/02/3" or "01/02/003" are parsed, using the
  156.  * same pattern, as Jan 2, 3 AD.  Likewise, "01/02/-3" is parsed as Jan 2, 4 BC.
  157.  *
  158.  * <p>
  159.  * If the year pattern has more than two 'y' characters, the year is
  160.  * interpreted literally, regardless of the number of digits.  So using the
  161.  * pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
  162.  *
  163.  * <P>
  164.  * For time zones that have no names, SimpleDateFormat uses strings GMT+hours:minutes or
  165.  * GMT-hours:minutes.
  166.  * <P>
  167.  * The calendar defines what is the first day of the week, the first week of the
  168.  * year, whether hours are zero based or not (0 vs 12 or 24), and the timezone.
  169.  * There is one common number format to handle all the numbers; the digit count
  170.  * is handled programmatically according to the pattern.
  171.  */
  172. class U_I18N_API SimpleDateFormat: public DateFormat {
  173. public:
  174.     /**
  175.      * Construct a SimpleDateFormat using the default pattern for the default
  176.      * locale.
  177.      * <P>
  178.      * [Note:] Not all locales support SimpleDateFormat; for full generality,
  179.      * use the factory methods in the DateFormat class.
  180.      */
  181.     SimpleDateFormat(UErrorCode& status);
  182.  
  183.     /**
  184.      * Construct a SimpleDateFormat using the given pattern and the default locale.
  185.      * The locale is used to obtain the symbols used in formatting (e.g., the
  186.      * names of the months), but not to provide the pattern.
  187.      * <P>
  188.      * [Note:] Not all locales support SimpleDateFormat; for full generality,
  189.      * use the factory methods in the DateFormat class.
  190.      */
  191.     SimpleDateFormat(const UnicodeString& pattern,
  192.                      UErrorCode& status);
  193.  
  194.     /**
  195.      * Construct a SimpleDateFormat using the given pattern and locale.
  196.      * The locale is used to obtain the symbols used in formatting (e.g., the
  197.      * names of the months), but not to provide the pattern.
  198.      * <P>
  199.      * [Note:] Not all locales support SimpleDateFormat; for full generality,
  200.      * use the factory methods in the DateFormat class.
  201.      */
  202.     SimpleDateFormat(const UnicodeString& pattern,
  203.                      const Locale& locale,
  204.                      UErrorCode& status);
  205.  
  206.     /**
  207.      * Construct a SimpleDateFormat using the given pattern and locale-specific
  208.      * symbol data.  The formatter takes ownership of the DateFormatSymbols object;
  209.      * the caller is no longer responsible for deleting it.
  210.      */
  211.     SimpleDateFormat(const UnicodeString& pattern,
  212.                      DateFormatSymbols* formatDataToAdopt,
  213.                      UErrorCode& status);
  214.  
  215.     /**
  216.      * Construct a SimpleDateFormat using the given pattern and locale-specific
  217.      * symbol data.  The DateFormatSymbols object is NOT adopted; the caller
  218.      * remains responsible for deleting it.
  219.      */
  220.     SimpleDateFormat(const UnicodeString& pattern,
  221.                      const DateFormatSymbols& formatData,
  222.                      UErrorCode& status);
  223.  
  224.     /**
  225.      * Copy constructor.
  226.      */
  227.     SimpleDateFormat(const SimpleDateFormat&);
  228.  
  229.     /**
  230.      * Assignment operator.
  231.      */
  232.     SimpleDateFormat& operator=(const SimpleDateFormat&);
  233.  
  234.     /**
  235.      * Destructor.
  236.      */
  237.     virtual ~SimpleDateFormat();
  238.  
  239.     /**
  240.      * Clone this Format object polymorphically. The caller owns the result and
  241.      * should delete it when done.
  242.      */
  243.     virtual Format* clone(void) const;
  244.  
  245.     /**
  246.      * Return true if the given Format objects are semantically equal. Objects
  247.      * of different subclasses are considered unequal.
  248.      */
  249.     virtual bool_t operator==(const Format& other) const;
  250.  
  251.     /**
  252.      * Format a date or time, which is the standard millis since 24:00 GMT, Jan
  253.      * 1, 1970. Overrides DateFormat pure virtual method.
  254.      * <P>
  255.      * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
  256.      * 1996.07.10 AD at 15:08:56 PDT
  257.      *
  258.      * @param date          The date-time value to be formatted into a date-time string.
  259.      * @param toAppendTo    The result of the formatting operation is appended to this
  260.      *                      string.
  261.      * @param pos           The formatting position. On input: an alignment field,
  262.      *                      if desired. On output: the offsets of the alignment field.
  263.      * @return              A reference to 'toAppendTo'.
  264.      */
  265.     virtual UnicodeString& format(  UDate date,
  266.                                     UnicodeString& toAppendTo,
  267.                                     FieldPosition& pos) const;
  268.  
  269.     /**
  270.      * Format a date or time, which is the standard millis since 24:00 GMT, Jan
  271.      * 1, 1970. Overrides DateFormat pure virtual method.
  272.      * <P>
  273.      * Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
  274.      * 1996.07.10 AD at 15:08:56 PDT
  275.      *
  276.      * @param obj           A Formattable containing the date-time value to be formatted
  277.      *                      into a date-time string.  If the type of the Formattable
  278.      *                      is a numeric type, it is treated as if it were an
  279.      *                      instance of Date.
  280.      * @param toAppendTo    The result of the formatting operation is appended to this
  281.      *                      string.
  282.      * @param pos           The formatting position. On input: an alignment field,
  283.      *                      if desired. On output: the offsets of the alignment field.
  284.      * @return              A reference to 'toAppendTo'.
  285.      */
  286.     virtual UnicodeString& format(  const Formattable& obj,
  287.                                     UnicodeString& toAppendTo,
  288.                                     FieldPosition& pos,
  289.                                     UErrorCode& status) const;
  290.  
  291.     /**
  292.      * Redeclared DateFormat method.
  293.      */
  294.     UnicodeString& format(const Formattable& obj,
  295.                           UnicodeString& result,
  296.                           UErrorCode& status) const;
  297.  
  298.     /**
  299.      * Redeclared DateFormat method.
  300.      */
  301.     UnicodeString& format(UDate date, UnicodeString& result) const;
  302.  
  303.     /**
  304.      * Parse a date/time string starting at the given parse position. For
  305.      * example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
  306.      * that is equivalent to Date(837039928046).
  307.      * <P>
  308.      * By default, parsing is lenient: If the input is not in the form used by
  309.      * this object's format method but can still be parsed as a date, then the
  310.      * parse succeeds. Clients may insist on strict adherence to the format by
  311.      * calling setLenient(false).
  312.      *
  313.      * @see DateFormat::setLenient(boolean)
  314.      *
  315.      * @param text  The date/time string to be parsed
  316.      * @param pos   On input, the position at which to start parsing; on
  317.      *              output, the position at which parsing terminated, or the
  318.      *              start position if the parse failed.
  319.      * @return      A valid UDate if the input could be parsed.
  320.      */
  321.     virtual UDate parse( const UnicodeString& text,
  322.                         ParsePosition& pos) const;
  323.  
  324.  
  325.     /**
  326.      * Parse a date/time string. For example, a time text "07/10/96 4:5 PM, PDT"
  327.      * will be parsed into a UDate that is equivalent to Date(837039928046).
  328.      * Parsing begins at the beginning of the string and proceeds as far as
  329.      * possible.  Assuming no parse errors were encountered, this function
  330.      * doesn't return any information about how much of the string was consumed
  331.      * by the parsing.  If you need that information, use the version of
  332.      * parse() that takes a ParsePosition.
  333.      *
  334.      * @param text  The date/time string to be parsed
  335.      * @param status Filled in with U_ZERO_ERROR if the parse was successful, and with
  336.      *              an error value if there was a parse error.
  337.      * @return      A valid UDate if the input could be parsed.
  338.      */
  339.     virtual UDate parse( const UnicodeString& text,
  340.                         UErrorCode& status) const;
  341.  
  342.     /**
  343.      * Set the start UDate used to interpret two-digit year strings.
  344.      * When dates are parsed having 2-digit year strings, they are placed within
  345.      * a assumed range of 100 years starting on the two digit start date.  For
  346.      * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
  347.      * some other year.  SimpleDateFormat chooses a year so that the resultant
  348.      * date is on or after the two digit start date and within 100 years of the
  349.      * two digit start date.
  350.      * <P>
  351.      * By default, the two digit start date is set to 80 years before the current
  352.      * time at which a SimpleDateFormat object is created.
  353.      */
  354.     virtual void set2DigitYearStart(UDate d, UErrorCode& status);
  355.  
  356.     /**
  357.      * Get the start UDate used to interpret two-digit year strings.
  358.      * When dates are parsed having 2-digit year strings, they are placed within
  359.      * a assumed range of 100 years starting on the two digit start date.  For
  360.      * example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
  361.      * some other year.  SimpleDateFormat chooses a year so that the resultant
  362.      * date is on or after the two digit start date and within 100 years of the
  363.      * two digit start date.
  364.      * <P>
  365.      * By default, the two digit start date is set to 80 years before the current
  366.      * time at which a SimpleDateFormat object is created.
  367.      */
  368.     UDate get2DigitYearStart(UErrorCode& status) const;
  369.  
  370.     /**
  371.      * Return a pattern string describing this date format.
  372.      */
  373.     virtual UnicodeString& toPattern(UnicodeString& result) const;
  374.  
  375.     /**
  376.      * Return a localized pattern string describing this date format.
  377.      * In most cases, this will return the same thing as toPattern(),
  378.      * but a locale can specify characters to use in pattern descriptions
  379.      * in place of the ones described in this class's class documentation.
  380.      * (Presumably, letters that would be more mnemonic in that locale's
  381.      * language.)  This function would produce a pattern using those
  382.      * letters.
  383.      *
  384.      * @param result    Receives the localized pattern.
  385.      * @param status    Output param set to success/failure code on
  386.      *                  exit. If the pattern is invalid, this will be
  387.      *                  set to a failure result.
  388.      */
  389.     virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
  390.                                               UErrorCode& status) const;
  391.  
  392.     /**
  393.      * Apply the given unlocalized pattern string to this date format.
  394.      * (i.e., after this call, this formatter will format dates according to
  395.      * the new pattern)
  396.      *
  397.      * @param pattern   The pattern to be applied.
  398.      */
  399.     virtual void applyPattern(const UnicodeString& pattern);
  400.  
  401.     /**
  402.      * Apply the given localized pattern string to this date format.
  403.      * (see toLocalizedPattern() for more information on localized patterns.)
  404.      *
  405.      * @param pattern   The localized pattern to be applied.
  406.      * @param status    Output param set to success/failure code on
  407.      *                  exit. If the pattern is invalid, this will be
  408.      *                  set to a failure result.
  409.      */
  410.     virtual void applyLocalizedPattern(const UnicodeString& pattern,
  411.                                        UErrorCode& status);
  412.  
  413.     /**
  414.      * Gets the date/time formatting symbols (this is an object carrying
  415.      * the various strings and other symbols used in formatting: e.g., month
  416.      * names and abbreviations, time zone names, AM/PM strings, etc.)
  417.      * @return a copy of the date-time formatting data associated
  418.      * with this date-time formatter.
  419.      */
  420.     virtual const DateFormatSymbols* getDateFormatSymbols(void) const;
  421.  
  422.     /**
  423.      * Set the date/time formatting symbols.  The caller no longer owns the
  424.      * DateFormatSymbols object and should not delete it after making this call.
  425.      * @param newFormatData the given date-time formatting data.
  426.      */
  427.     virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
  428.  
  429.     /**
  430.      * Set the date/time formatting data.
  431.      * @param newFormatData the given date-time formatting data.
  432.      */
  433.     virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
  434.  
  435.  
  436. public:
  437.     /**
  438.      * Resource bundle file suffix and tag names used by this class.
  439.      */
  440.     static const UnicodeString      fgErasTag;   // resource bundle tag for era names
  441.     static const UnicodeString      fgMonthNamesTag; // resource bundle tag for month names
  442.     static const UnicodeString      fgMonthAbbreviationsTag; // resource bundle tag for month abbreviations
  443.     static const UnicodeString      fgDayNamesTag;   // resource bundle tag for day names
  444.     static const UnicodeString      fgDayAbbreviationsTag;   // resource bundle tag for day abbreviations
  445.     static const UnicodeString      fgAmPmMarkersTag;    // resource bundle tag for AM/PM strings
  446.     static const UnicodeString      fgDateTimePatternsTag;   // resource bundle tag for default date and time patterns
  447.  
  448.     static const UnicodeString      fgZoneStringsTag;    // resource bundle tag for time zone names
  449.     static const UnicodeString      fgLocalPatternCharsTag;  // resource bundle tag for localized pattern characters
  450.  
  451.     static const UnicodeString      fgDefaultPattern;    // date/time pattern of last resort
  452.  
  453. public:
  454.     /**
  455.      * Return the class ID for this class. This is useful only for comparing to
  456.      * a return value from getDynamicClassID(). For example:
  457.      * <pre>
  458.      * .   Base* polymorphic_pointer = createPolymorphicObject();
  459.      * .   if (polymorphic_pointer->getDynamicClassID() ==
  460.      * .       erived::getStaticClassID()) ...
  461.      * </pre>
  462.      * @return          The class ID for all objects of this class.
  463.      */
  464.     static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
  465.  
  466.     /**
  467.      * Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
  468.      * method is to implement a simple version of RTTI, since not all C++
  469.      * compilers support genuine RTTI. Polymorphic operator==() and clone()
  470.      * methods call this method.
  471.      *
  472.      * @return          The class ID for this object. All objects of a
  473.      *                  given class have the same class ID.  Objects of
  474.      *                  other classes have different class IDs.
  475.      */
  476.     virtual UClassID getDynamicClassID(void) const { return getStaticClassID(); }
  477.  
  478. private:
  479.     static char fgClassID;
  480.  
  481.     friend class DateFormat;
  482.  
  483.     /**
  484.      * Gets the index for the given time zone ID to obtain the timezone strings
  485.      * for formatting. The time zone ID is just for programmatic lookup. NOT
  486.      * LOCALIZED!!!
  487.      *
  488.      * @param DateFormatSymbols     a DateFormatSymbols object contianing the time zone names
  489.      * @param ID        the given time zone ID.
  490.      * @return          the index of the given time zone ID.  Returns -1 if
  491.      *                  the given time zone ID can't be located in the
  492.      *                  DateFormatSymbols object.
  493.      * @see SimpleTimeZone
  494.      */
  495.     //int32_t getZoneIndex(const DateFormatSymbols&, const UnicodeString& ID) const;
  496.  
  497.     void initializeDefaultCentury(void);
  498.  
  499.     /**
  500.      * Used by the DateFormat factory methods to construct a SimpleDateFormat.
  501.      */
  502.     SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
  503.  
  504.     /**
  505.      * Construct a SimpleDateFormat for the given locale.  If no resource data
  506.      * is available, create an object of last resort, using hard-coded strings.
  507.      * This is an internal method, called by DateFormat.  It should never fail.
  508.      */
  509.     SimpleDateFormat(const Locale& locale, UErrorCode& status); // Use default pattern
  510.  
  511.     /**
  512.      * Called by format() to format a single field.
  513.      *
  514.      * @param result    Filled in with the result.
  515.      * @param ch        The format character we encountered in the pattern.
  516.      * @param count     Number of characters in the current pattern symbol (e.g.,
  517.      *                  "yyyy" in the pattern would result in a call to this function
  518.      *                  with ch equal to 'y' and count equal to 4)
  519.      * @param beginOffset   Tells where the text returned by this function will go in
  520.      *                  the finished string.  Used when this function needs to fill
  521.      *                  in a FieldPosition
  522.      * @param pos       The FieldPosition being filled in by the format() call.  If
  523.      *                  this function is formatting the field specfied by pos, it
  524.      *                  will fill in pos will the beginning and ending offsets of the
  525.      *                  field.
  526.      * @param status    Receives a status code, which will be U_ZERO_ERROR if the operation
  527.      *                  succeeds.
  528.      * @return A reference to "result".
  529.      */
  530.     UnicodeString& subFormat(   UnicodeString& result,
  531.                                 UChar ch,
  532.                                 int32_t count,
  533.                                 int32_t beginOffset,
  534.                                 FieldPosition& pos,
  535.                                 UErrorCode& status) const; // in case of illegal argument
  536.  
  537.     /**
  538.      * Used by subFormat() to format a numeric value.  Fills in "result" with a string
  539.      * representation of "value" having a number of digits between "minDigits" and
  540.      * "maxDigits".  Uses the DateFormat's NumberFormat.
  541.      * @param result    Filled in with the formatted number.
  542.      * @param value     Value to format.
  543.      * @param minDigits Minimum number of digits the result should have
  544.      * @param maxDigits Maximum number of digits the result should have
  545.      * @return A reference to "result".
  546.      */
  547.     UnicodeString& zeroPaddingNumber(UnicodeString& result,
  548.                                      int32_t value,
  549.                                      int32_t minDigits,
  550.                                      int32_t maxDigits) const;
  551.  
  552.     /**
  553.      * Called by several of the constructors to load pattern data and formatting symbols
  554.      * out of a resource bundle and initialize the locale based on it.
  555.      * @param timeStyle     The time style, as passed to DateFormat::createDateInstance().
  556.      * @param dateStyle     The date style, as passed to DateFormat::createTimeInstance().
  557.      * @param locale        The locale to load the patterns from.
  558.      * @param status        Filled in with an error code if loading the data from the
  559.      *                      resources fails.
  560.      */
  561.     void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, UErrorCode& status);
  562.  
  563.     /**
  564.      * Called by construct() and the various constructors to set up the SimpleDateFormat's
  565.      * Calendar and NumberFormat objects.
  566.      * @param locale    The locale for which we want a Calendar and a NumberFormat.
  567.      * @param statuc    Filled in with an error code if creating either subobject fails.
  568.      */
  569.     void initialize(const Locale& locale, UErrorCode& status);
  570.  
  571.     /**
  572.      * Private code-size reduction function used by subParse.
  573.      * @param text the time text being parsed.
  574.      * @param start where to start parsing.
  575.      * @param field the date field being parsed.
  576.      * @param data the string array to parsed.
  577.      * @return the new start position if matching succeeded; a negative number
  578.      * indicating matching failure, otherwise.
  579.      */
  580.     int32_t matchString(const UnicodeString& text, UTextOffset start, Calendar::EDateFields field,
  581.                     const UnicodeString* stringArray, int32_t stringArrayCount) const;
  582.  
  583.     /**
  584.      * Private member function that converts the parsed date strings into
  585.      * timeFields. Returns -start (for ParsePosition) if failed.
  586.      * @param text the time text to be parsed.
  587.      * @param start where to start parsing.
  588.      * @param ch the pattern character for the date field text to be parsed.
  589.      * @param count the count of a pattern character.
  590.      * @param obeyCount if true then the count is strictly obeyed.
  591.      * @return the new start position if matching succeeded; a negative number
  592.      * indicating matching failure, otherwise.
  593.      */
  594.     int32_t subParse(const UnicodeString& text, int32_t& start, UChar ch, int32_t count,
  595.                  bool_t obeyCount, bool_t ambiguousYear[]) const;
  596.  
  597.     /**
  598.      * Parse the given text, at the given position, as a numeric value, using
  599.      * this object's NumberFormat. Return the corresponding long value in the
  600.      * fill-in parameter 'value'. If the parse fails, this method leaves pos
  601.      * unchanged and returns FALSE; otherwise it advances pos and
  602.      * returns TRUE.
  603.      */
  604.     //bool_t subParseLong(const UnicodeString& text, ParsePosition& pos, int32_t& value) const;
  605.  
  606.     /**
  607.      * Translate a pattern, mapping each character in the from string to the
  608.      * corresponding character in the to string. Return an error if the original
  609.      * pattern contains an unmapped character, or if a quote is unmatched.
  610.      * Quoted (single quotes only) material is not translated.
  611.      */
  612.     static void translatePattern(const UnicodeString& originalPattern,
  613.                                 UnicodeString& translatedPattern,
  614.                                 const UnicodeString& from,
  615.                                 const UnicodeString& to,
  616.                                 UErrorCode& status);
  617.     /**
  618.      * Given a zone ID, try to locate it in our time zone array. Return the
  619.      * index (row index) of the found time zone, or -1 if we can't find it.
  620.      */
  621.     //int32_t getZoneIndex(const UnicodeString& ID) const;
  622.  
  623.     /**
  624.      * Sets the starting date of the 100-year window that dates with 2-digit years
  625.      * are considered to fall within.
  626.      */
  627.     void         parseAmbiguousDatesAsAfter(UDate startDate, UErrorCode& status);
  628.  
  629.     /**
  630.      * Returns the beginning date of the 100-year window that dates with 2-digit years
  631.      * are considered to fall within.
  632.      */
  633.     UDate         internalGetDefaultCenturyStart(void) const;
  634.  
  635.     /**
  636.      * Returns the first year of the 100-year window that dates with 2-digit years
  637.      * are considered to fall within.
  638.      */
  639.     int32_t          internalGetDefaultCenturyStartYear(void) const;
  640.  
  641.     /**
  642.      * Initializes the 100-year window that dates with 2-digit years are considered
  643.      * to fall within so that its start date is 80 years before the current time.
  644.      */
  645.     static void  initializeSystemDefaultCentury(void);
  646.  
  647.     /**
  648.      * Last-resort string to use for "GMT" when constructing time zone strings.
  649.      */
  650.     // For time zones that have no names, use strings GMT+minutes and
  651.     // GMT-minutes. For instance, in France the time zone is GMT+60.
  652.     static const UnicodeString fgGmtPlus;
  653.     static const UnicodeString fgGmtMinus;
  654.     static const UnicodeString fgGmt;
  655.  
  656.     /**
  657.      * Used to map pattern characters to Calendar field identifiers.
  658.      */
  659.     static const Calendar::EDateFields fgPatternIndexToCalendarField[];
  660.  
  661.     /**
  662.      * Map index into pattern character string to DateFormat field number
  663.      */
  664.     static const DateFormat::EField fgPatternIndexToDateFormatField[];
  665.  
  666.     /**
  667.      * The formatting pattern for this formatter.
  668.      */
  669.     UnicodeString       fPattern;
  670.  
  671.     /**
  672.      * A pointer to an object containing the strings to use in formatting (e.g.,
  673.      * month and day names, AM and PM strings, time zone names, etc.)
  674.      */
  675.     DateFormatSymbols*  fSymbols;   // Owned
  676.  
  677.     /**
  678.      * If dates have ambiguous years, we map them into the century starting
  679.      * at defaultCenturyStart, which may be any date.  If defaultCenturyStart is
  680.      * set to SYSTEM_DEFAULT_CENTURY, which it is by default, then the system
  681.      * values are used.  The instance values defaultCenturyStart and
  682.      * defaultCenturyStartYear are only used if explicitly set by the user
  683.      * through the API method parseAmbiguousDatesAsAfter().
  684.      */
  685.     UDate                fDefaultCenturyStart;
  686.  
  687.     /**
  688.      * See documentation for defaultCenturyStart.
  689.      */
  690.     /*transient*/ int32_t   fDefaultCenturyStartYear;
  691.  
  692.     /**
  693.      * The system maintains a static default century start date.  This is initialized
  694.      * the first time it is used.  Before then, it is set to SYSTEM_DEFAULT_CENTURY to
  695.      * indicate an uninitialized state.  Once the system default century date and year
  696.      * are set, they do not change.
  697.      */
  698.     static UDate         fgSystemDefaultCenturyStart;
  699.  
  700.     /**
  701.      * See documentation for systemDefaultCenturyStart.
  702.      */
  703.     static int32_t          fgSystemDefaultCenturyStartYear;
  704.  
  705.     /**
  706.      * Default value that indicates the defaultCenturyStartYear is unitialized
  707.      */
  708.     static const int32_t    fgSystemDefaultCenturyYear;
  709.  
  710. public:
  711.     /**
  712.      * If a start date is set to this value, that indicates that the system default
  713.      * start is in effect for this instance.
  714.      */
  715.     static const UDate        fgSystemDefaultCentury;
  716. };
  717.  
  718. inline UDate
  719. SimpleDateFormat::get2DigitYearStart(UErrorCode& status) const
  720. {
  721.     return fDefaultCenturyStart;
  722. }
  723.  
  724. inline UnicodeString&
  725. SimpleDateFormat::format(const Formattable& obj,
  726.                          UnicodeString& result,
  727.                          UErrorCode& status) const {
  728.     // Don't use Format:: - use immediate base class only,
  729.     // in case immediate base modifies behavior later.
  730.     return DateFormat::format(obj, result, status);
  731. }
  732.  
  733. inline UnicodeString&
  734. SimpleDateFormat::format(UDate date, UnicodeString& result) const {
  735.     return DateFormat::format(date, result);
  736. }
  737.  
  738. #endif // _SMPDTFMT
  739. //eof
  740.