mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-4567 Merged Before Minguo support in TaiwanCalendar from ICU4C to ICU4J. Changed GregorianCalendar subclasses to use a Gregorian year in EXTENDED_YEAR field. Also clean up GregorianCalendar subclasses to remove unnecessary override methods.
X-SVN-Rev: 22416
This commit is contained in:
parent
f4a7861584
commit
a439b9f7f6
7 changed files with 94 additions and 118 deletions
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:610fd840b3b3d0330f17fae47e0423ea3e4017683f84f6b1e9b91d2d8cdaccfe
|
||||
size 792654
|
||||
oid sha256:71b11bf9729a28f70fe4614871023b7de988b53f6588e897f3e957691d2bc1bb
|
||||
size 792871
|
||||
|
|
|
@ -307,9 +307,10 @@ public class IBMCalendarTest extends CalendarTest {
|
|||
public void TestTaiwan() {
|
||||
quasiGregorianTest(new TaiwanCalendar(),
|
||||
new int[] {
|
||||
0, 1, 1912, Calendar.JUNE, 4,
|
||||
0, 3, 1914, Calendar.FEBRUARY, 12,
|
||||
0, 96,2007, Calendar.FEBRUARY, 12,
|
||||
TaiwanCalendar.BEFORE_MINGUO, 8, 1904, Calendar.FEBRUARY, 29,
|
||||
TaiwanCalendar.MINGUO, 1, 1912, Calendar.JUNE, 4,
|
||||
TaiwanCalendar.MINGUO, 3, 1914, Calendar.FEBRUARY, 12,
|
||||
TaiwanCalendar.MINGUO, 96,2007, Calendar.FEBRUARY, 12,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2002-2006, International Business Machines Corporation and *
|
||||
* Copyright (C) 2002-2007, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -50,7 +50,7 @@ public class JapaneseTest extends CalendarTest {
|
|||
errln("could not create JapaneseCalendar with TimeZone ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// new JapaneseCalendar(Locale)
|
||||
JapaneseCalendar cal = new JapaneseCalendar(Locale.getDefault());
|
||||
|
@ -113,7 +113,7 @@ public class JapaneseTest extends CalendarTest {
|
|||
cal.add(Calendar.YEAR, 1);
|
||||
logln("date: " + fmt.format(cal.getTime()));
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// data
|
||||
JapaneseCalendar cal = new JapaneseCalendar(1868, Calendar.JANUARY, 1);
|
||||
|
@ -127,16 +127,16 @@ public class JapaneseTest extends CalendarTest {
|
|||
"en", "ja"
|
||||
};
|
||||
for (int i = 0; i < calendarLocales.length; ++i) {
|
||||
String calLocName = calendarLocales[i];
|
||||
Locale calLocale = LocaleUtility.getLocaleFromName(calLocName);
|
||||
cal = new JapaneseCalendar(calLocale);
|
||||
String calLocName = calendarLocales[i];
|
||||
Locale calLocale = LocaleUtility.getLocaleFromName(calLocName);
|
||||
cal = new JapaneseCalendar(calLocale);
|
||||
|
||||
for (int j = 0; j < formatLocales.length; ++j) {
|
||||
String locName = formatLocales[j];
|
||||
Locale formatLocale = LocaleUtility.getLocaleFromName(locName);
|
||||
DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.FULL, formatLocale);
|
||||
logln(calLocName + "/" + locName + " --> " + format.format(time));
|
||||
}
|
||||
for (int j = 0; j < formatLocales.length; ++j) {
|
||||
String locName = formatLocales[j];
|
||||
Locale formatLocale = LocaleUtility.getLocaleFromName(locName);
|
||||
DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.FULL, formatLocale);
|
||||
logln(calLocName + "/" + locName + " --> " + format.format(time));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ public class JapaneseTest extends CalendarTest {
|
|||
ParsePosition pos = new ParsePosition(0);
|
||||
Date aDate = format.parse("1.1.9", pos); // after the start of heisei accession. Jan 1, 1H wouldn't work because it is actually showa 64
|
||||
String inEn = enjformat.format(aDate);
|
||||
|
||||
|
||||
cal.clear();
|
||||
cal.setTime(aDate);
|
||||
int gotYear = cal.get(Calendar.YEAR);
|
||||
|
@ -162,11 +162,11 @@ public class JapaneseTest extends CalendarTest {
|
|||
|
||||
if((gotYear != expectYear) || (gotEra != expectEra)) {
|
||||
errln("Expected year " + expectYear + ", era " + expectEra +", but got year " + gotYear + " and era " + gotEra + ", == " + inEn);
|
||||
} else {
|
||||
} else {
|
||||
logln("Got year " + gotYear + " and era " + gotEra + ", == " + inEn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Test5345parse() {
|
||||
// Test parse with incomplete information
|
||||
DateFormat fmt2= DateFormat.getDateInstance(); //DateFormat.LONG, Locale.US);
|
||||
|
@ -201,8 +201,8 @@ public class JapaneseTest extends CalendarTest {
|
|||
|
||||
errln("FAIL: Parse incorrect of " + expected + ": wanted " + aDate + " ("+aLong+"), but got " + " " +
|
||||
otherDate + " ("+oLong+") = " + str3 + " not " + dd.toString() );
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
logln("Parsed OK: " + expected);
|
||||
}
|
||||
|
@ -242,12 +242,12 @@ public class JapaneseTest extends CalendarTest {
|
|||
JapaneseCalendar c = new JapaneseCalendar(TimeZone.getDefault());
|
||||
logln("test clear");
|
||||
c.clear();
|
||||
|
||||
int expected0[] = { Calendar.ERA, 0 ,
|
||||
Calendar.YEAR, -643 };
|
||||
|
||||
// Showa 45 = Gregorian 1970
|
||||
int expected0[] = { Calendar.ERA, 234,
|
||||
Calendar.YEAR, 45 };
|
||||
checkExpected(c, expected0);
|
||||
|
||||
|
||||
|
||||
logln("test setting era");
|
||||
c.clear();
|
||||
c.set(Calendar.ERA, JapaneseCalendar.MEIJI);
|
||||
|
@ -255,7 +255,7 @@ public class JapaneseTest extends CalendarTest {
|
|||
|
||||
int expectedA[] = { Calendar.ERA, JapaneseCalendar.MEIJI };
|
||||
checkExpected(c, expectedA);
|
||||
|
||||
|
||||
|
||||
logln("test setting era and year and month and date");
|
||||
c.clear();
|
||||
|
@ -263,11 +263,11 @@ public class JapaneseTest extends CalendarTest {
|
|||
c.set(Calendar.YEAR, 1);
|
||||
c.set(Calendar.MONTH, Calendar.JANUARY);
|
||||
c.set(Calendar.DATE, 1);
|
||||
|
||||
|
||||
|
||||
|
||||
int expectedC[] = { Calendar.ERA, JapaneseCalendar.MEIJI -1};
|
||||
checkExpected(c, expectedC);
|
||||
|
||||
|
||||
|
||||
logln("test setting year and month and date THEN era");
|
||||
c.clear();
|
||||
|
@ -284,12 +284,12 @@ public class JapaneseTest extends CalendarTest {
|
|||
c.clear();
|
||||
c.set(Calendar.YEAR, 1);
|
||||
c.set(Calendar.ERA, JapaneseCalendar.MEIJI);
|
||||
|
||||
|
||||
|
||||
|
||||
int expectedB[] = { Calendar.ERA, JapaneseCalendar.MEIJI,
|
||||
Calendar.YEAR, 1 };
|
||||
checkExpected(c, expectedB);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:62e4c288ee162abf767199c40b3648ef3fc850ad4ba974260cda5cf9e758087e
|
||||
size 5422624
|
||||
oid sha256:2697da44666d01ee2839d8b3dbd607fb124a72611db349507013d237951217f4
|
||||
size 5423300
|
||||
|
|
|
@ -186,17 +186,21 @@ public class BuddhistCalendar extends GregorianCalendar {
|
|||
// Starts in -543 AD, ie 544 BC
|
||||
private static final int BUDDHIST_ERA_START = -543;
|
||||
|
||||
// Use 1970 as the default value of EXTENDED_YEAR
|
||||
private static final int GREGORIAN_EPOCH = 1970;
|
||||
|
||||
/**
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
protected int handleGetExtendedYear() {
|
||||
// EXTENDED_YEAR in BuddhistCalendar is a Gregorian year
|
||||
// The default value of EXTENDED_YEAR is 1970 (Buddhist 2513)
|
||||
int year;
|
||||
if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR) {
|
||||
year = internalGet(EXTENDED_YEAR, 1);
|
||||
year = internalGet(EXTENDED_YEAR, GREGORIAN_EPOCH);
|
||||
} else {
|
||||
// extended year is a gregorian year, where 1 = 1AD, 0 = 1BC, -1 = 2BC, etc
|
||||
year = internalGet(YEAR, 1) // pin to minimum of year 1 (first year)
|
||||
+ BUDDHIST_ERA_START; // add gregorian starting year
|
||||
year = internalGet(YEAR, GREGORIAN_EPOCH - BUDDHIST_ERA_START)
|
||||
+ BUDDHIST_ERA_START;
|
||||
}
|
||||
return year;
|
||||
}
|
||||
|
@ -241,22 +245,4 @@ public class BuddhistCalendar extends GregorianCalendar {
|
|||
public String getType() {
|
||||
return "buddhist";
|
||||
}
|
||||
|
||||
/*
|
||||
private static CalendarFactory factory;
|
||||
public static CalendarFactory factory() {
|
||||
if (factory == null) {
|
||||
factory = new CalendarFactory() {
|
||||
public Calendar create(TimeZone tz, ULocale loc) {
|
||||
return new BuddhistCalendar(tz, loc);
|
||||
}
|
||||
|
||||
public String factoryName() {
|
||||
return "Buddhist";
|
||||
}
|
||||
};
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -206,14 +206,19 @@ public class JapaneseCalendar extends GregorianCalendar {
|
|||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
// Use 1970 as the default value of EXTENDED_YEAR
|
||||
private static final int GREGORIAN_EPOCH = 1970;
|
||||
|
||||
/**
|
||||
* @stable ICU 2.8
|
||||
*/
|
||||
protected int handleGetExtendedYear() {
|
||||
// EXTENDED_YEAR in JapaneseCalendar is a Gregorian year
|
||||
// The default value of EXTENDED_YEAR is 1970 (Showa 45)
|
||||
int year;
|
||||
if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR &&
|
||||
newerField(EXTENDED_YEAR, ERA) == EXTENDED_YEAR) {
|
||||
year = internalGet(EXTENDED_YEAR, 1);
|
||||
year = internalGet(EXTENDED_YEAR, GREGORIAN_EPOCH);
|
||||
} else {
|
||||
// extended year is a gregorian year, where 1 = 1AD, 0 = 1BC, -1 = 2BC, etc
|
||||
year = internalGet(YEAR, 1) // pin to minimum of year 1 (first year)
|
||||
|
@ -647,22 +652,4 @@ public class JapaneseCalendar extends GregorianCalendar {
|
|||
public String getType() {
|
||||
return "japanese";
|
||||
}
|
||||
|
||||
/*
|
||||
private static CalendarFactory factory;
|
||||
public static CalendarFactory factory() {
|
||||
if (factory == null) {
|
||||
factory = new CalendarFactory() {
|
||||
public Calendar create(TimeZone tz, ULocale loc) {
|
||||
return new JapaneseCalendar(tz, loc);
|
||||
}
|
||||
|
||||
public String factoryName() {
|
||||
return "Japanese";
|
||||
}
|
||||
};
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -44,15 +44,26 @@ public class TaiwanCalendar extends GregorianCalendar {
|
|||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constant for the Taiwan Era. This is the only allowable <code>ERA</code>
|
||||
* value for the Taiwan calendar.
|
||||
* Constant for the Taiwan Era for years before Minguo 1.
|
||||
* Brefore Minuo 1 is Gregorian 1911, Before Minguo 2 is Gregorian 1910
|
||||
* and so on.
|
||||
*
|
||||
* @see com.ibm.icu.util.Calendar#ERA
|
||||
* @draft ICU 3.8
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public static final int MINGUO = 0;
|
||||
|
||||
public static final int BEFORE_MINGUO = 0;
|
||||
|
||||
/**
|
||||
* Constant for the Taiwan Era for Minguo. Minguo 1 is 1912 in
|
||||
* Gregorian calendar.
|
||||
*
|
||||
* @see com.ibm.icu.util.Calendar#ERA
|
||||
* @draft ICU 3.8
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public static final int MINGUO = 1;
|
||||
|
||||
/**
|
||||
* Constructs a <code>TaiwanCalendar</code> using the current time
|
||||
* in the default time zone with the default locale.
|
||||
|
@ -185,32 +196,33 @@ public class TaiwanCalendar extends GregorianCalendar {
|
|||
|
||||
private static final int Taiwan_ERA_START = 1911; // 0=1911, 1=1912
|
||||
|
||||
// Use 1970 as the default value of EXTENDED_YEAR
|
||||
private static final int GREGORIAN_EPOCH = 1970;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @draft ICU 3.8
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
protected int handleGetExtendedYear() {
|
||||
int year;
|
||||
if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR) {
|
||||
year = internalGet(EXTENDED_YEAR, 1);
|
||||
// EXTENDED_YEAR in TaiwanCalendar is a Gregorian year
|
||||
// The default value of EXTENDED_YEAR is 1970 (Minguo 59)
|
||||
int year = GREGORIAN_EPOCH;
|
||||
if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR
|
||||
&& newerField(EXTENDED_YEAR, ERA) == EXTENDED_YEAR) {
|
||||
year = internalGet(EXTENDED_YEAR, GREGORIAN_EPOCH);
|
||||
} else {
|
||||
// Ignore the era, as there is only one
|
||||
year = internalGet(YEAR, 1);
|
||||
int era = internalGet(ERA, MINGUO);
|
||||
if (era == MINGUO) {
|
||||
year = internalGet(YEAR, 1) + Taiwan_ERA_START;
|
||||
} else {
|
||||
year = 1 - internalGet(YEAR, 1) + Taiwan_ERA_START;
|
||||
}
|
||||
}
|
||||
return year;
|
||||
}
|
||||
|
||||
// Return JD of start of given month/year
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @draft ICU 3.8
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
protected int handleComputeMonthStart(int eyear, int month, boolean useMonth) {
|
||||
return super.handleComputeMonthStart(eyear + Taiwan_ERA_START, month, useMonth);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @draft ICU 3.8
|
||||
|
@ -219,9 +231,13 @@ public class TaiwanCalendar extends GregorianCalendar {
|
|||
protected void handleComputeFields(int julianDay) {
|
||||
super.handleComputeFields(julianDay);
|
||||
int y = internalGet(EXTENDED_YEAR) - Taiwan_ERA_START;
|
||||
internalSet(EXTENDED_YEAR, y);
|
||||
internalSet(ERA, 0);
|
||||
internalSet(YEAR, y);
|
||||
if (y > 0) {
|
||||
internalSet(ERA, MINGUO);
|
||||
internalSet(YEAR, y);
|
||||
} else {
|
||||
internalSet(ERA, BEFORE_MINGUO);
|
||||
internalSet(YEAR, 1- y);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,7 +249,11 @@ public class TaiwanCalendar extends GregorianCalendar {
|
|||
*/
|
||||
protected int handleGetLimit(int field, int limitType) {
|
||||
if (field == ERA) {
|
||||
return MINGUO;
|
||||
if (limitType == MINIMUM || limitType == GREATEST_MINIMUM) {
|
||||
return BEFORE_MINGUO;
|
||||
} else {
|
||||
return MINGUO;
|
||||
}
|
||||
}
|
||||
return super.handleGetLimit(field, limitType);
|
||||
}
|
||||
|
@ -246,22 +266,4 @@ public class TaiwanCalendar extends GregorianCalendar {
|
|||
public String getType() {
|
||||
return "taiwan";
|
||||
}
|
||||
|
||||
/*
|
||||
private static CalendarFactory factory;
|
||||
public static CalendarFactory factory() {
|
||||
if (factory == null) {
|
||||
factory = new CalendarFactory() {
|
||||
public Calendar create(TimeZone tz, ULocale loc) {
|
||||
return new TaiwanCalendar(tz, loc);
|
||||
}
|
||||
|
||||
public String factoryName() {
|
||||
return "Taiwan";
|
||||
}
|
||||
};
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue