ICU-4571 Updated EthiopicCalendar's constructor to specify era mode. New calendar keyword ethiopic-amete-alem to create an instance of EthiopicCalendar with Amete Alem era only. Modified the test case to cover ethiopic-amete-alem.

X-SVN-Rev: 23665
This commit is contained in:
Yoshito Umaoka 2008-03-24 22:21:21 +00:00
parent 308a2aa0b5
commit 9971f8f5f5
4 changed files with 43 additions and 12 deletions

View File

@ -148,6 +148,7 @@ static const char * const gCalendarKeywords[] = {
"indian",
"coptic",
"ethiopic",
"ethiopic-amete-alem",
NULL
};
@ -209,7 +210,9 @@ static Calendar *createStandardCalendar(char *calType, const Locale &canLoc, UEr
} else if(!uprv_strcmp(calType, "coptic")) {
return new CopticCalendar(canLoc, status);
} else if(!uprv_strcmp(calType, "ethiopic")) {
return new EthiopicCalendar(canLoc, status);
return new EthiopicCalendar(canLoc, status, EthiopicCalendar::AMETE_MIHRET_ERA);
} else if(!uprv_strcmp(calType, "ethiopic-amete-alem")) {
return new EthiopicCalendar(canLoc, status, EthiopicCalendar::AMETE_ALEM_ERA);
} else {
status = U_UNSUPPORTED_ERROR;
return NULL;

View File

@ -26,15 +26,17 @@ static const int32_t AMETE_MIHRET_DELTA = 5500; // 5501 - 1 (Amete Alem 5501 = A
// Constructors...
//-------------------------------------------------------------------------
EthiopicCalendar::EthiopicCalendar(const Locale& aLocale, UErrorCode& success)
EthiopicCalendar::EthiopicCalendar(const Locale& aLocale,
UErrorCode& success,
EEraType type /*= AMETE_MIHRET_ERA*/)
: CECalendar(aLocale, success),
isAmeteAlem(FALSE)
eraType(type)
{
}
EthiopicCalendar::EthiopicCalendar(const EthiopicCalendar& other)
: CECalendar(other),
isAmeteAlem(other.isAmeteAlem)
eraType(other.eraType)
{
}
@ -52,7 +54,7 @@ const char *
EthiopicCalendar::getType() const
{
if (isAmeteAlemEra()) {
return "ethiopic_aa";
return "ethiopic-amete-alem";
}
return "ethiopic";
}
@ -60,13 +62,13 @@ EthiopicCalendar::getType() const
void
EthiopicCalendar::setAmeteAlemEra(UBool onOff)
{
isAmeteAlem = onOff;
eraType = onOff ? AMETE_ALEM_ERA : AMETE_MIHRET_ERA;
}
UBool
EthiopicCalendar::isAmeteAlemEra() const
{
return isAmeteAlem;
return (eraType == AMETE_ALEM_ERA);
}
//-------------------------------------------------------------------------

View File

@ -24,6 +24,15 @@ U_NAMESPACE_BEGIN
class EthiopicCalendar : public CECalendar {
public:
/**
* Calendar type - use Amete Alem era for all the time or not
* @internal
*/
enum EEraType {
AMETE_MIHRET_ERA,
AMETE_ALEM_ERA
};
/**
* Useful constants for EthiopicCalendar.
* @internal
@ -107,9 +116,11 @@ public:
* @param aLocale The given locale.
* @param success Indicates the status of EthiopicCalendar object construction.
* Returns U_ZERO_ERROR if constructed successfully.
* @param type Whether this Ethiopic calendar use Amete Mihrret (default) or
* only use Amete Alem for all the time.
* @internal
*/
EthiopicCalendar(const Locale& aLocale, UErrorCode& success);
EthiopicCalendar(const Locale& aLocale, UErrorCode& success, EEraType type = AMETE_MIHRET_ERA);
/**
* Copy Constructor
@ -225,15 +236,15 @@ private:
static void initializeSystemDefaultCentury(void);
/**
* When isAmeteAlem is true, then this calendar use only AMETE_ALEM
* When eraType is AMETE_ALEM_ERA, then this calendar use only AMETE_ALEM
* for the era. Otherwise (default), this calendar uses both AMETE_ALEM
* and AMETE_MIHRET.
*
* EXTENDED_YEAR isAmeteAlem(false) isAmeteAlem(true)
* EXTENDED_YEAR AMETE_ALEM_ERA AMETE_MIHRET_ERA
* 0 Amete Alem 5500 Amete Alem 5500
* 1 Amete Mihret 1 Amete Alem 5501
*/
UBool isAmeteAlem;
EEraType eraType;
public:
/**

View File

@ -430,7 +430,7 @@ void CalendarCaseTest::Coptic() {
}
void CalendarCaseTest::Ethiopic() {
static const TestCase tests[] = {
static TestCase tests[] = {
// JD Era Year Month Day WkDay Hour Min Sec
{2401442.5, 1, 1855, 2, 20, WED, 0, 0, 0}, // Gregorian: 29/10/1862
{2402422.5, 1, 1857, 10, 29, WED, 0, 0, 0}, // Gregorian: 05/07/1865
@ -474,6 +474,21 @@ void CalendarCaseTest::Ethiopic() {
doTestCases(tests, c);
delete c;
// Testing Amete Alem mode
int32_t i;
TestCase *tcase = tests;
for (i = 0; tcase[i].era >= 0; i++) {
if (tcase[i].era == 1) {
tcase[i].era = 0; // Change to Amete Alem era
tcase[i].year += 5500; // Amete Mihret 1 = Amete Alem 5501
}
}
c = Calendar::createInstance("am_ET@calendar=ethiopic-amete-alem", status);
c->setLenient(TRUE);
doTestCases(tests, c);
delete c;
}