ICU-4383 support for Ethiopic and Coptic Calendars

X-SVN-Rev: 17678
This commit is contained in:
Doug Felt 2005-05-25 03:11:12 +00:00
parent 38a8d00feb
commit 054b67ba4b
4 changed files with 302 additions and 241 deletions

View File

@ -11,6 +11,7 @@ import java.util.Locale;
import com.ibm.icu.impl.LocaleUtility;
import com.ibm.icu.text.DateFormat;
import com.ibm.icu.text.SimpleDateFormat;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.CopticCalendar;
import com.ibm.icu.util.TimeZone;
@ -98,16 +99,13 @@ public class CopticTest extends CalendarTest
// Julian Day Era Year Month Day WkDay Hour Min Sec
//
// Dates from "Emporer Theodore..."
new TestCase(2401442.5, 1, 1579, 2, 20, WED, 0, 0, 0), // Gregorian: 20/10/1862
new TestCase(2402422.5, 1, 1581, 10, 29, WED, 0, 0, 0), // Gregorian: 05/07/1865
new TestCase(2402630.5, 1, 1582, 5, 22, MON, 0, 0, 0), // Gregorian: 29/01/1866
new TestCase(2402708.5, 1, 1582, 8, 10, TUE, 0, 0, 0), // Gregorian: 17/04/1866
new TestCase(2402971.5, 1, 1583, 4, 28, SAT, 0, 0, 0), // Gregorian: 05/01/1867
new TestCase(2403344.5, 1, 1584, 5, 5, MON, 0, 0, 0), // Gregorian: 13/01/1868
/* Skip these tests until JD bug fixed in the Gregorian calendar:
* http://www.jtcsv.com/cgibin/icu-bugs/incoming?id=4406;page=2;user=guest
*
new TestCase(1721059.5, 0, -284, 5, 7, SAT, 0, 0, 0), // Gregorian: 01/01/0000
new TestCase(1721425.5, 0, -283, 5, 8, MON, 0, 0, 0), // Gregorian: 01/01/0001
new TestCase(1824663.5, 0, -1, 13, 6, WED, 0, 0, 0), // Gregorian: 29/08/0283
@ -120,11 +118,12 @@ public class CopticTest extends CalendarTest
new TestCase(1825393.5, 1, 1, 13, 5, FRI, 0, 0, 0), // Gregorian: 28/08/0285
new TestCase(1825758.5, 1, 2, 13, 5, SAT, 0, 0, 0), // Gregorian: 28/08/0286
new TestCase(1826123.5, 1, 3, 13, 5, SUN, 0, 0, 0), // Gregorian: 28/08/0287
new TestCase(1826124.5, 1, 3, 13, 6, MON, 0, 0, 0), // Gregorian: 29/08/0287 - first coptic leap year
new TestCase(1826124.5, 1, 3, 13, 6, MON, 0, 0, 0), // Gregorian: 29/08/0287
// above is first coptic leap year
new TestCase(1826489.5, 1, 4, 13, 5, TUE, 0, 0, 0), // Gregorian: 28/08/0288
new TestCase(2299158.5, 1, 1299, 2, 6, WED, 0, 0, 0), // Gregorian: 13/10/1582
new TestCase(2299159.5, 1, 1299, 2, 7, THU, 0, 0, 0), // Gregorian: 14/10/1582
*/
new TestCase(2299160.5, 1, 1299, 2, 8, FRI, 0, 0, 0), // Gregorian: 15/10/1582
new TestCase(2299161.5, 1, 1299, 2, 9, SAT, 0, 0, 0), // Gregorian: 16/10/1582
@ -138,6 +137,38 @@ public class CopticTest extends CalendarTest
doTestCases(tests, testCalendar);
}
// basic sanity check that the conversion algorithm round-trips
public void TestCopticToJD() {
for (int y = -2; y < 3; ++y) {
for (int m = 0; m < 12; ++m) { // don't understand rules for 13th month
for (int d = 1; d < 25; d += 3) { // play it safe on days per month
int jd = CopticCalendar.copticToJD(y, m, d);
Integer[] res = CopticCalendar.getDateFromJD(jd);
if (!(y == res[0].intValue() &&
m == res[1].intValue() &&
d == res[2].intValue())) {
errln("y: " + y +
" m: " + m +
" d: " + d +
" --> jd: " + jd +
" --> y: " + res[0].intValue() +
" m: " + res[1].intValue() +
" d: " + res[2].intValue());
}
}
}
}
}
// basic check to see that we print out eras ok
// eventually should modify to use locale strings and formatter appropriate to coptic calendar
public void TestEraStart() {
CopticCalendar cal = new CopticCalendar(0, 0, 1);
SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd, yyyy GG");
assertEquals("Coptic Date", "Thu Jan 01, 0000 AD", fmt.format(cal));
assertEquals("Gregorian Date", "Thu Aug 30, 0283 AD", fmt.format(cal.getTime()));
}
public void TestBasic() {
CopticCalendar cal = new CopticCalendar();
cal.clear();

View File

@ -11,7 +11,9 @@ import java.util.Locale;
import com.ibm.icu.impl.LocaleUtility;
import com.ibm.icu.text.DateFormat;
import com.ibm.icu.text.SimpleDateFormat;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.GregorianCalendar;
import com.ibm.icu.util.EthiopicCalendar;
import com.ibm.icu.util.TimeZone;
import com.ibm.icu.util.ULocale;
@ -123,6 +125,7 @@ public class EthiopicTest extends CalendarTest
// Julian Day Era Year Month Day WkDay Hour Min Sec
//
// Dates from "Emporer Theodore..."
new TestCase(2401442.5, 1, 1855, 2, 20, WED, 0, 0, 0), // Gregorian: 29/10/1862
new TestCase(2402422.5, 1, 1857, 10, 29, WED, 0, 0, 0), // Gregorian: 05/07/1865
new TestCase(2402630.5, 1, 1858, 5, 22, MON, 0, 0, 0), // Gregorian: 29/01/1866
@ -133,7 +136,7 @@ public class EthiopicTest extends CalendarTest
// Miscellaneous:
/* Skip these tests until JD bug fixed in the Gregorian calendar:
* http://www.jtcsv.com/cgibin/icu-bugs/incoming?id=4406;page=2;user=guest
*
*/
new TestCase(1721059.5, 0, -8, 5, 7, SAT, 0, 0, 0), // Gregorian: 01/01/0000
new TestCase(1721425.5, 0, -7, 5, 8, MON, 0, 0, 0), // Gregorian: 01/01/0001
new TestCase(1723854.5, 0, -1, 13, 6, MON, 0, 0, 0), // Gregorian: 27/08/0007
@ -142,17 +145,19 @@ public class EthiopicTest extends CalendarTest
new TestCase(1724220.5, 1, 1, 1, 1, WED, 0, 0, 0), // Gregorian: 27/08/0008
new TestCase(1724585.5, 1, 2, 1, 1, THU, 0, 0, 0), // Gregorian: 27/08/0009
new TestCase(1724950.5, 1, 3, 1, 1, FRI, 0, 0, 0), // Gregorian: 27/08/0010
new TestCase(1724536.5, 1, 4, 1, 1, SUN, 0, 0, 0), // Gregorian: 28/08/0011
// new TestCase(1724536.5, 1, 4, 1, 1, SUN, 0, 0, 0), // Gregorian: 28/08/0011
new TestCase(1725316.5, 1, 4, 1, 1, SUN, 0, 0, 0), // Gregorian: 28/08/0011 - dlf
new TestCase(1724219.5, 1, 0, 13, 5, TUE, 0, 0, 0), // Gregorian: 26/08/0008
new TestCase(1724584.5, 1, 1, 13, 5, WED, 0, 0, 0), // Gregorian: 26/08/0009
new TestCase(1724949.5, 1, 2, 13, 5, THU, 0, 0, 0), // Gregorian: 26/08/0010
new TestCase(1725314.5, 1, 3, 13, 5, FRI, 0, 0, 0), // Gregorian: 26/08/0011
new TestCase(1725315.5, 1, 3, 13, 6, SAT, 0, 0, 0), // Gregorian: 27/08/0011 - first ethiopic leap year
new TestCase(1725560.5, 1, 4, 13, 5, SUN, 0, 0, 0), // Gregorian: 26/08/0012
// new TestCase(1725560.5, 1, 4, 13, 5, SUN, 0, 0, 0), // Gregorian: 26/08/0012 - dlf
new TestCase(1725680.5, 1, 4, 13, 5, SUN, 0, 0, 0), // Gregorian: 26/08/0012
new TestCase(2299158.5, 1, 1575, 2, 6, WED, 0, 0, 0), // Gregorian: 13/10/1582
new TestCase(2299159.5, 1, 1575, 2, 7, THU, 0, 0, 0), // Gregorian: 14/10/1582 Julian 04/10/1582
*/
new TestCase(2299160.5, 1, 1575, 2, 8, FRI, 0, 0, 0), // Gregorian: 15/10/1582
new TestCase(2299161.5, 1, 1575, 2, 9, SAT, 0, 0, 0), // Gregorian: 16/10/1582
@ -166,6 +171,25 @@ public class EthiopicTest extends CalendarTest
doTestCases(tests, testCalendar);
}
// basic check to see that we print out eras ok
// eventually should modify to use locale strings and formatter appropriate to coptic calendar
public void TestEraStart() {
EthiopicCalendar cal = new EthiopicCalendar(0, 0, 1);
SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd, yyyy GG");
assertEquals("Ethiopic Date", "Tue Jan 01, 0000 AD", fmt.format(cal));
// The gregorian calendar gets off by two days when
// the date gets low, unless the gregorian changeover is set to
// very early. The funny thing is, it's ok for dates in the year
// 283, but not in the year 7, and it claims to be ok until the year 4.
// should track down when the dates start to differ...
GregorianCalendar gc = new GregorianCalendar();
gc.setGregorianChange(new Date(Long.MIN_VALUE)); // act like proleptic Gregorian
gc.setTime(cal.getTime());
assertEquals("Gregorian Date", "Tue Aug 28, 0007 AD", fmt.format(gc));
}
public void TestBasic() {
EthiopicCalendar cal = new EthiopicCalendar();
cal.clear();

View File

@ -156,9 +156,7 @@ class CECalendar extends Calendar {
*/
protected CECalendar(int year, int month, int date) {
super(TimeZone.getDefault(), ULocale.getDefault());
this.set(YEAR, year);
this.set(MONTH, month);
this.set(DATE, date);
this.set(year, month, date);
}
/**
@ -188,12 +186,7 @@ class CECalendar extends Calendar {
int minute, int second)
{
super(TimeZone.getDefault(), ULocale.getDefault());
this.set(YEAR, year);
this.set(MONTH, month);
this.set(DATE, date);
this.set(HOUR_OF_DAY, hour);
this.set(MINUTE, minute);
this.set(SECOND, second);
this.set(year, month, date, hour, minute, second);
}
@ -236,7 +229,7 @@ class CECalendar extends Calendar {
// Do we want to use EthiopicCalendar.AA, .AM here?
int era = GregorianCalendar.AD;
if (_year < 1) {
if (_year < 0) { // dlf: this is what the test says to do
era = GregorianCalendar.BC;
ceyear = 1 - _year;
}
@ -301,4 +294,3 @@ class CECalendar extends Calendar {
return (int) Math.floor((double) i / j);
}
}

View File

@ -12,67 +12,81 @@ import java.util.Locale;
public final class CopticCalendar extends CECalendar
{
/**
* Constant for \u03c9\u03bf\u03b3\u03c4/\u062a\ufeee\ufe97, the 1st month of the Coptic year.
* Constant for \u03c9\u03bf\u03b3\u03c4/\u062a\ufeee\ufe97,
* the 1st month of the Coptic year.
*/
public static final int TOUT = 0;
/**
* Constant for \u03a0\u03b1\u03bf\u03c0\u03b9/\ufeea\ufe91\ufe8e\ufe91, the 2nd month of the Coptic year.
* Constant for \u03a0\u03b1\u03bf\u03c0\u03b9/\ufeea\ufe91\ufe8e\ufe91,
* the 2nd month of the Coptic year.
*/
public static final int BABA = 1;
/**
* Constant for \u0391\u03b8\u03bf\u03c1/\u0631\ufeee\ufe97\ufe8e\ufeeb, the 3rd month of the Coptic year.
* Constant for \u0391\u03b8\u03bf\u03c1/\u0631\ufeee\ufe97\ufe8e\ufeeb,
* the 3rd month of the Coptic year.
*/
public static final int HATOR = 2;
/**
* Constant for \u03a7\u03bf\u03b9\u03b1\u03ba/\ufeda\ufeec\ufef4\ufedb, the 4th month of the Coptic year.
* Constant for \u03a7\u03bf\u03b9\u03b1\u03ba/\ufeda\ufeec\ufef4\ufedb,
* the 4th month of the Coptic year.
*/
public static final int KIAHK = 3;
/**
* Constant for \u03a4\u03c9\u03b2\u03b9/\u0637\ufeee\ufe92\ufeeb, the 5th month of the Coptic year.
* Constant for \u03a4\u03c9\u03b2\u03b9/\u0637\ufeee\ufe92\ufeeb,
* the 5th month of the Coptic year.
*/
public static final int TOBA = 4;
/**
* Constant for \u039c\u03b5\u03e3\u03b9\u03c1/\ufeae\ufef4\ufeb8\ufee3\u0623, the 6th month of the Coptic year.
* Constant for \u039c\u03b5\u03e3\u03b9\u03c1/\ufeae\ufef4\ufeb8\ufee3\u0623,
* the 6th month of the Coptic year.
*/
public static final int AMSHIR = 5;
/**
* Constant for \u03a0\u03b1\u03c1\u03b5\u03bc\u03e9\u03b1\u03c4/\u062a\ufe8e\ufeec\ufee3\ufeae\ufe91, the 7th month of the Coptic year.
* Constant for \u03a0\u03b1\u03c1\u03b5\u03bc\u03e9\u03b1\u03c4/\u062a\ufe8e\ufeec\ufee3\ufeae\ufe91,
* the 7th month of the Coptic year.
*/
public static final int BARAMHAT = 6;
/**
* Constant for \u03a6\u03b1\u03c1\u03bc\u03bf\u03b8\u03b9/\u0647\u062f\ufeee\ufee3\ufeae\ufe91, the 8th month of the Coptic year.
* Constant for \u03a6\u03b1\u03c1\u03bc\u03bf\u03b8\u03b9/\u0647\u062f\ufeee\ufee3\ufeae\ufe91,
* the 8th month of the Coptic year.
*/
public static final int BARAMOUDA = 7;
/**
* Constant for \u03a0\u03b1\u03e3\u03b1\u03bd/\ufeb2\ufee8\ufeb8\ufe91, the 9th month of the Coptic year.
* Constant for \u03a0\u03b1\u03e3\u03b1\u03bd/\ufeb2\ufee8\ufeb8\ufe91,
* the 9th month of the Coptic year.
*/
public static final int BASHANS = 8;
/**
* Constant for \u03a0\u03b1\u03c9\u03bd\u03b9/\ufeea\ufee7\u0624\ufeee\ufe91, the 10th month of the Coptic year.
* Constant for \u03a0\u03b1\u03c9\u03bd\u03b9/\ufeea\ufee7\u0624\ufeee\ufe91,
* the 10th month of the Coptic year.
*/
public static final int PAONA = 9;
/**
* Constant for \u0395\u03c0\u03b7\u03c0/\ufe90\ufef4\ufe91\u0623, the 11th month of the Coptic year.
* Constant for \u0395\u03c0\u03b7\u03c0/\ufe90\ufef4\ufe91\u0623,
* the 11th month of the Coptic year.
*/
public static final int EPEP = 10;
/**
* Constant for \u039c\u03b5\u03f2\u03c9\u03c1\u03b7/\u0649\ufeae\ufeb4\ufee3, the 12th month of the Coptic year.
* Constant for \u039c\u03b5\u03f2\u03c9\u03c1\u03b7/\u0649\ufeae\ufeb4\ufee3,
* the 12th month of the Coptic year.
*/
public static final int MESRA = 11;
/**
* Constant for \u03a0\u03b9\u03ba\u03bf\u03b3\u03eb\u03b9 \u03bc\u03b1\u03b2\u03bf\u03c4/\ufeae\ufef4\ufed0\ufebc\ufedf\u0627 \ufeae\ufeec\ufeb8\ufedf\u0627,
* Constant for \u03a0\u03b9\u03ba\u03bf\u03b3\u03eb\u03b9
* \u03bc\u03b1\u03b2\u03bf\u03c4/\ufeae\ufef4\ufed0\ufebc\ufedf\u0627
* \ufeae\ufeec\ufeb8\ufedf\u0627,
* the 13th month of the Coptic year.
*/
public static final int NASIE = 12;
@ -121,7 +135,7 @@ public final class CopticCalendar extends CECalendar
super(year, month, date, hour, minute, second);
}
public static int CopticToJD(long year, int month, int date) {
public static int copticToJD(long year, int month, int date) {
return ceToJD(year, month, date, JD_EPOCH_OFFSET);
}