mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-2436 international calendars (Buddhist)
X-SVN-Rev: 11975
This commit is contained in:
parent
73a3d184bb
commit
0dfe4a433d
10 changed files with 472 additions and 66 deletions
|
@ -55,6 +55,7 @@ OBJECTS = ucln_in.o \
|
|||
fmtable.o format.o msgfmt.o umsg.o numfmt.o unum.o decimfmt.o dcfmtsym.o \
|
||||
choicfmt.o datefmt.o smpdtfmt.o dtfmtsym.o udat.o \
|
||||
ucal.o calendar.o gregocal.o timezone.o simpletz.o \
|
||||
buddhcal.o \
|
||||
sortkey.o bocsu.o coleitr.o coll.o ucoleitr.o \
|
||||
ucol.o ucol_bld.o ucol_cnt.o ucol_elm.o ucol_tok.o ucol_wgt.o tblcoll.o \
|
||||
strmatch.o usearch.o search.o stsearch.o \
|
||||
|
|
151
icu4c/source/i18n/buddhcal.cpp
Normal file
151
icu4c/source/i18n/buddhcal.cpp
Normal file
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2003, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* File BUDDHCAL.CPP
|
||||
*
|
||||
* Modification History:
|
||||
* 05/13/2003 srl copied from gregocal.cpp
|
||||
*
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#if !UCONFIG_NO_FORMATTING
|
||||
|
||||
#include "buddhcal.h"
|
||||
#include "unicode/gregocal.h"
|
||||
|
||||
|
||||
U_NAMESPACE_BEGIN
|
||||
|
||||
const char BuddhistCalendar::fgClassID = 0; // Value is irrelevant
|
||||
|
||||
static const int32_t kMaxEra = 0; // only 1 era
|
||||
|
||||
static const int32_t kBuddhistEraStart = -543; // 544 BC (Gregorian)
|
||||
|
||||
BuddhistCalendar::BuddhistCalendar(const Locale& aLocale, UErrorCode& success)
|
||||
: GregorianCalendar(aLocale, success)
|
||||
{
|
||||
}
|
||||
|
||||
BuddhistCalendar::~BuddhistCalendar()
|
||||
{
|
||||
}
|
||||
|
||||
BuddhistCalendar::BuddhistCalendar(const BuddhistCalendar& source)
|
||||
: GregorianCalendar(source)
|
||||
{
|
||||
}
|
||||
|
||||
BuddhistCalendar& BuddhistCalendar::operator= ( const BuddhistCalendar& right)
|
||||
{
|
||||
GregorianCalendar::operator=(right);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Calendar* BuddhistCalendar::clone(void) const
|
||||
{
|
||||
return new BuddhistCalendar(*this);
|
||||
}
|
||||
|
||||
const char *BuddhistCalendar::getType() const
|
||||
{
|
||||
return "buddhist";
|
||||
}
|
||||
|
||||
int32_t
|
||||
BuddhistCalendar::getMaximum(UCalendarDateFields field) const
|
||||
{
|
||||
if(field == UCAL_ERA) {
|
||||
return kMaxEra;
|
||||
} else {
|
||||
return GregorianCalendar::getMaximum(field);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t
|
||||
BuddhistCalendar::getLeastMaximum(UCalendarDateFields field) const
|
||||
{
|
||||
if(field == UCAL_ERA) {
|
||||
return kMaxEra;
|
||||
} else {
|
||||
return GregorianCalendar::getLeastMaximum(field);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t
|
||||
BuddhistCalendar::monthLength(int32_t month, int32_t year) const
|
||||
{
|
||||
return GregorianCalendar::monthLength(month,year);
|
||||
}
|
||||
|
||||
|
||||
int32_t
|
||||
BuddhistCalendar::monthLength(int32_t month) const
|
||||
{
|
||||
int32_t year = internalGet(UCAL_YEAR);
|
||||
// ignore era
|
||||
return monthLength(month, year);
|
||||
}
|
||||
|
||||
#if 0
|
||||
UBool
|
||||
BuddhistCalendar::isLeapYear(int32_t year) const
|
||||
{
|
||||
return (year >= fGregorianCutoverYear ?
|
||||
((year%4 == 0) && ((year%100 != 0) || (year%400 == 0))) : // Gregorian
|
||||
(year%4 == 0)); // Julian
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t BuddhistCalendar::internalGetEra() const
|
||||
{
|
||||
return isSet(UCAL_ERA) ? internalGet(UCAL_ERA) : BE;
|
||||
}
|
||||
|
||||
int32_t
|
||||
BuddhistCalendar::getGregorianYear(UErrorCode &status)
|
||||
{
|
||||
int32_t year = (fStamp[UCAL_YEAR] != kUnset) ? internalGet(UCAL_YEAR) : 1970+kBuddhistEraStart;
|
||||
int32_t era = BE;
|
||||
if (fStamp[UCAL_ERA] != kUnset) {
|
||||
era = internalGet(UCAL_ERA);
|
||||
if (era != BE) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return 1970 + kBuddhistEraStart;
|
||||
}
|
||||
}
|
||||
return year + kBuddhistEraStart;
|
||||
}
|
||||
|
||||
void BuddhistCalendar::timeToFields(UDate theTime, UBool quick, UErrorCode& status)
|
||||
{
|
||||
GregorianCalendar::timeToFields(theTime, quick, status);
|
||||
|
||||
int32_t era = internalGet(UCAL_ERA);
|
||||
int32_t year = internalGet(UCAL_YEAR);
|
||||
|
||||
if(era == GregorianCalendar::BC) {
|
||||
year = 1-year;
|
||||
era = BuddhistCalendar::BE;
|
||||
} else if(era == GregorianCalendar::AD) {
|
||||
era = BuddhistCalendar::BE;
|
||||
} else {
|
||||
status = U_INTERNAL_PROGRAM_ERROR;
|
||||
}
|
||||
|
||||
year = year - kBuddhistEraStart;
|
||||
|
||||
internalSet(UCAL_ERA, era);
|
||||
internalSet(UCAL_YEAR, year);
|
||||
}
|
||||
|
||||
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif
|
150
icu4c/source/i18n/buddhcal.h
Normal file
150
icu4c/source/i18n/buddhcal.h
Normal file
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright (C) 2003, 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
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef BUDDHCAL_H
|
||||
#define BUDDHCAL_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 Buddhist calendar.
|
||||
* <P>
|
||||
* <i>(stuff pasted here from java)
|
||||
* <p>
|
||||
* @internal
|
||||
*/
|
||||
class U_I18N_API BuddhistCalendar : public GregorianCalendar {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Useful constants for BuddhistCalendar. Only one Era.
|
||||
* @internal
|
||||
*/
|
||||
enum EEras {
|
||||
BE
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a BuddhistCalendar 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 BuddhistCalendar object construction.
|
||||
* Returns U_ZERO_ERROR if constructed successfully.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
BuddhistCalendar(const Locale& aLocale, UErrorCode& success);
|
||||
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @internal
|
||||
*/
|
||||
virtual ~BuddhistCalendar();
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
* @param source the object to be copied.
|
||||
* @internal
|
||||
*/
|
||||
BuddhistCalendar(const BuddhistCalendar& source);
|
||||
|
||||
/**
|
||||
* Default assignment operator
|
||||
* @param right the object to be copied.
|
||||
* @internal
|
||||
*/
|
||||
BuddhistCalendar& operator=(const BuddhistCalendar& 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
|
||||
*/
|
||||
static inline UClassID getStaticClassID(void);
|
||||
|
||||
/**
|
||||
* return the calendar type, "gregorian".
|
||||
*
|
||||
* @return calendar type
|
||||
* @internal
|
||||
*/
|
||||
virtual const char * getType() const;
|
||||
|
||||
private:
|
||||
BuddhistCalendar(); // default constructor not implemented
|
||||
|
||||
static const char fgClassID;
|
||||
|
||||
protected:
|
||||
virtual int32_t monthLength(int32_t month) const;
|
||||
virtual int32_t monthLength(int32_t month, int32_t year) const;
|
||||
int32_t getGregorianYear(UErrorCode& status);
|
||||
int32_t getMaximum(UCalendarDateFields field) const;
|
||||
int32_t getLeastMaximum(UCalendarDateFields field) const;
|
||||
virtual int32_t internalGetEra() const;
|
||||
virtual void timeToFields(UDate theTime, UBool quick, UErrorCode& status);
|
||||
};
|
||||
|
||||
inline UClassID
|
||||
BuddhistCalendar::getStaticClassID(void)
|
||||
{ return (UClassID)&fgClassID; }
|
||||
|
||||
inline UClassID
|
||||
BuddhistCalendar::getDynamicClassID(void) const
|
||||
{ return BuddhistCalendar::getStaticClassID(); }
|
||||
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
#endif // _GREGOCAL
|
||||
//eof
|
||||
|
|
@ -30,9 +30,7 @@
|
|||
|
||||
#include "unicode/resbund.h"
|
||||
#include "unicode/gregocal.h"
|
||||
#ifdef U_ENABLE_INTL_CALENDARS
|
||||
# include "buddhcal.h"
|
||||
#endif
|
||||
#include "buddhcal.h"
|
||||
#include "unicode/calendar.h"
|
||||
#include "cpputils.h"
|
||||
#include "iculserv.h"
|
||||
|
@ -45,7 +43,7 @@ U_NAMESPACE_BEGIN
|
|||
//
|
||||
//-------------------------------------------
|
||||
//#define U_DEBUG_CALSVC 1
|
||||
//#define U_ENABLE_INTL_CALENDARS [disabled for now]
|
||||
//
|
||||
|
||||
#ifdef U_DEBUG_CALSVC
|
||||
#include <stdio.h>
|
||||
|
@ -115,14 +113,12 @@ protected:
|
|||
|
||||
if(!fType || !*fType || !strcmp(fType,"gregorian")) { // Gregorian (default)
|
||||
return new GregorianCalendar(canLoc, status);
|
||||
#ifdef U_ENABLE_INTL_CALENDARS
|
||||
# if 0
|
||||
} else if(!strcmp(fType, "japanese")) {
|
||||
return new JapaneseCalendar(loc, status);
|
||||
# endif
|
||||
#endif
|
||||
} else if(!strcmp(fType, "buddhist")) {
|
||||
return new BuddhistCalendar(canLoc, status);
|
||||
#endif
|
||||
} else {
|
||||
status = U_UNSUPPORTED_ERROR;
|
||||
return NULL;
|
||||
|
@ -265,10 +261,8 @@ getService(void)
|
|||
#endif
|
||||
|
||||
// Register all basic instances.
|
||||
#ifdef U_ENABLE_INTL_CALENDARS
|
||||
newservice->registerFactory(new BasicCalendarFactory("japanese"),status);
|
||||
newservice->registerFactory(new BasicCalendarFactory("buddhist"),status);
|
||||
#endif
|
||||
newservice->registerFactory(new BasicCalendarFactory("gregorian"),status);
|
||||
|
||||
#ifdef U_DEBUG_CALSVC
|
||||
|
@ -1177,9 +1171,6 @@ Calendar::updateTime(UErrorCode& status)
|
|||
|
||||
U_NAMESPACE_END
|
||||
|
||||
extern "C" void calLoadSvc() {
|
||||
getService();
|
||||
}
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "ucln_in.h"
|
||||
#include "mutex.h"
|
||||
#include "cmemory.h"
|
||||
#include "cstring.h"
|
||||
|
||||
// *****************************************************************************
|
||||
// class DateFormatSymbols
|
||||
|
@ -535,13 +536,40 @@ DateFormatSymbols::initField(UnicodeString **field, int32_t& length, const UChar
|
|||
}
|
||||
|
||||
ResourceBundle
|
||||
DateFormatSymbols::getData(ResourceBundle &rb, const char *tag, const char * /*type*/, UErrorCode& status )
|
||||
DateFormatSymbols::getData(ResourceBundle &rb, const char *tag, const char *type, UErrorCode& status )
|
||||
{
|
||||
return rb.get(tag, status);
|
||||
char tmp[100];
|
||||
char *fullTag = tmp;
|
||||
|
||||
if(!type || !*type) {
|
||||
type = "gregorian";
|
||||
}
|
||||
|
||||
int32_t len = uprv_strlen(tag) + 1 + uprv_strlen(type); // tag + _ + type (i.e. Eras_Japanese )
|
||||
if(len > 100) {
|
||||
fullTag = (char*)uprv_malloc(len+1);
|
||||
}
|
||||
|
||||
uprv_strcpy(fullTag, tag);
|
||||
uprv_strcat(fullTag, "_");
|
||||
uprv_strcat(fullTag, type);
|
||||
|
||||
ResourceBundle resource = rb.get(fullTag, status);
|
||||
|
||||
if(status == U_MISSING_RESOURCE_ERROR) {
|
||||
status = U_ZERO_ERROR;
|
||||
resource = rb.get(tag, status);
|
||||
}
|
||||
|
||||
if(fullTag != tmp) {
|
||||
delete fullTag; // not stack allocated
|
||||
}
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
void
|
||||
DateFormatSymbols::initializeData(const Locale& locale, const char * /* type */, UErrorCode& status, UBool useLastResortData)
|
||||
DateFormatSymbols::initializeData(const Locale& locale, const char *type, UErrorCode& status, UBool useLastResortData)
|
||||
{
|
||||
int32_t i;
|
||||
|
||||
|
@ -600,10 +628,10 @@ DateFormatSymbols::initializeData(const Locale& locale, const char * /* type */,
|
|||
// if we make it to here, the resource data is cool, and we can get everything out
|
||||
// of it that we need except for the time-zone and localized-pattern data, which
|
||||
// are stoerd in a separate file
|
||||
initField(&fEras, fErasCount, resource.get(fgErasTag, status), status);
|
||||
initField(&fMonths, fMonthsCount, resource.get(fgMonthNamesTag, status), status);
|
||||
initField(&fShortMonths, fShortMonthsCount, resource.get(fgMonthAbbreviationsTag, status), status);
|
||||
initField(&fAmPms, fAmPmsCount, resource.get(fgAmPmMarkersTag, status), status);
|
||||
initField(&fEras, fErasCount, getData(resource, fgErasTag, type, status), status);
|
||||
initField(&fMonths, fMonthsCount, getData(resource, fgMonthNamesTag, type, status), status);
|
||||
initField(&fShortMonths, fShortMonthsCount, getData(resource, fgMonthAbbreviationsTag, type, status), status);
|
||||
initField(&fAmPms, fAmPmsCount, getData(resource, fgAmPmMarkersTag, type, status), status);
|
||||
// fastCopyFrom() - see assignArray comments
|
||||
fLocalPatternChars.fastCopyFrom(resource.getStringEx(fgLocalPatternCharsTag, status));
|
||||
|
||||
|
@ -633,7 +661,7 @@ DateFormatSymbols::initializeData(const Locale& locale, const char * /* type */,
|
|||
}
|
||||
|
||||
// {sfb} fixed to handle 1-based weekdays
|
||||
ResourceBundle weekdaysData = resource.get(fgDayNamesTag, status);
|
||||
ResourceBundle weekdaysData = getData(resource, fgDayNamesTag, type, status);
|
||||
fWeekdaysCount = weekdaysData.getSize();
|
||||
fWeekdays = new UnicodeString[fWeekdaysCount+1];
|
||||
/* test for NULL */
|
||||
|
@ -647,7 +675,7 @@ DateFormatSymbols::initializeData(const Locale& locale, const char * /* type */,
|
|||
fWeekdays[i+1].fastCopyFrom(weekdaysData.getStringEx(i, status));
|
||||
}
|
||||
|
||||
ResourceBundle lsweekdaysData = resource.get(fgDayAbbreviationsTag, status);
|
||||
ResourceBundle lsweekdaysData = getData(resource, fgDayAbbreviationsTag, type, status);
|
||||
fShortWeekdaysCount = lsweekdaysData.getSize();
|
||||
fShortWeekdays = new UnicodeString[fShortWeekdaysCount+1];
|
||||
/* test for NULL */
|
||||
|
|
|
@ -647,7 +647,8 @@ GregorianCalendar::computeFields(UErrorCode& status)
|
|||
|
||||
// Call getOffset() to get the TimeZone offset. The millisInDay value must
|
||||
// be standard local millis.
|
||||
int32_t dstOffset = getTimeZone().getOffset(era, year, month, date, dayOfWeek, millisInDay,
|
||||
int32_t gregoYear = getGregorianYear(status);
|
||||
int32_t dstOffset = getTimeZone().getOffset((gregoYear>0?AD:BC), getGregorianYear(status), month, date, dayOfWeek, millisInDay,
|
||||
monthLength(month), status) - rawOffset;
|
||||
if(U_FAILURE(status))
|
||||
return;
|
||||
|
@ -778,6 +779,24 @@ GregorianCalendar::getEpochDay(UErrorCode& status)
|
|||
|
||||
// -------------------------------------
|
||||
|
||||
int32_t
|
||||
GregorianCalendar::getGregorianYear(UErrorCode &status)
|
||||
{
|
||||
int32_t year = (fStamp[UCAL_YEAR] != kUnset) ? internalGet(UCAL_YEAR) : kEpochYear;
|
||||
int32_t era = AD;
|
||||
if (fStamp[UCAL_ERA] != kUnset) {
|
||||
era = internalGet(UCAL_ERA);
|
||||
if (era == BC)
|
||||
year = 1 - year;
|
||||
// Even in lenient mode we disallow ERA values other than AD & BC
|
||||
else if (era != AD) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return kEpochYear;
|
||||
}
|
||||
}
|
||||
return year;
|
||||
}
|
||||
|
||||
void
|
||||
GregorianCalendar::computeTime(UErrorCode& status)
|
||||
{
|
||||
|
@ -794,18 +813,8 @@ GregorianCalendar::computeTime(UErrorCode& status)
|
|||
|
||||
// The year is either the YEAR or the epoch year. YEAR_WOY is
|
||||
// used only if WOY is the predominant field; see computeJulianDay.
|
||||
int32_t year = (fStamp[UCAL_YEAR] != kUnset) ? internalGet(UCAL_YEAR) : kEpochYear;
|
||||
int32_t era = AD;
|
||||
if (fStamp[UCAL_ERA] != kUnset) {
|
||||
era = internalGet(UCAL_ERA);
|
||||
if (era == BC)
|
||||
year = 1 - year;
|
||||
// Even in lenient mode we disallow ERA values other than AD & BC
|
||||
else if (era != AD) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return;
|
||||
}
|
||||
}
|
||||
int32_t year = getGregorianYear(status);
|
||||
int32_t era = (year>0)?AD:BC; // calculate era from extended year.
|
||||
|
||||
// First, use the year to determine whether to use the Gregorian or the
|
||||
// Julian calendar. If the year is not the year of the cutover, this
|
||||
|
@ -2009,8 +2018,8 @@ GregorianCalendar::getActualMaximum(UCalendarDateFields field) const
|
|||
/* Perform a binary search, with the invariant that lowGood is a
|
||||
* valid year, and highBad is an out of range year.
|
||||
*/
|
||||
int32_t lowGood = kLeastMaxValues[field];
|
||||
int32_t highBad = kMaxValues[field] + 1;
|
||||
int32_t lowGood = getLeastMaximum(field);
|
||||
int32_t highBad = getMaximum(field) + 1;
|
||||
while((lowGood + 1) < highBad) {
|
||||
int32_t y = (lowGood + highBad) / 2;
|
||||
cal->set(field, y);
|
||||
|
|
|
@ -97,11 +97,11 @@ SimpleDateFormat::~SimpleDateFormat()
|
|||
//----------------------------------------------------------------------
|
||||
|
||||
SimpleDateFormat::SimpleDateFormat(UErrorCode& status)
|
||||
: fSymbols(NULL),
|
||||
fDefaultCenturyStart(fgSystemDefaultCentury),
|
||||
fDefaultCenturyStartYear(fgSystemDefaultCenturyYear)
|
||||
: fSymbols(NULL),fLocale(Locale::getDefault()),
|
||||
fDefaultCenturyStart(fgSystemDefaultCentury),
|
||||
fDefaultCenturyStartYear(fgSystemDefaultCenturyYear)
|
||||
{
|
||||
construct(kShort, (EStyle) (kShort + kDateOffset), Locale::getDefault(), status);
|
||||
construct(kShort, (EStyle) (kShort + kDateOffset), fLocale, status);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -109,11 +109,13 @@ SimpleDateFormat::SimpleDateFormat(UErrorCode& status)
|
|||
SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
|
||||
UErrorCode &status)
|
||||
: fPattern(pattern),
|
||||
fSymbols(new DateFormatSymbols(status)),
|
||||
fSymbols(NULL),
|
||||
fLocale(Locale::getDefault()),
|
||||
fDefaultCenturyStart(fgSystemDefaultCentury),
|
||||
fDefaultCenturyStartYear(fgSystemDefaultCenturyYear)
|
||||
{
|
||||
initialize(Locale::getDefault(), status);
|
||||
initializeSymbols(fLocale, initializeCalendar(NULL,fLocale,status), status);
|
||||
initialize(fLocale, status);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -122,11 +124,12 @@ SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
|
|||
const Locale& locale,
|
||||
UErrorCode& status)
|
||||
: fPattern(pattern),
|
||||
fSymbols(new DateFormatSymbols(locale, status)),
|
||||
fLocale(locale),
|
||||
fDefaultCenturyStart(fgSystemDefaultCentury),
|
||||
fDefaultCenturyStartYear(fgSystemDefaultCenturyYear)
|
||||
{
|
||||
initialize(locale, status);
|
||||
initializeSymbols(fLocale, initializeCalendar(NULL,fLocale,status), status);
|
||||
initialize(fLocale, status);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -136,10 +139,12 @@ SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
|
|||
UErrorCode& status)
|
||||
: fPattern(pattern),
|
||||
fSymbols(symbolsToAdopt),
|
||||
fLocale(Locale::getDefault()),
|
||||
fDefaultCenturyStart(fgSystemDefaultCentury),
|
||||
fDefaultCenturyStartYear(fgSystemDefaultCenturyYear)
|
||||
{
|
||||
initialize(Locale::getDefault(), status);
|
||||
initializeCalendar(NULL,fLocale,status);
|
||||
initialize(fLocale, status);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -150,9 +155,11 @@ SimpleDateFormat::SimpleDateFormat(const UnicodeString& pattern,
|
|||
: fPattern(pattern),
|
||||
fSymbols(new DateFormatSymbols(symbols)),
|
||||
fDefaultCenturyStart(fgSystemDefaultCentury),
|
||||
fDefaultCenturyStartYear(fgSystemDefaultCenturyYear)
|
||||
fDefaultCenturyStartYear(fgSystemDefaultCenturyYear),
|
||||
fLocale(Locale::getDefault())
|
||||
{
|
||||
initialize(Locale::getDefault(), status);
|
||||
initializeCalendar(NULL, fLocale, status);
|
||||
initialize(fLocale, status);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -164,9 +171,10 @@ SimpleDateFormat::SimpleDateFormat(EStyle timeStyle,
|
|||
UErrorCode& status)
|
||||
: fSymbols(NULL),
|
||||
fDefaultCenturyStart(fgSystemDefaultCentury),
|
||||
fDefaultCenturyStartYear(fgSystemDefaultCenturyYear)
|
||||
fDefaultCenturyStartYear(fgSystemDefaultCenturyYear),
|
||||
fLocale(locale)
|
||||
{
|
||||
construct(timeStyle, dateStyle, locale, status);
|
||||
construct(timeStyle, dateStyle, fLocale, status);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -180,11 +188,12 @@ SimpleDateFormat::SimpleDateFormat(const Locale& locale,
|
|||
UErrorCode& status)
|
||||
: fPattern(fgDefaultPattern),
|
||||
fSymbols(NULL),
|
||||
fLocale(locale),
|
||||
fDefaultCenturyStart(fgSystemDefaultCentury),
|
||||
fDefaultCenturyStartYear(fgSystemDefaultCenturyYear)
|
||||
{
|
||||
if (U_FAILURE(status)) return;
|
||||
fSymbols = new DateFormatSymbols(locale, status);
|
||||
fSymbols = new DateFormatSymbols(fLocale, status);
|
||||
if (U_FAILURE(status))
|
||||
{
|
||||
status = U_ZERO_ERROR;
|
||||
|
@ -197,7 +206,7 @@ SimpleDateFormat::SimpleDateFormat(const Locale& locale,
|
|||
return;
|
||||
}
|
||||
}
|
||||
initialize(locale, status);
|
||||
initialize(fLocale, status);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -282,8 +291,9 @@ void SimpleDateFormat::construct(EStyle timeStyle,
|
|||
return;
|
||||
}
|
||||
|
||||
initializeSymbols(locale, initializeCalendar(NULL, locale, status), status);
|
||||
// create a symbols object from the locale
|
||||
fSymbols = new DateFormatSymbols(locale, status);
|
||||
if (U_FAILURE(status)) return;
|
||||
/* test for NULL */
|
||||
if (fSymbols == 0) {
|
||||
status = U_MEMORY_ALLOCATION_ERROR;
|
||||
|
@ -343,6 +353,26 @@ void SimpleDateFormat::construct(EStyle timeStyle,
|
|||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
Calendar*
|
||||
SimpleDateFormat::initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status)
|
||||
{
|
||||
if(!U_FAILURE(status)) {
|
||||
fCalendar = Calendar::createInstance(adoptZone?adoptZone:TimeZone::createDefault(), locale, status);
|
||||
}
|
||||
return fCalendar;
|
||||
}
|
||||
|
||||
void
|
||||
SimpleDateFormat::initializeSymbols(const Locale& locale, Calendar* calendar, UErrorCode& status)
|
||||
{
|
||||
if(U_FAILURE(status)) {
|
||||
fSymbols = NULL;
|
||||
} else {
|
||||
// pass in calendar type - use NULL (default) if no calendar set (or err).
|
||||
fSymbols = new DateFormatSymbols(locale, calendar?calendar->getType() :NULL , status);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SimpleDateFormat::initialize(const Locale& locale,
|
||||
UErrorCode& status)
|
||||
|
@ -1548,6 +1578,16 @@ SimpleDateFormat::initializeSystemDefaultCentury()
|
|||
}
|
||||
}
|
||||
|
||||
void SimpleDateFormat::adoptCalendar(Calendar* calendarToAdopt)
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
DateFormat::adoptCalendar(calendarToAdopt);
|
||||
delete fSymbols;
|
||||
fSymbols=NULL;
|
||||
initializeSymbols(fLocale, fCalendar, status);
|
||||
}
|
||||
|
||||
|
||||
U_NAMESPACE_END
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
|
|
@ -538,6 +538,7 @@ public:
|
|||
* Set the calendar to be used by this date format. Initially, the default
|
||||
* calendar for the specified or default locale is used. The caller should
|
||||
* not delete the Calendar object after it is adopted by this call.
|
||||
* Adopting a new calendar will change to the default symbols.
|
||||
*
|
||||
* @param calendarToAdopt Calendar object to be adopted.
|
||||
* @stable ICU 2.0
|
||||
|
|
|
@ -560,7 +560,7 @@ protected:
|
|||
* Called by computeFields. Converts calendar's year into Gregorian Extended Year (where negative = BC)
|
||||
* @internal
|
||||
*/
|
||||
//virtual int32_t getGregorianYear(UErrorCode &status);
|
||||
virtual int32_t getGregorianYear(UErrorCode &status);
|
||||
|
||||
/**
|
||||
* (Overrides Calendar) Converts GMT as milliseconds to time field values.
|
||||
|
@ -580,7 +580,7 @@ protected:
|
|||
*/
|
||||
virtual void computeTime(UErrorCode& status);
|
||||
|
||||
private:
|
||||
private:
|
||||
GregorianCalendar(); // default constructor not implemented
|
||||
|
||||
protected:
|
||||
|
@ -634,6 +634,20 @@ private:
|
|||
* @return the day number with respect to the epoch.
|
||||
*/
|
||||
virtual UDate getEpochDay(UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Compute the date-based fields given the milliseconds since the epoch start. Do
|
||||
* not compute the time-based fields (HOUR, MINUTE, etc.).
|
||||
*
|
||||
* @param theTime the time in wall millis (either Standard or DST),
|
||||
* whichever is in effect
|
||||
* @param quick if true, only compute the ERA, YEAR, MONTH, DATE,
|
||||
* DAY_OF_WEEK, and DAY_OF_YEAR.
|
||||
* @param status Fill-in parameter which receives the status of this operation.
|
||||
* @internal
|
||||
*/
|
||||
virtual void timeToFields(UDate theTime, UBool quick, UErrorCode& status);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Compute the julian day number of the given year.
|
||||
|
@ -681,18 +695,6 @@ private:
|
|||
*/
|
||||
double computeJulianDay(UBool isGregorian, int32_t year);
|
||||
|
||||
/**
|
||||
* Compute the date-based fields given the milliseconds since the epoch start. Do
|
||||
* not compute the time-based fields (HOUR, MINUTE, etc.).
|
||||
*
|
||||
* @param theTime the time in wall millis (either Standard or DST),
|
||||
* whichever is in effect
|
||||
* @param quick if true, only compute the ERA, YEAR, MONTH, DATE,
|
||||
* DAY_OF_WEEK, and DAY_OF_YEAR.
|
||||
* @param status Fill-in parameter which receives the status of this operation.
|
||||
*/
|
||||
void timeToFields(UDate theTime, UBool quick, UErrorCode& status);
|
||||
|
||||
|
||||
/**
|
||||
* Return the week number of a day, within a period. This may be the week number in
|
||||
|
|
|
@ -572,6 +572,17 @@ public:
|
|||
*/
|
||||
virtual UClassID getDynamicClassID(void) const;
|
||||
|
||||
/**
|
||||
* Set the calendar to be used by this date format. Initially, the default
|
||||
* calendar for the specified or default locale is used. The caller should
|
||||
* not delete the Calendar object after it is adopted by this call.
|
||||
* Adopting a new calendar will change to the default symbols.
|
||||
*
|
||||
* @param calendarToAdopt Calendar object to be adopted.
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
virtual void adoptCalendar(Calendar* calendarToAdopt);
|
||||
|
||||
private:
|
||||
static const char fgClassID;
|
||||
|
||||
|
@ -651,6 +662,23 @@ private:
|
|||
*/
|
||||
static UBool isNumeric(UChar formatChar, int32_t count);
|
||||
|
||||
/**
|
||||
* initializes fCalendar from parameters. Returns fCalendar as a convenience.
|
||||
* @param adoptZone Zone to be adopted, or NULL for TimeZone::createDefault().
|
||||
* @param locale Locale of the calendar
|
||||
* @param status Error code
|
||||
* @return the newly constructed fCalendar
|
||||
*/
|
||||
Calendar *initializeCalendar(TimeZone* adoptZone, const Locale& locale, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* initializes fSymbols from parameters.
|
||||
* @param locale Locale of the symbols
|
||||
* @param calendar Alias to Calendar that will be used.
|
||||
* @param status Error code
|
||||
*/
|
||||
void initializeSymbols(const Locale& locale, Calendar* calendar, UErrorCode& status);
|
||||
|
||||
/**
|
||||
* Called by several of the constructors to load pattern data and formatting symbols
|
||||
* out of a resource bundle and initialize the locale based on it.
|
||||
|
@ -780,6 +808,11 @@ private:
|
|||
*/
|
||||
UnicodeString fPattern;
|
||||
|
||||
/**
|
||||
* The original locale used (for reloading symbols)
|
||||
*/
|
||||
Locale fLocale;
|
||||
|
||||
/**
|
||||
* A pointer to an object containing the strings to use in formatting (e.g.,
|
||||
* month and day names, AM and PM strings, time zone names, etc.)
|
||||
|
|
Loading…
Add table
Reference in a new issue