ICU-20078 Add JP_ERA_2019 constants, export enableTentativeEra(), add intervalFmt tests with eras

This commit is contained in:
Peter Edberg 2019-02-07 22:56:00 -08:00 committed by pedberg-icu
parent 7dfdfb330f
commit 641326d7b8
7 changed files with 767 additions and 612 deletions

View file

@ -61,8 +61,9 @@ UOBJECT_DEFINE_RTTI_IMPLEMENTATION(JapaneseCalendar)
static const int32_t kGregorianEpoch = 1970; // used as the default value of EXTENDED_YEAR
static const char* TENTATIVE_ERA_VAR_NAME = "ICU_ENABLE_TENTATIVE_ERA";
// Initialize global Japanese era data
static void U_CALLCONV initializeEras(UErrorCode &status) {
// Export the following for use by test code.
UBool JapaneseCalendar::enableTentativeEra() {
// Although start date of next Japanese era is planned ahead, a name of
// new era might not be available. This implementation allows tester to
// check a new era without era names by settings below (in priority order).
@ -87,7 +88,13 @@ static void U_CALLCONV initializeEras(UErrorCode &status) {
includeTentativeEra = TRUE;
}
#endif
gJapaneseEraRules = EraRules::createInstance("japanese", includeTentativeEra, status);
return includeTentativeEra;
}
// Initialize global Japanese era data
static void U_CALLCONV initializeEras(UErrorCode &status) {
gJapaneseEraRules = EraRules::createInstance("japanese", JapaneseCalendar::enableTentativeEra(), status);
if (U_FAILURE(status)) {
return;
}

View file

@ -67,7 +67,14 @@ class JapaneseCalendar : public GregorianCalendar {
public:
/**
* Useful constants for JapaneseCalendar.
* Check environment variable.
* @internal
*/
U_I18N_API static UBool U_EXPORT2 enableTentativeEra(void);
/**
* Useful constants for JapaneseCalendar.
* Exported for use by test code.
* @internal
*/
U_I18N_API static uint32_t U_EXPORT2 getCurrentEra(void); // the current era

View file

@ -482,6 +482,27 @@ typedef enum UDateFormatStyle {
#define UDAT_HOUR_TZ "jz"
#endif /* U_HIDE_DEPRECATED_API */
#ifndef U_HIDE_INTERNAL_API
/**
* Constant for Unicode string name of new (in 2019) Japanese calendar era,
* root/English abbreviated version (ASCII-range characters).
* @internal
*/
#define JP_ERA_2019_ROOT "Qqqq"
/**
* Constant for Unicode string name of new (in 2019) Japanese calendar era,
* Japanese abbreviated version (Han, or fullwidth Latin for testing).
* @internal
*/
#define JP_ERA_2019_JA "\\uFF31\\uFF31"
/**
* Constant for Unicode string name of new (in 2019) Japanese calendar era,
* root and Japanese narrow version (ASCII-range characters).
* @internal
*/
#define JP_ERA_2019_NARROW "Q"
#endif // U_HIDE_INTERNAL_API
/**
* FieldPosition and UFieldPosition selectors for format fields
* defined by DateFormat and UDateFormat.

File diff suppressed because it is too large Load diff

View file

@ -1311,6 +1311,32 @@ public abstract class DateFormat extends UFormat {
@Deprecated
public static final String HOUR_TZ = "jz";
/**
* Constant for Unicode string name of new (in 2019) Japanese calendar era,
* root/English abbreviated version (ASCII-range characters).
* @internal
* @deprecated This API is ICU internal only.
*/
@Deprecated
public static final String JP_ERA_2019_ROOT = "Qqqq";
/**
* Constant for Unicode string name of new (in 2019) Japanese calendar era,
* Japanese abbreviated version (Han, or fullwidth Latin for testing).
* @internal
* @deprecated This API is ICU internal only.
*/
@Deprecated
public static final String JP_ERA_2019_JA = "\uFF31\uFF31";
/**
* Constant for Unicode string name of new (in 2019) Japanese calendar era,
* root and Japanese narrow version (ASCII-range characters).
* @internal
* @deprecated This API is ICU internal only.
*/
@Deprecated
public static final String JP_ERA_2019_NARROW = "Q";
/**
* Gets the time formatter with the default formatting style

View file

@ -231,6 +231,16 @@ public class JapaneseCalendar extends GregorianCalendar {
private static final EraRules ERA_RULES;
static {
ERA_RULES = EraRules.getInstance(CalType.JAPANESE, enableTentativeEra());
}
/**
* Check environment variable that enables use of future eras.
* @internal
* @deprecated This API is ICU internal only.
*/
@Deprecated
public static boolean enableTentativeEra() {
// Although start date of next Japanese era is planned ahead, a name of
// new era might not be available. This implementation allows tester to
// check a new era without era names by settings below (in priority order).
@ -258,8 +268,7 @@ public class JapaneseCalendar extends GregorianCalendar {
String jdkEraConf = System.getProperty("jdk.calendar.japanese.supplemental.era");
includeTentativeEra = jdkEraConf != null;
}
ERA_RULES = EraRules.getInstance(CalType.JAPANESE, includeTentativeEra);
return includeTentativeEra;
}
/**