ICU-4383 support for Ethiopic and Coptic Calendars
X-SVN-Rev: 17678
This commit is contained in:
parent
38a8d00feb
commit
054b67ba4b
@ -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;
|
||||
@ -96,35 +97,33 @@ public class CopticTest extends CalendarTest
|
||||
// because it's easier to edit that way.
|
||||
// Coptic
|
||||
// Julian Day Era Year Month Day WkDay Hour Min Sec
|
||||
//
|
||||
// Dates from "Emporer Theodore..."
|
||||
//
|
||||
// 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
|
||||
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
|
||||
new TestCase(1824664.5, 1, 0, 1, 1, THU, 0, 0, 0), // Gregorian: 30/08/0283
|
||||
new TestCase(1825029.5, 1, 1, 1, 1, FRI, 0, 0, 0), // Gregorian: 29/08/0284
|
||||
new TestCase(1825394.5, 1, 2, 1, 1, SAT, 0, 0, 0), // Gregorian: 29/08/0285
|
||||
new TestCase(1825759.5, 1, 3, 1, 1, SUN, 0, 0, 0), // Gregorian: 29/08/0286
|
||||
new TestCase(1826125.5, 1, 4, 1, 1, TUE, 0, 0, 0), // Gregorian: 30/08/0287
|
||||
new TestCase(1825028.5, 1, 0, 13, 5, THU, 0, 0, 0), // Gregorian: 28/08/0284
|
||||
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
|
||||
// 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
|
||||
|
||||
/* 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
|
||||
new TestCase(1824664.5, 1, 0, 1, 1, THU, 0, 0, 0), // Gregorian: 30/08/0283
|
||||
new TestCase(1825029.5, 1, 1, 1, 1, FRI, 0, 0, 0), // Gregorian: 29/08/0284
|
||||
new TestCase(1825394.5, 1, 2, 1, 1, SAT, 0, 0, 0), // Gregorian: 29/08/0285
|
||||
new TestCase(1825759.5, 1, 3, 1, 1, SUN, 0, 0, 0), // Gregorian: 29/08/0286
|
||||
new TestCase(1826125.5, 1, 4, 1, 1, TUE, 0, 0, 0), // Gregorian: 30/08/0287
|
||||
new TestCase(1825028.5, 1, 0, 13, 5, THU, 0, 0, 0), // Gregorian: 28/08/0284
|
||||
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(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();
|
||||
@ -156,78 +187,78 @@ public class CopticTest extends CalendarTest
|
||||
|
||||
public void TestCoverage() {
|
||||
|
||||
{
|
||||
// new CopticCalendar(TimeZone)
|
||||
CopticCalendar cal = new CopticCalendar(TimeZone.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with TimeZone");
|
||||
}
|
||||
}
|
||||
{
|
||||
// new CopticCalendar(TimeZone)
|
||||
CopticCalendar cal = new CopticCalendar(TimeZone.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with TimeZone");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new CopticCalendar(ULocale)
|
||||
CopticCalendar cal = new CopticCalendar(ULocale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with ULocale");
|
||||
}
|
||||
}
|
||||
{
|
||||
// new CopticCalendar(ULocale)
|
||||
CopticCalendar cal = new CopticCalendar(ULocale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new CopticCalendar(Locale)
|
||||
CopticCalendar cal = new CopticCalendar(Locale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with Locale");
|
||||
}
|
||||
}
|
||||
{
|
||||
// new CopticCalendar(Locale)
|
||||
CopticCalendar cal = new CopticCalendar(Locale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with Locale");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new CopticCalendar(Date)
|
||||
CopticCalendar cal = new CopticCalendar(new Date());
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with Date");
|
||||
}
|
||||
}
|
||||
{
|
||||
// new CopticCalendar(Date)
|
||||
CopticCalendar cal = new CopticCalendar(new Date());
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with Date");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new CopticCalendar(int year, int month, int date)
|
||||
CopticCalendar cal = new CopticCalendar(1997, CopticCalendar.TOUT, 1);
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with year,month,date");
|
||||
}
|
||||
}
|
||||
{
|
||||
// new CopticCalendar(int year, int month, int date)
|
||||
CopticCalendar cal = new CopticCalendar(1997, CopticCalendar.TOUT, 1);
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with year,month,date");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new CopticCalendar(int year, int month, int date, int hour, int minute, int second)
|
||||
CopticCalendar cal = new CopticCalendar(1997, CopticCalendar.TOUT, 1, 1, 1, 1);
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with year,month,date,hour,minute,second");
|
||||
}
|
||||
}
|
||||
{
|
||||
// new CopticCalendar(int year, int month, int date, int hour, int minute, int second)
|
||||
CopticCalendar cal = new CopticCalendar(1997, CopticCalendar.TOUT, 1, 1, 1, 1);
|
||||
if(cal == null){
|
||||
errln("could not create CopticCalendar with year,month,date,hour,minute,second");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// data
|
||||
CopticCalendar cal = new CopticCalendar(1997, CopticCalendar.TOUT, 1);
|
||||
Date time = cal.getTime();
|
||||
{
|
||||
// data
|
||||
CopticCalendar cal = new CopticCalendar(1997, CopticCalendar.TOUT, 1);
|
||||
Date time = cal.getTime();
|
||||
|
||||
String[] calendarLocales = {
|
||||
"am_ET", "gez_ET", "ti_ET"
|
||||
};
|
||||
String[] calendarLocales = {
|
||||
"am_ET", "gez_ET", "ti_ET"
|
||||
};
|
||||
|
||||
String[] formatLocales = {
|
||||
"en", "am", "gez", "ti"
|
||||
};
|
||||
for (int i = 0; i < calendarLocales.length; ++i) {
|
||||
String calLocName = calendarLocales[i];
|
||||
Locale calLocale = LocaleUtility.getLocaleFromName(calLocName);
|
||||
cal = new CopticCalendar(calLocale);
|
||||
String[] formatLocales = {
|
||||
"en", "am", "gez", "ti"
|
||||
};
|
||||
for (int i = 0; i < calendarLocales.length; ++i) {
|
||||
String calLocName = calendarLocales[i];
|
||||
Locale calLocale = LocaleUtility.getLocaleFromName(calLocName);
|
||||
cal = new CopticCalendar(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -121,41 +123,44 @@ public class EthiopicTest extends CalendarTest
|
||||
// because it's easier to edit that way.
|
||||
// Ethiopic
|
||||
// Julian Day Era Year Month Day WkDay Hour Min Sec
|
||||
//
|
||||
// Dates from "Emporer Theodore..."
|
||||
//
|
||||
// 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
|
||||
new TestCase(2402708.5, 1, 1858, 8, 10, TUE, 0, 0, 0), // Gregorian: 17/04/1866
|
||||
new TestCase(2402971.5, 1, 1859, 4, 28, SAT, 0, 0, 0), // Gregorian: 05/01/1867
|
||||
new TestCase(2403344.5, 1, 1860, 5, 5, MON, 0, 0, 0), // Gregorian: 13/01/1868
|
||||
|
||||
// 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
|
||||
|
||||
// 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
|
||||
|
||||
new TestCase(1723855.5, 1, 0, 1, 1, TUE, 0, 0, 0), // Gregorian: 28/08/0007
|
||||
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(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(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(1723855.5, 1, 0, 1, 1, TUE, 0, 0, 0), // Gregorian: 28/08/0007
|
||||
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(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 - 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
|
||||
|
||||
|
||||
new TestCase(2415020.5, 1, 1892, 4, 23, MON, 0, 0, 0), // Gregorian: 01/01/1900
|
||||
new TestCase(2453371.5, 1, 1997, 4, 23, SAT, 0, 0, 0), // Gregorian: 01/01/2005
|
||||
new TestCase(2454719.5, 1, 2000, 13, 5, WED, 0, 0, 0), // Gregorian: 10/09/2008
|
||||
@ -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();
|
||||
@ -184,105 +208,105 @@ public class EthiopicTest extends CalendarTest
|
||||
|
||||
public void TestCoverage() {
|
||||
|
||||
{
|
||||
// new EthiopicCalendar(TimeZone)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(TimeZone.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with TimeZone");
|
||||
}
|
||||
}
|
||||
{
|
||||
// new EthiopicCalendar(TimeZone)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(TimeZone.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with TimeZone");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new EthiopicCalendar(ULocale)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(ULocale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with ULocale");
|
||||
}
|
||||
}
|
||||
{
|
||||
// new EthiopicCalendar(ULocale)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(ULocale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with ULocale");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new EthiopicCalendar(Locale)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(Locale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with Locale");
|
||||
}
|
||||
}
|
||||
{
|
||||
// new EthiopicCalendar(Locale)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(Locale.getDefault());
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with Locale");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new EthiopicCalendar(Date)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(new Date());
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with Date");
|
||||
}
|
||||
}
|
||||
{
|
||||
// new EthiopicCalendar(Date)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(new Date());
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with Date");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new EthiopicCalendar(int year, int month, int date)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(1997, EthiopicCalendar.MESKEREM, 1);
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with year,month,date");
|
||||
}
|
||||
}
|
||||
{
|
||||
// new EthiopicCalendar(int year, int month, int date)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(1997, EthiopicCalendar.MESKEREM, 1);
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with year,month,date");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// new EthiopicCalendar(int year, int month, int date, int hour, int minute, int second)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(1997, EthiopicCalendar.MESKEREM, 1, 1, 1, 1);
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with year,month,date,hour,minute,second");
|
||||
}
|
||||
}
|
||||
{
|
||||
// new EthiopicCalendar(int year, int month, int date, int hour, int minute, int second)
|
||||
EthiopicCalendar cal = new EthiopicCalendar(1997, EthiopicCalendar.MESKEREM, 1, 1, 1, 1);
|
||||
if(cal == null){
|
||||
errln("could not create EthiopicCalendar with year,month,date,hour,minute,second");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// setCivil/isCivil
|
||||
// operations on non-civil calendar
|
||||
EthiopicCalendar cal = newAmeteAlemEraCalendar();
|
||||
cal.setAmeteAlemEra(false);
|
||||
if (cal.isAmeteAlemEra()) {
|
||||
errln("EthiopicCalendar calendar is old system");
|
||||
}
|
||||
{
|
||||
// setCivil/isCivil
|
||||
// operations on non-civil calendar
|
||||
EthiopicCalendar cal = newAmeteAlemEraCalendar();
|
||||
cal.setAmeteAlemEra(false);
|
||||
if (cal.isAmeteAlemEra()) {
|
||||
errln("EthiopicCalendar calendar is old system");
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
cal.setTime(now);
|
||||
Date now = new Date();
|
||||
cal.setTime(now);
|
||||
|
||||
Date then = cal.getTime();
|
||||
if (!now.equals(then)) {
|
||||
errln("get/set time failed with non-civil EthiopicCalendar calendar");
|
||||
}
|
||||
Date then = cal.getTime();
|
||||
if (!now.equals(then)) {
|
||||
errln("get/set time failed with non-civil EthiopicCalendar calendar");
|
||||
}
|
||||
|
||||
logln(then.toString());
|
||||
logln(then.toString());
|
||||
|
||||
cal.add(Calendar.MONTH, 1);
|
||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||
cal.add(Calendar.YEAR, 1);
|
||||
cal.add(Calendar.MONTH, 1);
|
||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||
cal.add(Calendar.YEAR, 1);
|
||||
|
||||
logln(cal.getTime().toString());
|
||||
}
|
||||
logln(cal.getTime().toString());
|
||||
}
|
||||
|
||||
{
|
||||
// data
|
||||
EthiopicCalendar cal = new EthiopicCalendar(1997, EthiopicCalendar.MESKEREM, 1);
|
||||
Date time = cal.getTime();
|
||||
{
|
||||
// data
|
||||
EthiopicCalendar cal = new EthiopicCalendar(1997, EthiopicCalendar.MESKEREM, 1);
|
||||
Date time = cal.getTime();
|
||||
|
||||
String[] calendarLocales = {
|
||||
"am_ET", "gez_ET", "ti_ET"
|
||||
};
|
||||
String[] calendarLocales = {
|
||||
"am_ET", "gez_ET", "ti_ET"
|
||||
};
|
||||
|
||||
String[] formatLocales = {
|
||||
"en", "am", "gez", "ti"
|
||||
};
|
||||
for (int i = 0; i < calendarLocales.length; ++i) {
|
||||
String calLocName = calendarLocales[i];
|
||||
Locale calLocale = LocaleUtility.getLocaleFromName(calLocName);
|
||||
cal = new EthiopicCalendar(calLocale);
|
||||
String[] formatLocales = {
|
||||
"en", "am", "gez", "ti"
|
||||
};
|
||||
for (int i = 0; i < calendarLocales.length; ++i) {
|
||||
String calLocName = calendarLocales[i];
|
||||
Locale calLocale = LocaleUtility.getLocaleFromName(calLocName);
|
||||
cal = new EthiopicCalendar(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static EthiopicCalendar newAmeteAlemEraCalendar() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -185,15 +183,10 @@ class CECalendar extends Calendar {
|
||||
* @param second The value used to set the calendar's {@link #SECOND SECOND} time field.
|
||||
*/
|
||||
protected CECalendar(int year, int month, int date, int hour,
|
||||
int minute, int second)
|
||||
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;
|
||||
}
|
||||
@ -253,18 +246,18 @@ class CECalendar extends Calendar {
|
||||
*/
|
||||
public static int ceToJD(long year, int month, int date, int jdEpochOffset) {
|
||||
|
||||
// Julian<->Ethiopic algorithms from:
|
||||
//"Calendars in Ethiopia", Berhanu Beyene, Manfred Kudlek, International Conference
|
||||
// of Ethiopian Studies XV, Hamburg, 2003
|
||||
// Julian<->Ethiopic algorithms from:
|
||||
// "Calendars in Ethiopia", Berhanu Beyene, Manfred Kudlek, International Conference
|
||||
// of Ethiopian Studies XV, Hamburg, 2003
|
||||
|
||||
return (int) (
|
||||
(jdEpochOffset+365) // difference from Julian epoch to 1,1,1
|
||||
+ 365 * (year - 1) // number of days from years
|
||||
+ quotient(year, 4) // extra day of leap year
|
||||
+ 30 * (month + 1) // number of days from months
|
||||
+ date // number of days for present month
|
||||
- 31 // slack?
|
||||
);
|
||||
+ 365 * (year - 1) // number of days from years
|
||||
+ quotient(year, 4) // extra day of leap year
|
||||
+ 30 * (month + 1) // number of days from months
|
||||
+ date // number of days for present month
|
||||
- 31 // slack?
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -272,15 +265,15 @@ class CECalendar extends Calendar {
|
||||
* @deprecated This is a draft API and might change in a future release of ICU.
|
||||
*/
|
||||
public static Integer[] getDateFromJD(int julianDay, int jdEpochOffset) {
|
||||
// 1461 is the number of days in 4 years
|
||||
// 1461 is the number of days in 4 years
|
||||
long r4 = mod(julianDay - jdEpochOffset, 1461); // number of days within a 4 year period
|
||||
long n = mod(r4, 365) + 365 * quotient(r4, 1460); // days in present year
|
||||
|
||||
long aprime = 4 // number of years in the leap year cycle
|
||||
* quotient(julianDay - jdEpochOffset, 1461) // number of 4 year periods between epochs?
|
||||
* quotient(julianDay - jdEpochOffset, 1461) // number of 4 year periods between epochs?
|
||||
+ quotient(r4, 365) // number of regular years?
|
||||
- quotient(r4, 1460) // number of 4 year periods?
|
||||
- 1;
|
||||
- 1;
|
||||
|
||||
int _year = (int) (aprime + 1);
|
||||
int _month = (int) (quotient(n, 30));
|
||||
@ -301,4 +294,3 @@ class CECalendar extends Calendar {
|
||||
return (int) Math.floor((double) i / j);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -81,11 +95,11 @@ public final class CopticCalendar extends CECalendar
|
||||
|
||||
// init base class value, common to all constructors
|
||||
{
|
||||
jdEpochOffset = JD_EPOCH_OFFSET;
|
||||
jdEpochOffset = JD_EPOCH_OFFSET;
|
||||
}
|
||||
|
||||
public CopticCalendar() {
|
||||
super();
|
||||
super();
|
||||
}
|
||||
|
||||
public CopticCalendar(TimeZone zone) {
|
||||
@ -109,24 +123,24 @@ public final class CopticCalendar extends CECalendar
|
||||
}
|
||||
|
||||
public CopticCalendar(int year, int month, int date) {
|
||||
super(year, month, date);
|
||||
super(year, month, date);
|
||||
}
|
||||
|
||||
public CopticCalendar(Date date) {
|
||||
super(date);
|
||||
super(date);
|
||||
}
|
||||
|
||||
public CopticCalendar(int year, int month, int date, int hour,
|
||||
int minute, int second) {
|
||||
super(year, month, date, hour, minute, second);
|
||||
super(year, month, date, hour, minute, second);
|
||||
}
|
||||
|
||||
public static int CopticToJD(long year, int month, int date) {
|
||||
return ceToJD(year, month, date, JD_EPOCH_OFFSET);
|
||||
public static int copticToJD(long year, int month, int date) {
|
||||
return ceToJD(year, month, date, JD_EPOCH_OFFSET);
|
||||
}
|
||||
|
||||
public static Integer[] getDateFromJD(int julianDay) {
|
||||
return getDateFromJD(julianDay, JD_EPOCH_OFFSET);
|
||||
return getDateFromJD(julianDay, JD_EPOCH_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user