ICU-4567 Updated TaiwanCalendar to use a Gregorian year in EXTENDED_YEAR. As a result, some override methods are no longer required. Also, use 1970 as the default value of EXTENDED_YEAR in all GregorianCalendar subclasses

X-SVN-Rev: 22411
This commit is contained in:
Yoshito Umaoka 2007-08-16 22:10:16 +00:00
parent 14200e84ea
commit f7f687e073
5 changed files with 21 additions and 193 deletions

View file

@ -28,6 +28,8 @@ static const int32_t kMaxEra = 0; // only 1 era
static const int32_t kBuddhistEraStart = -543; // 544 BC (Gregorian)
static const int32_t kGregorianEpoch = 1970; // used as the default value of EXTENDED_YEAR
BuddhistCalendar::BuddhistCalendar(const Locale& aLocale, UErrorCode& success)
: GregorianCalendar(aLocale, success)
{
@ -81,13 +83,15 @@ BuddhistCalendar::getLeastMaximum(UCalendarDateFields field) const
int32_t BuddhistCalendar::handleGetExtendedYear()
{
// EXTENDED_YEAR in BuddhistCalendar is a Gregorian year.
// The default value of EXTENDED_YEAR is 1970 (Buddhist 2513)
int32_t year;
if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
year = internalGet(UCAL_EXTENDED_YEAR, 1);
year = internalGet(UCAL_EXTENDED_YEAR, kGregorianEpoch);
} else {
// extended year is a gregorian year, where 1 = 1AD, 0 = 1BC, -1 = 2BC, etc
year = internalGet(UCAL_YEAR, 1) // pin to minimum of year 1 (first year)
+ kBuddhistEraStart; // add gregorian starting year
year = internalGet(UCAL_YEAR, kGregorianEpoch - kBuddhistEraStart)
+ kBuddhistEraStart;
}
return year;
}
@ -140,28 +144,6 @@ void BuddhistCalendar::timeToFields(UDate theTime, UBool quick, UErrorCode& stat
}
#endif
void BuddhistCalendar::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 BuddhistCalendar::fgSystemDefaultCentury = DBL_MIN;
const int32_t BuddhistCalendar::fgSystemDefaultCenturyYear = -1;

View file

@ -128,20 +128,6 @@ public:
*/
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.
@ -162,19 +148,6 @@ public:
*/
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:
BuddhistCalendar(); // default constructor not implemented

View file

@ -280,6 +280,8 @@ static const struct {
static const uint32_t kCurrentEra = (kEraCount-1);
static const int32_t kGregorianEpoch = 1970; // used as the default value of EXTENDED_YEAR
/* Some platforms don't like to export constants, like old Palm OS and some z/OS configurations. */
uint32_t JapaneseCalendar::getCurrentEra() {
return kCurrentEra;
@ -361,17 +363,18 @@ int32_t JapaneseCalendar::internalGetEra() const
int32_t JapaneseCalendar::handleGetExtendedYear()
{
// EXTENDED_YEAR in JapaneseCalendar is a Gregorian year
// The default value of EXTENDED_YEAR is 1970 (Showa 45)
int32_t year;
if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR &&
newerField(UCAL_EXTENDED_YEAR, UCAL_ERA) == UCAL_EXTENDED_YEAR) {
year = internalGet(UCAL_EXTENDED_YEAR, 1);
year = internalGet(UCAL_EXTENDED_YEAR, kGregorianEpoch);
} else {
// Subtract one because year starts at 1
year = internalGet(UCAL_YEAR) + kEraInfo[internalGetEra()].year - 1;
}
return year;
}

View file

@ -82,73 +82,30 @@ TaiwanCalendar::getLeastMaximum(UCalendarDateFields field) const
}
}
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 era = internalGetEra();
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;
}
}
int32_t TaiwanCalendar::handleGetExtendedYear()
{
int32_t year = 1;
if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
year = internalGet(UCAL_EXTENDED_YEAR, 1);
// EXTENDED_YEAR in TaiwanCalendar is a Gregorian year
// The default value of EXTENDED_YEAR is 1970 (Minguo 59)
int32_t year = kGregorianEpoch;
if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR
&& newerField(UCAL_EXTENDED_YEAR, UCAL_ERA) == UCAL_EXTENDED_YEAR) {
year = internalGet(UCAL_EXTENDED_YEAR, kGregorianEpoch);
} else {
int32_t era = internalGetEra();
if(era == MINGUO) {
year = internalGet(UCAL_YEAR, 1);
year = internalGet(UCAL_YEAR, 1) + kTaiwanEraStart;
} else if(era == BEFORE_MINGUO) {
year = 1 - internalGet(UCAL_YEAR, 1);
year = 1 - internalGet(UCAL_YEAR, 1) + kTaiwanEraStart;
}
}
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);
if(y>0) {
internalSet(UCAL_ERA, MINGUO);
internalSet(UCAL_YEAR, y);
@ -195,28 +152,6 @@ void TaiwanCalendar::timeToFields(UDate theTime, UBool quick, UErrorCode& status
}
#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;

View file

@ -125,20 +125,6 @@ public:
*/
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.
@ -159,19 +145,6 @@ public:
*/
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
@ -199,44 +172,6 @@ private:
* @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