ICU-2436 Multiple Calendar support

X-SVN-Rev: 11956
This commit is contained in:
Steven R. Loomis 2003-05-15 22:30:24 +00:00
parent 90ccc8e5dc
commit de486792a9
3 changed files with 136 additions and 10 deletions

View File

@ -35,6 +35,13 @@
U_NAMESPACE_BEGIN
class ICUServiceFactory;
/**
* @draft ICU 2.6
*/
typedef const void* URegistryKey;
/**
* <code>Calendar</code> is an abstract base class for converting between
* a <code>UDate</code> object and a set of integer fields such as
@ -245,7 +252,8 @@ public:
*
* @param success Indicates the success/failure of Calendar creation. Filled in
* with U_ZERO_ERROR if created successfully, set to a failure result
* otherwise.
* otherwise. U_MISSING_RESOURCE_ERROR will be returned if the resource data
* requests a calendar type which has not been installed.
* @return A Calendar if created successfully. NULL otherwise.
* @stable ICU 2.0
*/
@ -325,7 +333,7 @@ public:
* @param count Number of locales returned.
* @return An array of Locale objects representing the set of locales for which
* Calendars are installed. The system retains ownership of this list;
* the caller must NOT delete it.
* the caller must NOT delete it. Does not include user-registered Calendars.
* @stable ICU 2.0
*/
static const Locale* getAvailableLocales(int32_t& count);
@ -1403,6 +1411,60 @@ private:
* The resource tag for the resource where the week-count data is stored.
*/
static const char kDateTimeElements[];
/**
* The resource tag where the default calendar is stored.
*/
static const char kDefaultCalendar[];
/**
* INTERNAL FOR 2.6 -- Registration.
*/
public:
/**
* Returns the resource key string used for this calendar type.
* For example, prepending "Eras_" to this string could return "Eras_japanese"
* or "Eras_gregorian".
*
* @returns static string, for example, "gregorian" or "japanese"
* @internal
*/
virtual const char * getType() const = 0;
/**
* Return a StringEnumeration over the locales available at the time of the call,
* including registered locales.
* @return a StringEnumeration over the locales available at the time of the call
* @internal
*/
static StringEnumeration* getAvailableLocales(void);
/**
* Register a new Calendar factory. The factory will be adopted.
* INTERNAL in 2.6
* @param toAdopt the factory instance to be adopted
* @param status the in/out status code, no special meanings are assigned
* @return a registry key that can be used to unregister this factory
* @internal
*/
static URegistryKey registerFactory(ICUServiceFactory* toAdopt, UErrorCode& status);
/**
* Unregister a previously-registered CalendarFactory using the key returned from the
* register call. Key becomes invalid after a successful call and should not be used again.
* The CalendarFactory corresponding to the key will be deleted.
* INTERNAL in 2.6
* @param key the registry key returned by a previous call to registerFactory
* @param status the in/out status code, no special meanings are assigned
* @return TRUE if the factory for the key was successfully unregistered
* @internal
*/
static UBool unregister(URegistryKey key, UErrorCode& status);
friend class CalendarFactory;
friend class CalendarService;
friend class DefaultCalendarFactory;
};
// -------------------------------------

View File

@ -65,7 +65,7 @@ class U_I18N_API DateFormatSymbols : public UObject {
public:
/**
* Construct a DateFormatSymbols object by loading format data from
* resources for the default locale.
* resources for the default locale, in the default calendar (Gregorian).
* <P>
* NOTE: This constructor will never fail; if it cannot get resource
* data for the default locale, it will return a last-resort object
@ -80,7 +80,7 @@ public:
/**
* Construct a DateFormatSymbols object by loading format data from
* resources for the given locale.
* resources for the given locale, in the default calendar (Gregorian).
*
* @param locale Locale to load format data from.
* @param status Output param set to success of failure. Failure
@ -91,6 +91,41 @@ public:
DateFormatSymbols(const Locale& locale,
UErrorCode& status);
/**
* Construct a DateFormatSymbols object by loading format data from
* resources for the default locale, in the default calendar (Gregorian).
* <P>
* NOTE: This constructor will never fail; if it cannot get resource
* data for the default locale, it will return a last-resort object
* based on hard-coded strings.
*
* @param type Type of calendar (as returned by Calendar::getType).
* Will be used to access the correct set of strings.
* (NULL or empty string defaults to "gregorian".)
* @param status Output param set to success of failure. Failure
* results if the resources for the default cannot be
* found or cannot be loaded
* @draft ICU 2.6
*/
DateFormatSymbols(const char *type, UErrorCode& status);
/**
* Construct a DateFormatSymbols object by loading format data from
* resources for the given locale, in the default calendar (Gregorian).
*
* @param locale Locale to load format data from.
* @param type Type of calendar (as returned by Calendar::getType).
* Will be used to access the correct set of strings.
* (NULL or empty string defaults to "gregorian".)
* @param status Output param set to success of failure. Failure
* results if the resources for the locale cannot be
* found or cannot be loaded
* @draft ICU 2.6
*/
DateFormatSymbols(const Locale& locale,
const char *type,
UErrorCode& status);
/**
* Copy constructor.
* @stable ICU 2.0
@ -378,15 +413,29 @@ private:
void initField(UnicodeString **field, int32_t& length, const ResourceBundle data, UErrorCode &status);
void initField(UnicodeString **field, int32_t& length, const UChar *data, LastResortSize numStr, LastResortSize strLen, UErrorCode &status);
/**
* Load data for specified 'type', falling back to gregorian if needed
*
* @param rb ResourceBundle
* @param tag Resource key to data
* @param type Calendar type
* @param status Error Status
* @internal
*/
ResourceBundle
getData(ResourceBundle &rb, const char *tag, const char *type, UErrorCode& status);
/**
* Called by the constructors to actually load data from the resources
*
* @param locale The locale to get symbols for.
* @param type Calendar Type (as from Calendar::getType())
* @param status Input/output parameter, set to success or
* failure code upon return.
* @param useLastResortData determine if use last resort data
*/
void initializeData(const Locale&, UErrorCode& status, UBool useLastResortData = FALSE);
void initializeData(const Locale&, const char *type, UErrorCode& status, UBool useLastResortData = FALSE);
/**
* Copy or alias an array in another object, as appropriate.

View File

@ -546,8 +546,22 @@ public:
*/
static inline UClassID getStaticClassID(void);
/**
* return the calendar type, "gregorian".
*
* @return calendar type
* @internal
*/
virtual const char * getType() const;
protected:
/***
* Called by computeFields. Converts calendar's year into Gregorian Extended Year (where negative = BC)
* @internal
*/
//virtual int32_t getGregorianYear(UErrorCode &status);
/**
* (Overrides Calendar) Converts GMT as milliseconds to time field values.
* @param status Fill-in parameter which receives the status of this operation.
@ -569,19 +583,20 @@ protected:
private:
GregorianCalendar(); // default constructor not implemented
protected:
/**
* Return the ERA. We need a special method for this because the
* default ERA is AD, but a zero (unset) ERA is BC.
* @return the ERA.
*/
int32_t internalGetEra() const;
virtual int32_t internalGetEra() const;
/**
* return the length of the given month.
* @param month the given month.
* @return the length of the given month.
*/
int32_t monthLength(int32_t month) const;
virtual int32_t monthLength(int32_t month) const;
/**
* return the length of the month according to the given year.
@ -589,7 +604,7 @@ private:
* @param year the given year.
* @return the length of the month
*/
int32_t monthLength(int32_t month, int32_t year) const;
virtual int32_t monthLength(int32_t month, int32_t year) const;
/**
* return the length of the given year.
@ -618,8 +633,8 @@ private:
* @param status Fill-in parameter which receives the status of this operation.
* @return the day number with respect to the epoch.
*/
UDate getEpochDay(UErrorCode& status);
virtual UDate getEpochDay(UErrorCode& status);
private:
/**
* Compute the julian day number of the given year.
* @param isGregorian if true, using Gregorian calendar, otherwise using Julian calendar