From 9f4a4ce5e0da0bc00ebb1bc14a28de66be8bd25b Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Fri, 29 Jun 2007 16:56:34 +0000 Subject: [PATCH] ICU-4567 initial taiwan calendar support X-SVN-Rev: 21854 --- icu4c/source/data/locales/root.txt | 9 + icu4c/source/data/locales/zh.txt | 9 + icu4c/source/data/xml/main/root.xml | 54 ++++ icu4c/source/data/xml/main/zh.xml | 12 + icu4c/source/i18n/Makefile.in | 2 +- icu4c/source/i18n/calendar.cpp | 4 + icu4c/source/i18n/i18n.vcproj | 8 + icu4c/source/i18n/taiwncal.cpp | 292 ++++++++++++++++++++++ icu4c/source/i18n/taiwncal.h | 311 ++++++++++++++++++++++++ icu4c/source/test/intltest/incaltst.cpp | 131 ++++++++++ icu4c/source/test/intltest/incaltst.h | 3 + 11 files changed, 834 insertions(+), 1 deletion(-) create mode 100644 icu4c/source/i18n/taiwncal.cpp create mode 100644 icu4c/source/i18n/taiwncal.h diff --git a/icu4c/source/data/locales/root.txt b/icu4c/source/data/locales/root.txt index 148465fd945..e7a0ad39b8c 100644 --- a/icu4c/source/data/locales/root.txt +++ b/icu4c/source/data/locales/root.txt @@ -72,6 +72,15 @@ root{ } Version{"1.92"} calendar{ + // taiwan calendar added manually by srl. To be replaced by autogenerated data in xml/root.xml and later in CLDR + taiwan{ + eras { + abbreviated{ + "míngúo" + } + } + } + // end manual additions buddhist{ AmPmMarkers{ "AM", diff --git a/icu4c/source/data/locales/zh.txt b/icu4c/source/data/locales/zh.txt index e34ed210632..3e606e537b3 100644 --- a/icu4c/source/data/locales/zh.txt +++ b/icu4c/source/data/locales/zh.txt @@ -2016,6 +2016,15 @@ zh{ } Version{"1.92"} calendar{ + // taiwan calendar added manually by srl. To be replaced by autogenerated data in xml/zh.xml and later in CLDR + taiwan{ + eras { + abbreviated{ + "民國" + } + } + } + // end manual additions gregorian{ AmPmMarkers{ "上午", diff --git a/icu4c/source/data/xml/main/root.xml b/icu4c/source/data/xml/main/root.xml index 35f9b881e7f..6254cfee242 100644 --- a/icu4c/source/data/xml/main/root.xml +++ b/icu4c/source/data/xml/main/root.xml @@ -37,6 +37,60 @@ + + + + + + + + + + + AM + PM + + + + + + míngúo + + + + + + + + + + + EEEE, MMMM d, yyyy G + + + + + MMMM d, yyyy G + + + + + MMM d, yyyy G + + + + + M/d/yyyy + + + + + + + + + + diff --git a/icu4c/source/data/xml/main/zh.xml b/icu4c/source/data/xml/main/zh.xml index dfc6a065afc..33c40534ef2 100644 --- a/icu4c/source/data/xml/main/zh.xml +++ b/icu4c/source/data/xml/main/zh.xml @@ -21,5 +21,17 @@ + + + + + + 民國 + + + + + + diff --git a/icu4c/source/i18n/Makefile.in b/icu4c/source/i18n/Makefile.in index 84a18f207c3..87f791c672d 100644 --- a/icu4c/source/i18n/Makefile.in +++ b/icu4c/source/i18n/Makefile.in @@ -67,7 +67,7 @@ ucurr.o digitlst.o fmtable_cnv.o \ choicfmt.o datefmt.o smpdtfmt.o reldtfmt.o dtfmtsym.o udat.o \ nfrs.o nfrule.o nfsubs.o rbnf.o ucsdet.o \ ucal.o calendar.o gregocal.o timezone.o simpletz.o olsontz.o \ -astro.o buddhcal.o persncal.o islamcal.o japancal.o gregoimp.o hebrwcal.o \ +astro.o taiwncal.o buddhcal.o persncal.o islamcal.o japancal.o gregoimp.o hebrwcal.o \ coleitr.o coll.o tblcoll.o sortkey.o bocsu.o ucoleitr.o \ ucol.o ucol_res.o ucol_bld.o ucol_sit.o ucol_tok.o ucol_wgt.o ucol_cnt.o ucol_elm.o \ strmatch.o usearch.o search.o stsearch.o \ diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index eed6804ab14..a31e4d8d491 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -31,6 +31,7 @@ #include "unicode/gregocal.h" #include "gregoimp.h" #include "buddhcal.h" +#include "taiwncal.h" #include "japancal.h" #include "islamcal.h" #include "hebrwcal.h" @@ -156,6 +157,7 @@ static const char * const gCalendarKeywords[] = { "gregorian", "japanese", "buddhist", + "taiwan", "persian", "islamic-civil", "islamic", @@ -205,6 +207,8 @@ static Calendar *createStandardCalendar(char *calType, const Locale &canLoc, UEr return new JapaneseCalendar(canLoc, status); } else if(!uprv_strcmp(calType, "buddhist")) { return new BuddhistCalendar(canLoc, status); + } else if(!uprv_strcmp(calType, "taiwan")) { + return new TaiwanCalendar(canLoc, status); } else if(!uprv_strcmp(calType, "islamic-civil")) { return new IslamicCalendar(canLoc, status, IslamicCalendar::CIVIL); } else if(!uprv_strcmp(calType, "islamic")) { diff --git a/icu4c/source/i18n/i18n.vcproj b/icu4c/source/i18n/i18n.vcproj index 9e0f88cc83c..e1ac44e7853 100644 --- a/icu4c/source/i18n/i18n.vcproj +++ b/icu4c/source/i18n/i18n.vcproj @@ -530,6 +530,14 @@ RelativePath=".\unicode\basictz.h" > + + + + diff --git a/icu4c/source/i18n/taiwncal.cpp b/icu4c/source/i18n/taiwncal.cpp new file mode 100644 index 00000000000..d0df5b205ca --- /dev/null +++ b/icu4c/source/i18n/taiwncal.cpp @@ -0,0 +1,292 @@ +/* +******************************************************************************* +* Copyright (C) 2003-2006, International Business Machines Corporation and * +* others. All Rights Reserved. * +******************************************************************************* +* +* File TAIWNCAL.CPP +* +* Modification History: +* 05/13/2003 srl copied from gregocal.cpp +* 06/29/2007 srl copied from buddhcal.cpp +* +*/ + +#include "unicode/utypes.h" + +#if !UCONFIG_NO_FORMATTING + +#include "taiwncal.h" +#include "unicode/gregocal.h" +#include "umutex.h" +#include + +U_NAMESPACE_BEGIN + +UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TaiwanCalendar) + +static const int32_t kMaxEra = 0; // only 1 era + +static const int32_t kTaiwanEraStart = 1911; // 1911 (Gregorian) + +static const int32_t kGregorianEpoch = 1970; + +TaiwanCalendar::TaiwanCalendar(const Locale& aLocale, UErrorCode& success) +: GregorianCalendar(aLocale, success) +{ + setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly. +} + +TaiwanCalendar::~TaiwanCalendar() +{ +} + +TaiwanCalendar::TaiwanCalendar(const TaiwanCalendar& source) +: GregorianCalendar(source) +{ +} + +TaiwanCalendar& TaiwanCalendar::operator= ( const TaiwanCalendar& right) +{ + GregorianCalendar::operator=(right); + return *this; +} + +Calendar* TaiwanCalendar::clone(void) const +{ + return new TaiwanCalendar(*this); +} + +const char *TaiwanCalendar::getType() const +{ + return "taiwan"; +} + +int32_t +TaiwanCalendar::getMaximum(UCalendarDateFields field) const +{ + if(field == UCAL_ERA) { + return kMaxEra; + } else { + return GregorianCalendar::getMaximum(field); + } +} + +int32_t +TaiwanCalendar::getLeastMaximum(UCalendarDateFields field) const +{ + if(field == UCAL_ERA) { + return kMaxEra; + } else { + return GregorianCalendar::getLeastMaximum(field); + } +} + +int32_t +TaiwanCalendar::monthLength(int32_t month, int32_t year) const +{ + return GregorianCalendar::monthLength(month,year); +} + + +int32_t +TaiwanCalendar::monthLength(int32_t month) const +{ + UErrorCode status = U_ZERO_ERROR; + // ignore era + return GregorianCalendar::monthLength(month, getGregorianYear(status)); +} + +int32_t TaiwanCalendar::internalGetEra() const +{ + return internalGet(UCAL_ERA, MINGUO); +} + +int32_t +TaiwanCalendar::getGregorianYear(UErrorCode &status) const +{ + int32_t year = (fStamp[UCAL_YEAR] != kUnset) ? internalGet(UCAL_YEAR) : kGregorianEpoch+kTaiwanEraStart; + int32_t era = MINGUO; + if (fStamp[UCAL_ERA] != kUnset) { + era = internalGet(UCAL_ERA); + if (era != MINGUO) { + status = U_ILLEGAL_ARGUMENT_ERROR; + return kGregorianEpoch + kTaiwanEraStart; + } + } + return year + kTaiwanEraStart; +} + +int32_t TaiwanCalendar::handleGetExtendedYear() +{ + int32_t year; + if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) { + year = internalGet(UCAL_EXTENDED_YEAR, 1); + } else { + // Ignore the era, as there is only one + year = internalGet(UCAL_YEAR, 1); + } + return year; +} + +int32_t TaiwanCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, + + UBool useMonth) const +{ + return GregorianCalendar::handleComputeMonthStart(eyear+kTaiwanEraStart, month, useMonth); +} + +void TaiwanCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status) +{ + GregorianCalendar::handleComputeFields(julianDay, status); + int32_t y = internalGet(UCAL_EXTENDED_YEAR) - kTaiwanEraStart; + internalSet(UCAL_EXTENDED_YEAR, y); + internalSet(UCAL_ERA, 0); + internalSet(UCAL_YEAR, y); +} + +int32_t TaiwanCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const +{ + if(field == UCAL_ERA) { + return MINGUO; + } else { + return GregorianCalendar::handleGetLimit(field,limitType); + } +} + +#if 0 +void TaiwanCalendar::timeToFields(UDate theTime, UBool quick, UErrorCode& status) +{ + //Calendar::timeToFields(theTime, quick, status); + + int32_t era = internalGet(UCAL_ERA); + int32_t year = internalGet(UCAL_YEAR); + + if(era == GregorianCalendar::BC) { + year = 1-year; + era = TaiwanCalendar::MINGUO; + } else if(era == GregorianCalendar::AD) { + era = TaiwanCalendar::MINGUO; + } else { + status = U_INTERNAL_PROGRAM_ERROR; + } + + year = year - kTaiwanEraStart; + + internalSet(UCAL_ERA, era); + internalSet(UCAL_YEAR, year); +} +#endif + +void TaiwanCalendar::add(UCalendarDateFields field, int32_t amount, UErrorCode& status) +{ + if (U_FAILURE(status)) + return; + + if (amount == 0) + return; // Do nothing! + + if(field == UCAL_YEAR /* || field == UCAL_YEAR_WOY */) { + int32_t year = get(field, status); // not internalGet -- force completion + + year += amount; + + set(field,year); + pinDayOfMonth(); + } else { + GregorianCalendar::add(field,amount,status); + } +} + + + +// default century +const UDate TaiwanCalendar::fgSystemDefaultCentury = DBL_MIN; +const int32_t TaiwanCalendar::fgSystemDefaultCenturyYear = -1; + +UDate TaiwanCalendar::fgSystemDefaultCenturyStart = DBL_MIN; +int32_t TaiwanCalendar::fgSystemDefaultCenturyStartYear = -1; + + +UBool TaiwanCalendar::haveDefaultCentury() const +{ + return TRUE; +} + +UDate TaiwanCalendar::defaultCenturyStart() const +{ + return internalGetDefaultCenturyStart(); +} + +int32_t TaiwanCalendar::defaultCenturyStartYear() const +{ + return internalGetDefaultCenturyStartYear(); +} + +UDate +TaiwanCalendar::internalGetDefaultCenturyStart() const +{ + // lazy-evaluate systemDefaultCenturyStart + UBool needsUpdate; + UMTX_CHECK(NULL, (fgSystemDefaultCenturyStart == fgSystemDefaultCentury), needsUpdate); + + if (needsUpdate) { + initializeSystemDefaultCentury(); + } + + // use defaultCenturyStart unless it's the flag value; + // then use systemDefaultCenturyStart + + return fgSystemDefaultCenturyStart; +} + +int32_t +TaiwanCalendar::internalGetDefaultCenturyStartYear() const +{ + // lazy-evaluate systemDefaultCenturyStartYear + UBool needsUpdate; + UMTX_CHECK(NULL, (fgSystemDefaultCenturyStart == fgSystemDefaultCentury), needsUpdate); + + if (needsUpdate) { + initializeSystemDefaultCentury(); + } + + // use defaultCenturyStart unless it's the flag value; + // then use systemDefaultCenturyStartYear + + return fgSystemDefaultCenturyStartYear; +} + +void +TaiwanCalendar::initializeSystemDefaultCentury() +{ + // initialize systemDefaultCentury and systemDefaultCenturyYear based + // on the current time. They'll be set to 80 years before + // the current time. + // No point in locking as it should be idempotent. + if (fgSystemDefaultCenturyStart == fgSystemDefaultCentury) + { + UErrorCode status = U_ZERO_ERROR; + TaiwanCalendar calendar(Locale("@calendar=Taiwan"),status); + if (U_SUCCESS(status)) + { + calendar.setTime(Calendar::getNow(), status); + calendar.add(UCAL_YEAR, -80, status); + UDate newStart = calendar.getTime(status); + int32_t newYear = calendar.get(UCAL_YEAR, status); + { + umtx_lock(NULL); + fgSystemDefaultCenturyStart = newStart; + fgSystemDefaultCenturyStartYear = newYear; + umtx_unlock(NULL); + } + } + // We have no recourse upon failure unless we want to propagate the failure + // out. + } +} + + +U_NAMESPACE_END + +#endif diff --git a/icu4c/source/i18n/taiwncal.h b/icu4c/source/i18n/taiwncal.h new file mode 100644 index 00000000000..c0ebe8721ae --- /dev/null +++ b/icu4c/source/i18n/taiwncal.h @@ -0,0 +1,311 @@ +/* + ******************************************************************************** + * Copyright (C) 2003-2007, International Business Machines Corporation + * and others. All Rights Reserved. + ******************************************************************************** + * + * File BUDDHCAL.H + * + * Modification History: + * + * Date Name Description + * 05/13/2003 srl copied from gregocal.h + * 06/29/2007 srl copied from buddhcal.h + ******************************************************************************** + */ + +#ifndef TAIWNCAL_H +#define TAIWNCAL_H + +#include "unicode/utypes.h" + +#if !UCONFIG_NO_FORMATTING + +#include "unicode/calendar.h" +#include "unicode/gregocal.h" + +U_NAMESPACE_BEGIN + +/** + * Concrete class which provides the Taiwan calendar. + *

+ * TaiwanCalendar is a subclass of GregorianCalendar + * that numbers years since 1912 + *

+ * The Taiwan calendar is identical to the Gregorian calendar in all respects + * except for the year and era. Years are numbered since 1912 AD (Gregorian), + * so that 1912 AD (Gregorian) is equivalent to 1 MINGUO (Minguo Era) and 1998 AD is 87 MINGUO. + *

+ * The Taiwan Calendar has only one allowable era: MINGUO. If the + * calendar is not in lenient mode (see setLenient), dates before + * 1/1/1 MINGUO are rejected as an illegal argument. + *

+ * @internal + */ +class TaiwanCalendar : public GregorianCalendar { +public: + + /** + * Useful constants for TaiwanCalendar. Only one Era. + * @internal + */ + enum EEras { + MINGUO + }; + + /** + * Constructs a TaiwanCalendar based on the current time in the default time zone + * with the given locale. + * + * @param aLocale The given locale. + * @param success Indicates the status of TaiwanCalendar object construction. + * Returns U_ZERO_ERROR if constructed successfully. + * @internal + */ + TaiwanCalendar(const Locale& aLocale, UErrorCode& success); + + + /** + * Destructor + * @internal + */ + virtual ~TaiwanCalendar(); + + /** + * Copy constructor + * @param source the object to be copied. + * @internal + */ + TaiwanCalendar(const TaiwanCalendar& source); + + /** + * Default assignment operator + * @param right the object to be copied. + * @internal + */ + TaiwanCalendar& operator=(const TaiwanCalendar& right); + + /** + * Create and return a polymorphic copy of this calendar. + * @return return a polymorphic copy of this calendar. + * @internal + */ + virtual Calendar* clone(void) const; + +public: + /** + * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual + * override. This method is to implement a simple version of RTTI, since not all C++ + * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call + * this method. + * + * @return The class ID for this object. All objects of a given class have the + * same class ID. Objects of other classes have different class IDs. + * @internal + */ + virtual UClassID getDynamicClassID(void) const; + + /** + * Return the class ID for this class. This is useful only for comparing to a return + * value from getDynamicClassID(). For example: + * + * Base* polymorphic_pointer = createPolymorphicObject(); + * if (polymorphic_pointer->getDynamicClassID() == + * Derived::getStaticClassID()) ... + * + * @return The class ID for all objects of this class. + * @internal + */ + U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void); + + /** + * return the calendar type, "Taiwan". + * + * @return calendar type + * @internal + */ + virtual const char * getType() const; + + /** + * (Overrides Calendar) UDate Arithmetic function. Adds the specified (signed) amount + * of time to the given time field, based on the calendar's rules. For more + * information, see the documentation for Calendar::add(). + * + * @param field The time field. + * @param amount The amount of date or time to be added to the field. + * @param status Output param set to success/failure code on exit. If any value + * previously set in the time field is invalid, this will be set to + * an error status. + * @draft ICU 2.6 + */ + virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status); + + /** + * Gets the maximum value for the given time field. e.g. for DAY_OF_MONTH, + * 31. + * + * @param field The given time field. + * @return The maximum value for the given time field. + * @draft ICU 2.6 + */ + int32_t getMaximum(UCalendarDateFields field) const; + + /** + * Gets the lowest maximum value for the given field if varies. Otherwise same as + * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28. + * + * @param field The given time field. + * @return The lowest maximum value for the given time field. + * @draft ICU 2.6 + */ + int32_t getLeastMaximum(UCalendarDateFields field) const; + + /** + * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields + */ + inline virtual int32_t getMaximum(EDateFields field) const { return getMaximum((UCalendarDateFields)field); } + /** + * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields + */ + inline virtual int32_t getLeastMaximum(EDateFields field) const { return getLeastMaximum((UCalendarDateFields)field); } + /** + * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields + */ + inline virtual void add(EDateFields field, int32_t amount, UErrorCode& status) { add((UCalendarDateFields)field, amount, status); } + +private: + TaiwanCalendar(); // default constructor not implemented + + protected: + /** + * Return the extended year defined by the current fields. This will + * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such + * as UCAL_ERA) specific to the calendar system, depending on which set of + * fields is newer. + * @return the extended year + * @internal + */ + virtual int32_t handleGetExtendedYear(); + /** + * Subclasses may override this method to compute several fields + * specific to each calendar system. + * @internal + */ + virtual void handleComputeFields(int32_t julianDay, UErrorCode& status); + /** + * Subclass API for defining limits of different types. + * @param field one of the field numbers + * @param limitType one of MINIMUM, GREATEST_MINIMUM, + * LEAST_MAXIMUM, or MAXIMUM + * @internal + */ + virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const; + /** + * Return the Julian day number of day before the first day of the + * given month in the given extended year. Subclasses should override + * this method to implement their calendar system. + * @param eyear the extended year + * @param month the zero-based month, or 0 if useMonth is false + * @param useMonth if false, compute the day before the first day of + * the given year, otherwise, compute the day before the first day of + * the given month + * @param return the Julian day number of the day before the first + * day of the given month and year + * @internal + */ + virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, + UBool useMonth) const; + + /** + * month length of current month + * @internal + */ + virtual int32_t monthLength(int32_t month) const; + /** + * month length of month + * @internal + */ + virtual int32_t monthLength(int32_t month, int32_t year) const; + + /** + * month length of current month + * @internal + */ + int32_t getGregorianYear(UErrorCode& status) const; + + /** + * Calculate the era for internal computation + * @internal + */ + virtual int32_t internalGetEra() const; + + /** + * Returns TRUE because the Taiwan Calendar does have a default century + * @internal + */ + virtual UBool haveDefaultCentury() const; + + /** + * Returns the date of the start of the default century + * @return start of century - in milliseconds since epoch, 1970 + * @internal + */ + virtual UDate defaultCenturyStart() const; + + /** + * Returns the year in which the default century begins + * @internal + */ + virtual int32_t defaultCenturyStartYear() const; + + private: // default century stuff. + /** + * The system maintains a static default century start date. This is initialized + * the first time it is used. Before then, it is set to SYSTEM_DEFAULT_CENTURY to + * indicate an uninitialized state. Once the system default century date and year + * are set, they do not change. + */ + static UDate fgSystemDefaultCenturyStart; + + /** + * See documentation for systemDefaultCenturyStart. + */ + static int32_t fgSystemDefaultCenturyStartYear; + + /** + * Default value that indicates the defaultCenturyStartYear is unitialized + */ + static const int32_t fgSystemDefaultCenturyYear; + + /** + * start of default century, as a date + */ + static const UDate fgSystemDefaultCentury; + + /** + * Returns the beginning date of the 100-year window that dates + * with 2-digit years are considered to fall within. + */ + UDate internalGetDefaultCenturyStart(void) const; + + /** + * Returns the first year of the 100-year window that dates with + * 2-digit years are considered to fall within. + */ + int32_t internalGetDefaultCenturyStartYear(void) const; + + /** + * Initializes the 100-year window that dates with 2-digit years + * are considered to fall within so that its start date is 80 years + * before the current time. + */ + static void initializeSystemDefaultCentury(void); +}; + +U_NAMESPACE_END + +#endif /* #if !UCONFIG_NO_FORMATTING */ + +#endif // _TAIWNCAL +//eof + diff --git a/icu4c/source/test/intltest/incaltst.cpp b/icu4c/source/test/intltest/incaltst.cpp index bbaa139b050..b843012da11 100644 --- a/icu4c/source/test/intltest/incaltst.cpp +++ b/icu4c/source/test/intltest/incaltst.cpp @@ -77,6 +77,8 @@ void IntlCalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &n CASE(6,TestJapanese3860); CASE(7,TestPersian); CASE(8,TestPersianFormat); + CASE(9,TestTaiwan); + CASE(10,TestTaiwanFormat); default: name = ""; break; } } @@ -293,6 +295,52 @@ void IntlCalendarTest::TestBuddhist() { delete cal; } + +/** + * Verify that TaiWanCalendar shifts years to Minguo Era but otherwise + * behaves like GregorianCalendar. + */ +void IntlCalendarTest::TestTaiwan() { + // MG 1 == 1912 AD + UDate timeA = Calendar::getNow(); + + int32_t data[] = { + 0, // B. era [928479600000] + 1, // B. year + 1912, // G. year + UCAL_JUNE, // month + 4, // day + + 0, // B. era [-79204842000000] + 3, // B. year + 1914, // G. year + UCAL_FEBRUARY, // month + 12, // day + + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1 + }; + Calendar *cal; + UErrorCode status = U_ZERO_ERROR; + cal = Calendar::createInstance("en_US@calendar=taiwan", status); + CHECK(status, UnicodeString("Creating en_US@calendar=taiwan calendar")); + + // Sanity check the calendar + UDate timeB = Calendar::getNow(); + UDate timeCal = cal->getTime(status); + + if(!(timeA <= timeCal) || !(timeCal <= timeB)) { + errln((UnicodeString)"Error: Calendar time " + timeCal + + " is not within sampled times [" + timeA + " to " + timeB + "]!"); + } + // end sanity check + + + quasiGregorianTest(*cal,Locale("en_US"),data); + delete cal; +} + + + /** * Verify that JapaneseCalendar shifts years to Japanese Eras but otherwise * behaves like GregorianCalendar. @@ -342,6 +390,8 @@ void IntlCalendarTest::TestJapanese() { delete cal; } + + void IntlCalendarTest::TestBuddhistFormat() { UErrorCode status = U_ZERO_ERROR; @@ -420,6 +470,87 @@ void IntlCalendarTest::TestBuddhistFormat() { } +void IntlCalendarTest::TestTaiwanFormat() { +// TODO: need some more data +#if 0 + UErrorCode status = U_ZERO_ERROR; + + // Test simple parse/format with adopt + + // First, a contrived english test.. + UDate aDate = 999932400000.0; + SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=buddhist"), status); + CHECK(status, "creating date format instance"); + SimpleDateFormat *fmt2 = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=gregorian"), status); + CHECK(status, "creating gregorian date format instance"); + if(!fmt) { + errln("Coudln't create en_US instance"); + } else { + UnicodeString str; + fmt2->format(aDate, str); + logln(UnicodeString() + "Test Date: " + str); + str.remove(); + fmt->format(aDate, str); + logln(UnicodeString() + "as Buddhist Calendar: " + escape(str)); + UnicodeString expected("September 8, 2544 BE"); + if(str != expected) { + errln("Expected " + escape(expected) + " but got " + escape(str)); + } + UDate otherDate = fmt->parse(expected, status); + if(otherDate != aDate) { + UnicodeString str3; + fmt->format(otherDate, str3); + errln("Parse incorrect of " + escape(expected) + " - wanted " + aDate + " but got " + otherDate + ", " + escape(str3)); + } else { + logln("Parsed OK: " + expected); + } + delete fmt; + } + delete fmt2; + + CHECK(status, "Error occured testing Buddhist Calendar in English "); + + status = U_ZERO_ERROR; + // Now, try in Thai + { + UnicodeString expect = CharsToUnicodeString("\\u0E27\\u0E31\\u0E19\\u0E40\\u0E2A\\u0E32\\u0E23\\u0E4C\\u0E17\\u0E35\\u0E48" + " 8 \\u0E01\\u0E31\\u0e19\\u0e22\\u0e32\\u0e22\\u0e19 \\u0e1e.\\u0e28. 2544"); + UDate expectDate = 999932400000.0; + Locale loc("th_TH_TRADITIONAL"); // legacy + + simpleTest(loc, expect, expectDate, status); + } + status = U_ZERO_ERROR; + { + UnicodeString expect = CharsToUnicodeString("\\u0E27\\u0E31\\u0E19\\u0E40\\u0E2A\\u0E32\\u0E23\\u0E4C\\u0E17\\u0E35\\u0E48" + " 8 \\u0E01\\u0E31\\u0e19\\u0e22\\u0e32\\u0e22\\u0e19 \\u0e1e.\\u0e28. 2544"); + UDate expectDate = 999932400000.0; + Locale loc("th_TH@calendar=buddhist"); + + simpleTest(loc, expect, expectDate, status); + } + status = U_ZERO_ERROR; + { + UnicodeString expect = CharsToUnicodeString("\\u0E27\\u0E31\\u0E19\\u0E40\\u0E2A\\u0E32\\u0E23\\u0E4C\\u0E17\\u0E35\\u0E48" + " 8 \\u0E01\\u0E31\\u0e19\\u0e22\\u0e32\\u0e22\\u0e19 \\u0e04.\\u0e28. 2001"); + UDate expectDate = 999932400000.0; + Locale loc("th_TH@calendar=gregorian"); + + simpleTest(loc, expect, expectDate, status); + } + status = U_ZERO_ERROR; + { + UnicodeString expect = CharsToUnicodeString("\\u0E27\\u0E31\\u0E19\\u0E40\\u0E2A\\u0E32\\u0E23\\u0E4C\\u0E17\\u0E35\\u0E48" + " 8 \\u0E01\\u0E31\\u0e19\\u0e22\\u0e32\\u0e22\\u0e19 \\u0e04.\\u0e28. 2001"); + UDate expectDate = 999932400000.0; + Locale loc("th_TH_TRADITIONAL@calendar=gregorian"); + + simpleTest(loc, expect, expectDate, status); + } +#endif +} + + void IntlCalendarTest::TestJapaneseFormat() { Calendar *cal; UErrorCode status = U_ZERO_ERROR; diff --git a/icu4c/source/test/intltest/incaltst.h b/icu4c/source/test/intltest/incaltst.h index 81fd574e4b1..5319ae85c6d 100644 --- a/icu4c/source/test/intltest/incaltst.h +++ b/icu4c/source/test/intltest/incaltst.h @@ -27,6 +27,9 @@ public: void TestBuddhist(void); void TestBuddhistFormat(void); + void TestTaiwan(void); + void TestTaiwanFormat(void); + void TestJapanese(void); void TestJapaneseFormat(void); void TestJapanese3860(void);