ICU-4567 taiwan calendar for C/C++

X-SVN-Rev: 22403
This commit is contained in:
Steven R. Loomis 2007-08-16 18:40:18 +00:00
parent 07f488201c
commit 398b2aafc0
17 changed files with 84 additions and 129 deletions

View File

@ -2422,6 +2422,7 @@ ja{
}
eras{
abbreviated{
"民国前",
"民国",
}
}

View File

@ -2117,6 +2117,7 @@ ko{
}
eras{
abbreviated{
"중화민국전",
"중화민국",
}
}

View File

@ -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"}

View File

@ -2198,6 +2198,7 @@ zh{
}
eras{
abbreviated{
"民国前",
"民国",
}
}

View File

@ -1765,6 +1765,7 @@ zh_Hant{
}
eras{
abbreviated{
"民國前",
"民國",
}
}

View File

@ -28,9 +28,8 @@
<calendar type="taiwan">
<eras>
<eraAbbr>
<!-- pre-minguo: 民国前 -->
<era type="0">民国</era>
<!-- = 1912 AD gregorian. See: http://en.wikipedia.org/wiki/Minguo_calendar -->
<era type="0">民国前</era>
<era type="1">民国</era>
</eraAbbr>
</eras>
<dateFormats>

View File

@ -27,9 +27,8 @@
<calendar type="taiwan">
<eras>
<eraAbbr>
<!-- pre-minguo: 중화민국전 -->
<era type="0">중화민국</era>
<!-- = 1912 AD gregorian. See: http://en.wikipedia.org/wiki/Minguo_calendar -->
<era type="0">중화민국전</era>
<era type="1">중화민국</era>
</eraAbbr>
</eras>
<dateFormats>

View File

@ -52,8 +52,8 @@
<alias source="locale" path="../eraAbbr"/>
</eraNames>
<eraAbbr>
<!-- type="-1" 'before míngúo' -->
<era type="0">míngúo</era>
<era type="0">Before Minguo</era>
<era type="1">Minguo</era>
<!-- = 1912 AD gregorian. See: http://en.wikipedia.org/wiki/Minguo_calendar -->
</eraAbbr>
<eraNarrow>

View File

@ -26,9 +26,8 @@
<calendar type="taiwan">
<eras>
<eraAbbr>
<!-- pre-minguo: 民国前 -->
<era type="0">民国</era>
<!-- = 1912 AD gregorian. See: http://en.wikipedia.org/wiki/Minguo_calendar -->
<era type="0">民国前</era>
<era type="1">民国</era>
</eraAbbr>
</eras>
<dateFormats>

View File

@ -28,9 +28,8 @@
<calendar type="taiwan">
<eras>
<eraAbbr>
<!-- pre-minguo: 民國前 -->
<era type="0">民國</era>
<!-- = 1912 AD gregorian. See: http://en.wikipedia.org/wiki/Minguo_calendar -->
<era type="0">民國前</era>
<era type="1">民國</era>
</eraAbbr>
</eras>
<dateFormats>

View File

@ -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);
}

View File

@ -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.
* <p>
* The Taiwan Calendar has two era: <code>MINGUO</code>. If the
* calendar is not in lenient mode (see <code>setLenient</code>), dates before
* 1/1/1 MINGUO are rejected as an illegal argument.
* The Taiwan Calendar has two eras: <code>BEFORE_MINGUO</code> and <code>MINGUO</code>.
* <p>
* @internal
*/
@ -50,7 +48,8 @@ public:
* @internal
*/
enum EEras {
MINGUO = 0
BEFORE_MINGUO = 0,
MINGUO = 1
};
/**

View File

@ -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() {

View File

@ -28,7 +28,6 @@ public:
void TestBuddhistFormat(void);
void TestTaiwan(void);
void TestTaiwanFormat(void);
void TestJapanese(void);
void TestJapaneseFormat(void);

View File

@ -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
},
}
}
}
}
}

View File

@ -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日",
},
}
}
}
}
}

View File

@ -3220,6 +3220,7 @@ structLocale:table(nofallback){
eras{
abbreviated{
"",
"",
}
wide{
"",