From 398b2aafc08008d6cf22b3fbcba671bdc8d868f8 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Thu, 16 Aug 2007 18:40:18 +0000 Subject: [PATCH] ICU-4567 taiwan calendar for C/C++ X-SVN-Rev: 22403 --- icu4c/source/data/locales/ja.txt | 1 + icu4c/source/data/locales/ko.txt | 1 + icu4c/source/data/locales/root.txt | 3 +- icu4c/source/data/locales/zh.txt | 1 + icu4c/source/data/locales/zh_Hant.txt | 1 + icu4c/source/data/xml/main/ja.xml | 5 +- icu4c/source/data/xml/main/ko.xml | 5 +- icu4c/source/data/xml/main/root.xml | 4 +- icu4c/source/data/xml/main/zh.xml | 5 +- icu4c/source/data/xml/main/zh_Hant.xml | 5 +- icu4c/source/i18n/taiwncal.cpp | 40 ++++++--- icu4c/source/i18n/taiwncal.h | 7 +- icu4c/source/test/intltest/incaltst.cpp | 91 ++------------------- icu4c/source/test/intltest/incaltst.h | 1 - icu4c/source/test/testdata/calendar.txt | 31 ++++--- icu4c/source/test/testdata/format.txt | 11 ++- icu4c/source/test/testdata/structLocale.txt | 1 + 17 files changed, 84 insertions(+), 129 deletions(-) diff --git a/icu4c/source/data/locales/ja.txt b/icu4c/source/data/locales/ja.txt index a041de1787..7eeb0246c0 100644 --- a/icu4c/source/data/locales/ja.txt +++ b/icu4c/source/data/locales/ja.txt @@ -2422,6 +2422,7 @@ ja{ } eras{ abbreviated{ + "民国前", "民国", } } diff --git a/icu4c/source/data/locales/ko.txt b/icu4c/source/data/locales/ko.txt index de41cd9c34..0a8701de4b 100644 --- a/icu4c/source/data/locales/ko.txt +++ b/icu4c/source/data/locales/ko.txt @@ -2117,6 +2117,7 @@ ko{ } eras{ abbreviated{ + "중화민국전", "중화민국", } } diff --git a/icu4c/source/data/locales/root.txt b/icu4c/source/data/locales/root.txt index 2da723c3f8..2c9eb434a8 100644 --- a/icu4c/source/data/locales/root.txt +++ b/icu4c/source/data/locales/root.txt @@ -1206,7 +1206,8 @@ root{ dayNames:alias{"/LOCALE/calendar/gregorian/dayNames"} eras{ abbreviated{ - "míngúo", + "Before Minguo", + "Minguo", } narrow:alias{"/LOCALE/calendar/taiwan/eras/abbreviated"} wide:alias{"/LOCALE/calendar/taiwan/eras/abbreviated"} diff --git a/icu4c/source/data/locales/zh.txt b/icu4c/source/data/locales/zh.txt index 2aa792e049..5b7ede11ac 100644 --- a/icu4c/source/data/locales/zh.txt +++ b/icu4c/source/data/locales/zh.txt @@ -2198,6 +2198,7 @@ zh{ } eras{ abbreviated{ + "民国前", "民国", } } diff --git a/icu4c/source/data/locales/zh_Hant.txt b/icu4c/source/data/locales/zh_Hant.txt index cf07dd0adf..eb42778b99 100644 --- a/icu4c/source/data/locales/zh_Hant.txt +++ b/icu4c/source/data/locales/zh_Hant.txt @@ -1765,6 +1765,7 @@ zh_Hant{ } eras{ abbreviated{ + "民國前", "民國", } } diff --git a/icu4c/source/data/xml/main/ja.xml b/icu4c/source/data/xml/main/ja.xml index 8589efb579..999c670b5f 100644 --- a/icu4c/source/data/xml/main/ja.xml +++ b/icu4c/source/data/xml/main/ja.xml @@ -28,9 +28,8 @@ - - 民国 - + 民国前 + 民国 diff --git a/icu4c/source/data/xml/main/ko.xml b/icu4c/source/data/xml/main/ko.xml index ed90b412e0..54afd040f2 100644 --- a/icu4c/source/data/xml/main/ko.xml +++ b/icu4c/source/data/xml/main/ko.xml @@ -27,9 +27,8 @@ - - 중화민국 - + 중화민국전 + 중화민국 diff --git a/icu4c/source/data/xml/main/root.xml b/icu4c/source/data/xml/main/root.xml index 9cd9940093..ad4ab16cbf 100644 --- a/icu4c/source/data/xml/main/root.xml +++ b/icu4c/source/data/xml/main/root.xml @@ -52,8 +52,8 @@ - - míngúo + Before Minguo + Minguo diff --git a/icu4c/source/data/xml/main/zh.xml b/icu4c/source/data/xml/main/zh.xml index 6d55364371..c573929684 100644 --- a/icu4c/source/data/xml/main/zh.xml +++ b/icu4c/source/data/xml/main/zh.xml @@ -26,9 +26,8 @@ - - 民国 - + 民国前 + 民国 diff --git a/icu4c/source/data/xml/main/zh_Hant.xml b/icu4c/source/data/xml/main/zh_Hant.xml index b5826a94c6..3afb5be29d 100644 --- a/icu4c/source/data/xml/main/zh_Hant.xml +++ b/icu4c/source/data/xml/main/zh_Hant.xml @@ -28,9 +28,8 @@ - - 民國 - + 民國前 + 民國 diff --git a/icu4c/source/i18n/taiwncal.cpp b/icu4c/source/i18n/taiwncal.cpp index 666e3e67f4..856525ab00 100644 --- a/icu4c/source/i18n/taiwncal.cpp +++ b/icu4c/source/i18n/taiwncal.cpp @@ -25,7 +25,7 @@ U_NAMESPACE_BEGIN UOBJECT_DEFINE_RTTI_IMPLEMENTATION(TaiwanCalendar) -static const int32_t kMaxEra = 0; // only 1 era +static const int32_t kMaxEra = 1; // 1 eras static const int32_t kTaiwanEraStart = 1911; // 1911 (Gregorian) @@ -105,23 +105,34 @@ int32_t TaiwanCalendar::internalGetEra() const int32_t TaiwanCalendar::getGregorianYear(UErrorCode &status) const { - int32_t year = (fStamp[UCAL_YEAR] != kUnset) ? internalGet(UCAL_YEAR) : kGregorianEpoch+kTaiwanEraStart; int32_t era = internalGetEra(); - if (era != MINGUO) { + + int32_t year = 1; + if(fStamp[UCAL_YEAR] != kUnset) { + year = internalGet(UCAL_YEAR, 1); + } + if(era == MINGUO) { + return kTaiwanEraStart + year; + } else if(era == BEFORE_MINGUO) { + return kTaiwanEraStart - year; + } else { status = U_ILLEGAL_ARGUMENT_ERROR; return kGregorianEpoch + kTaiwanEraStart; } - return year + kTaiwanEraStart; } int32_t TaiwanCalendar::handleGetExtendedYear() { - int32_t year; + int32_t year = 1; 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); + int32_t era = internalGetEra(); + if(era == MINGUO) { + year = internalGet(UCAL_YEAR, 1); + } else if(era == BEFORE_MINGUO) { + year = 1 - internalGet(UCAL_YEAR, 1); + } } return year; } @@ -138,14 +149,23 @@ 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); + if(y>0) { + internalSet(UCAL_ERA, MINGUO); + internalSet(UCAL_YEAR, y); + } else { + internalSet(UCAL_ERA, BEFORE_MINGUO); + internalSet(UCAL_YEAR, 1-y); + } } int32_t TaiwanCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const { if(field == UCAL_ERA) { - return MINGUO; + if(limitType == UCAL_LIMIT_MINIMUM || limitType == UCAL_LIMIT_GREATEST_MINIMUM) { + return BEFORE_MINGUO; + } else { + return MINGUO; + } } else { return GregorianCalendar::handleGetLimit(field,limitType); } diff --git a/icu4c/source/i18n/taiwncal.h b/icu4c/source/i18n/taiwncal.h index 9ed8f8319f..fdbc32ffb2 100644 --- a/icu4c/source/i18n/taiwncal.h +++ b/icu4c/source/i18n/taiwncal.h @@ -36,9 +36,7 @@ U_NAMESPACE_BEGIN * 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 two era: MINGUO. If the - * calendar is not in lenient mode (see setLenient), dates before - * 1/1/1 MINGUO are rejected as an illegal argument. + * The Taiwan Calendar has two eras: BEFORE_MINGUO and MINGUO. *

* @internal */ @@ -50,7 +48,8 @@ public: * @internal */ enum EEras { - MINGUO = 0 + BEFORE_MINGUO = 0, + MINGUO = 1 }; /** diff --git a/icu4c/source/test/intltest/incaltst.cpp b/icu4c/source/test/intltest/incaltst.cpp index 3942d3aad1..ecc7377ba3 100644 --- a/icu4c/source/test/intltest/incaltst.cpp +++ b/icu4c/source/test/intltest/incaltst.cpp @@ -78,7 +78,6 @@ void IntlCalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &n CASE(7,TestPersian); CASE(8,TestPersianFormat); CASE(9,TestTaiwan); - CASE(10,TestTaiwanFormat); default: name = ""; break; } } @@ -303,21 +302,22 @@ void IntlCalendarTest::TestBuddhist() { void IntlCalendarTest::TestTaiwan() { // MG 1 == 1912 AD UDate timeA = Calendar::getNow(); - + + // TODO port these to the data items int32_t data[] = { - 0, // B. era [928479600000] + 1, // B. era [928479600000] 1, // B. year 1912, // G. year UCAL_JUNE, // month 4, // day - 0, // B. era [-79204842000000] + 1, // B. era [-79204842000000] 3, // B. year 1914, // G. year UCAL_FEBRUARY, // month 12, // day - 0, // B. era [-79204842000000] + 1, // B. era [-79204842000000] 96, // B. year 2007, // G. year UCAL_FEBRUARY, // month @@ -475,86 +475,7 @@ 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 -} +// TaiwanFormat has been moved to testdata/format.txt void IntlCalendarTest::TestJapaneseFormat() { diff --git a/icu4c/source/test/intltest/incaltst.h b/icu4c/source/test/intltest/incaltst.h index 5319ae85c6..2c03ce3231 100644 --- a/icu4c/source/test/intltest/incaltst.h +++ b/icu4c/source/test/intltest/incaltst.h @@ -28,7 +28,6 @@ public: void TestBuddhistFormat(void); void TestTaiwan(void); - void TestTaiwanFormat(void); void TestJapanese(void); void TestJapaneseFormat(void); diff --git a/icu4c/source/test/testdata/calendar.txt b/icu4c/source/test/testdata/calendar.txt index c2106f064c..1d126213fb 100644 --- a/icu4c/source/test/testdata/calendar.txt +++ b/icu4c/source/test/testdata/calendar.txt @@ -25,19 +25,26 @@ calendar:table(nofallback) { Cases { { "en_US@calendar=taiwan", - "ERA=0,YEAR=1,MONTH=JUNE,DATE=4", // tw + "ERA=1,YEAR=1,MONTH=JUNE,DATE=4", // tw "ERA=1,YEAR=1912,MONTH=,DATE=" // greg }, { "en_US@calendar=taiwan", - "ERA=0,YEAR=3,MONTH=FEBRUARY,DATE=12", // tw + "ERA=1,YEAR=3,MONTH=FEBRUARY,DATE=12", // tw "ERA=1,YEAR=1914,MONTH=,DATE=" // greg }, { "en_US@calendar=taiwan", - "ERA=0,YEAR=96,MONTH=FEBRUARY,DATE=12", // tw + "ERA=1,YEAR=96,MONTH=FEBRUARY,DATE=12", // tw "ERA=1,YEAR=2007,MONTH=,DATE=" // greg }, + // before 1912: + // [before minguo]2 1[month] 24[day] -> 1910-1-24 + { + "en_US@calendar=taiwan", + "ERA=0,YEAR=2,MONTH=JANUARY,DATE=24", // tw + "ERA=1,YEAR=1910,MONTH=JANUARY,DATE=24", // greg + } } } TestCalendarOperations { @@ -53,33 +60,33 @@ calendar:table(nofallback) { Cases { { "en_US@calendar=taiwan", - "ERA=0,YEAR=1,MONTH=JUNE,DATE=4", // tw + "ERA=1,YEAR=1,MONTH=JUNE,DATE=4", // tw "roll", "DATE=1", // date + 1 - "ERA=0,YEAR=1,MONTH=JUNE,DATE=5", // tw + "ERA=1,YEAR=1,MONTH=JUNE,DATE=5", // tw }, { "en_US@calendar=taiwan", - "ERA=0,YEAR=1,MONTH=JUNE,DATE=4", // tw + "ERA=1,YEAR=1,MONTH=JUNE,DATE=4", // tw "add", "DATE=1", // date + 1 - "ERA=0,YEAR=1,MONTH=JUNE,DATE=5", // tw + "ERA=1,YEAR=1,MONTH=JUNE,DATE=5", // tw }, { "en_US@calendar=taiwan", - "ERA=0,YEAR=1,MONTH=JUNE,DATE=4", // tw + "ERA=1,YEAR=1,MONTH=JUNE,DATE=4", // tw "roll", "YEAR=1", // date + 1 - "ERA=0,YEAR=2,MONTH=JUNE,DATE=4", // tw + "ERA=1,YEAR=2,MONTH=JUNE,DATE=4", // tw }, { "en_US@calendar=taiwan", - "ERA=0,YEAR=1,MONTH=JUNE,DATE=4", // tw + "ERA=1,YEAR=1,MONTH=JUNE,DATE=4", // tw "add", "YEAR=1", // date + 1 - "ERA=0,YEAR=2,MONTH=JUNE,DATE=4", // tw + "ERA=1,YEAR=2,MONTH=JUNE,DATE=4", // tw }, - } + } } } } \ No newline at end of file diff --git a/icu4c/source/test/testdata/format.txt b/icu4c/source/test/testdata/format.txt index e992fbff56..9f2ef99c0f 100644 --- a/icu4c/source/test/testdata/format.txt +++ b/icu4c/source/test/testdata/format.txt @@ -34,10 +34,17 @@ format:table(nofallback) { { "zh_TW@calendar=taiwan", "DATE=LONG", - "ERA=0,YEAR=98,MONTH=0,DATE=24", + "ERA=1,YEAR=98,MONTH=0,DATE=24", "民國98年1月24日", }, + { + //民國前2年1月24日 -> 1910-1-24 + "zh_TW@calendar=taiwan", + "DATE=LONG", + "ERA=0,YEAR=2,MONTH=0,DATE=24", + "民國前2年1月24日", + }, } } } -} \ No newline at end of file +} diff --git a/icu4c/source/test/testdata/structLocale.txt b/icu4c/source/test/testdata/structLocale.txt index e80be9e6c7..408a90536f 100644 --- a/icu4c/source/test/testdata/structLocale.txt +++ b/icu4c/source/test/testdata/structLocale.txt @@ -3220,6 +3220,7 @@ structLocale:table(nofallback){ eras{ abbreviated{ "", + "", } wide{ "",