ICU-4383 support for Ethiopic and Coptic Calendars
X-SVN-Rev: 17663
This commit is contained in:
parent
107d107089
commit
2331d4117d
233
icu4j/src/com/ibm/icu/dev/test/calendar/CopticTest.java
Normal file
233
icu4j/src/com/ibm/icu/dev/test/calendar/CopticTest.java
Normal file
@ -0,0 +1,233 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2005, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.calendar;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
import com.ibm.icu.util.Calendar;
|
||||
import com.ibm.icu.util.CopticCalendar;
|
||||
import com.ibm.icu.util.TimeZone;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
/**
|
||||
* Tests for the <code>CopticCalendar</code> class.
|
||||
*/
|
||||
public class CopticTest extends CalendarTest
|
||||
{
|
||||
public static void main(String args[]) throws Exception {
|
||||
new CopticTest().run(args);
|
||||
}
|
||||
|
||||
/** Constants to save typing. */
|
||||
public static final int TOUT = CopticCalendar.TOUT;
|
||||
public static final int BABA = CopticCalendar.BABA;
|
||||
public static final int HATOR = CopticCalendar.HATOR;
|
||||
public static final int KIAHK = CopticCalendar.KIAHK;
|
||||
public static final int TOBA = CopticCalendar.TOBA;
|
||||
public static final int AMSHIR = CopticCalendar.AMSHIR;
|
||||
public static final int BARAMHAT = CopticCalendar.BARAMHAT;
|
||||
public static final int BARAMOUDA = CopticCalendar.BARAMOUDA;
|
||||
public static final int BASHANS = CopticCalendar.BASHANS;
|
||||
public static final int PAONA = CopticCalendar.PAONA;
|
||||
public static final int EPEP = CopticCalendar.EPEP;
|
||||
public static final int MESRA = CopticCalendar.MESRA;
|
||||
public static final int NASIE = CopticCalendar.NASIE;
|
||||
|
||||
/* Test dates from:
|
||||
* "The Amharic Letters of Emperor Theodore of Ethiopia to Queen Victoria and
|
||||
* Her Special Envoy", David Appleyard, Girma Selasse Asfaw, Oxford University Press,
|
||||
* June 1 1979, ISBN: 0856726605, Longwood Pr Ltd
|
||||
*
|
||||
* Coptic Gregorian JD
|
||||
* 20/02/1579 29/10/1862 2401443
|
||||
* 29/10/1581 05/07/1865 2402423
|
||||
* 22/05/1582 29/01/1866 2402631
|
||||
* 10/08/1582 17/04/1866 2402709
|
||||
* 28/04/1583 05/01/1867 2402972
|
||||
* 05/05/1584 13/01/1868 2403345
|
||||
*
|
||||
* --------------------------------------------------
|
||||
*
|
||||
* From the Calendrica applet: http://emr.cs.iit.edu/home/reingold/calendar-book/Calendrica.html
|
||||
*
|
||||
* Coptic Gregorian JD
|
||||
* 07/05/-284 01/01/0000 1721060
|
||||
* 08/05/-283 01/01/0001 1721426
|
||||
* 06/13/-1 29/08/0283 1824664
|
||||
*
|
||||
* 01/01/0000 30/08/0283 1824665
|
||||
* 01/01/0001 29/08/0284 1825030
|
||||
* 01/01/0002 29/08/0285 1825395
|
||||
* 01/01/0003 29/08/0286 1825760
|
||||
* 01/01/0004 30/08/0287 1826126
|
||||
* 05/13/0000 28/08/0284 1825029
|
||||
* 05/13/0001 28/08/0285 1825394
|
||||
* 05/13/0002 28/08/0286 1825759
|
||||
* 05/13/0003 28/08/0287 1826124
|
||||
* 06/13/0003 29/08/0287 1826125 first coptic leap year
|
||||
* 05/13/0004 28/08/0288 1826490
|
||||
*
|
||||
* 06/02/1299 13/10/1582 2299159
|
||||
* 07/02/1299 14/10/1582 2299160 Julian 04/10/1582
|
||||
* 08/02/1299 15/10/1582 2299161
|
||||
* 09/02/1299 16/10/1582 2299162
|
||||
*
|
||||
* 23/04/1616 01/01/1900 2415021
|
||||
* 23/04/1721 01/01/2005 2453372
|
||||
* 05/13/2000 12/09/2284 2555529
|
||||
*/
|
||||
|
||||
|
||||
/** A huge list of test cases to make sure that computeTime and computeFields
|
||||
* work properly for a wide range of data in the civil calendar.
|
||||
*/
|
||||
public void TestCases()
|
||||
{
|
||||
final TestCase[] tests = {
|
||||
//
|
||||
// The months in this table are 1-based rather than 0-based,
|
||||
// because it's easier to edit that way.
|
||||
// Coptic
|
||||
// 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
|
||||
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
|
||||
|
||||
new TestCase(2415020.5, 1, 1616, 4, 23, MON, 0, 0, 0), // Gregorian: 01/01/1900
|
||||
new TestCase(2453371.5, 1, 1721, 4, 23, SAT, 0, 0, 0), // Gregorian: 01/01/2005
|
||||
new TestCase(2555528.5, 1, 2000, 13, 5, FRI, 0, 0, 0), // Gregorian: 12/09/2284
|
||||
};
|
||||
|
||||
CopticCalendar testCalendar = new CopticCalendar();
|
||||
testCalendar.setLenient(true);
|
||||
doTestCases(tests, testCalendar);
|
||||
}
|
||||
|
||||
public void TestBasic() {
|
||||
CopticCalendar cal = new CopticCalendar();
|
||||
cal.clear();
|
||||
cal.set(1000, 0, 30);
|
||||
logln("1000/0/30-> " +
|
||||
cal.get(YEAR) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(DATE));
|
||||
cal.clear();
|
||||
cal.set(1, 0, 30);
|
||||
logln("1/0/30 -> " +
|
||||
cal.get(YEAR) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(DATE));
|
||||
}
|
||||
|
||||
public void TestCoverage() {
|
||||
|
||||
{
|
||||
// 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(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(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");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// data
|
||||
CopticCalendar cal = new CopticCalendar(1997, CopticCalendar.TOUT, 1);
|
||||
Date time = cal.getTime();
|
||||
|
||||
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);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
293
icu4j/src/com/ibm/icu/dev/test/calendar/EthiopicTest.java
Normal file
293
icu4j/src/com/ibm/icu/dev/test/calendar/EthiopicTest.java
Normal file
@ -0,0 +1,293 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2005, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.test.calendar;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.ibm.icu.impl.LocaleUtility;
|
||||
import com.ibm.icu.text.DateFormat;
|
||||
import com.ibm.icu.util.Calendar;
|
||||
import com.ibm.icu.util.EthiopicCalendar;
|
||||
import com.ibm.icu.util.TimeZone;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
|
||||
/**
|
||||
* Tests for the <code>EthiopicCalendar</code> class.
|
||||
*/
|
||||
public class EthiopicTest extends CalendarTest
|
||||
{
|
||||
public static void main(String args[]) throws Exception {
|
||||
new EthiopicTest().run(args);
|
||||
}
|
||||
|
||||
/** Constants to save typing. */
|
||||
public static final int MESKEREM = EthiopicCalendar.MESKEREM;
|
||||
public static final int TEKEMT = EthiopicCalendar.TEKEMT;
|
||||
public static final int HEDAR = EthiopicCalendar.HEDAR;
|
||||
public static final int TAHSAS = EthiopicCalendar.TAHSAS;
|
||||
public static final int TER = EthiopicCalendar.TER;
|
||||
public static final int YEKATIT = EthiopicCalendar.YEKATIT;
|
||||
public static final int MEGABIT = EthiopicCalendar.MEGABIT;
|
||||
public static final int MIAZIA = EthiopicCalendar.MIAZIA;
|
||||
public static final int GENBOT = EthiopicCalendar.GENBOT;
|
||||
public static final int SENE = EthiopicCalendar.SENE;
|
||||
public static final int HAMLE = EthiopicCalendar.HAMLE;
|
||||
public static final int NEHASSE = EthiopicCalendar.NEHASSE;
|
||||
public static final int PAGUMEN = EthiopicCalendar.PAGUMEN;
|
||||
|
||||
/* DY[20050507] I don't know what this is for yet:
|
||||
public void TestRoll() {
|
||||
int[][] tests = new int[][] {
|
||||
// input roll by output
|
||||
// year month day field amount year month day
|
||||
|
||||
{ 0001, QIDAH, 2, MONTH, 1, 0001, HIJJAH, 2 }, // non-leap years
|
||||
{ 0001, QIDAH, 2, MONTH, 2, 0001, MUHARRAM, 2 },
|
||||
{ 0001, QIDAH, 2, MONTH, -1, 0001, SHAWWAL, 2 },
|
||||
{ 0001, MUHARRAM, 2, MONTH, 12, 0001, MUHARRAM, 2 },
|
||||
{ 0001, MUHARRAM, 2, MONTH, 13, 0001, SAFAR, 2 },
|
||||
|
||||
{ 0001, HIJJAH, 1, DATE, 30, 0001, HIJJAH, 2 }, // 29-day month
|
||||
{ 0002, HIJJAH, 1, DATE, 31, 0002, HIJJAH, 2 }, // 30-day month
|
||||
|
||||
// Try some rolls that require other fields to be adjusted
|
||||
{ 0001, MUHARRAM, 30, MONTH, 1, 0001, SAFAR, 29 },
|
||||
{ 0002, HIJJAH, 30, YEAR, -1, 0001, HIJJAH, 29 },
|
||||
};
|
||||
|
||||
EthiopicCalendar cal = newCivil();
|
||||
|
||||
doRollAdd(ROLL, cal, tests);
|
||||
}
|
||||
*/
|
||||
|
||||
/* Test dates from:
|
||||
* "The Amharic Letters of Emperor Theodore of Ethiopia to Queen Victoria and
|
||||
* Her Special Envoy", David Appleyard, Girma Selasse Asfaw, Oxford University Press,
|
||||
* June 1 1979, ISBN: 0856726605, Longwood Pr Ltd
|
||||
*
|
||||
* Ethiopic Gregorian JD
|
||||
* 20/02/1855 29/10/1862 2401443
|
||||
* 29/10/1857 05/07/1865 2402423
|
||||
* 22/05/1858 29/01/1866 2402631
|
||||
* 10/08/1858 17/04/1866 2402709
|
||||
* 28/04/1859 05/01/1867 2402972
|
||||
* 05/05/1860 13/01/1868 2403345
|
||||
*
|
||||
* --------------------------------------------------
|
||||
*
|
||||
* From the Calendrica applet: http://emr.cs.iit.edu/home/reingold/calendar-book/Calendrica.html
|
||||
*
|
||||
* Ethiopic Gregorian JD
|
||||
* 07/05/-8 01/01/0000 1721060
|
||||
* 08/05/-7 01/01/0001 1721426
|
||||
* 06/13/-1 27/08/0007 1723855
|
||||
*
|
||||
* 01/01/0000 28/08/0007 1723856
|
||||
* 01/01/0001 27/08/0008 1724221
|
||||
* 01/01/0002 27/08/0009 1724586
|
||||
* 01/01/0003 27/08/0010 1724951
|
||||
* 01/01/0004 28/08/0011 1724537
|
||||
* 05/13/0000 26/08/0008 1724220
|
||||
* 05/13/0001 26/08/0009 1724585
|
||||
* 05/13/0002 26/08/0010 1724950
|
||||
* 05/13/0003 26/08/0011 1725315
|
||||
* 06/13/0003 27/08/0011 1725316 first ethiopian leap year
|
||||
* 05/13/0004 26/08/0012 1725561
|
||||
*
|
||||
* 06/02/1575 13/10/1582 2299159
|
||||
* 07/02/1575 14/10/1582 2299160 Julian 04/10/1582
|
||||
* 08/02/1575 15/10/1582 2299161
|
||||
* 09/02/1575 16/10/1582 2299162
|
||||
*
|
||||
* 23/04/1892 01/01/1900 2415021
|
||||
* 23/04/1997 01/01/2005 2453372
|
||||
* 05/13/2000 10/09/2008 2454720
|
||||
*/
|
||||
|
||||
/** A huge list of test cases to make sure that computeTime and computeFields
|
||||
* work properly for a wide range of data in the civil calendar.
|
||||
*/
|
||||
public void TestCases()
|
||||
{
|
||||
final TestCase[] tests = {
|
||||
//
|
||||
// The months in this table are 1-based rather than 0-based,
|
||||
// because it's easier to edit that way.
|
||||
// Ethiopic
|
||||
// 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
|
||||
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
|
||||
|
||||
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(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
|
||||
};
|
||||
|
||||
EthiopicCalendar testCalendar = new EthiopicCalendar();
|
||||
testCalendar.setLenient(true);
|
||||
doTestCases(tests, testCalendar);
|
||||
}
|
||||
|
||||
public void TestBasic() {
|
||||
EthiopicCalendar cal = new EthiopicCalendar();
|
||||
cal.clear();
|
||||
cal.set(1000, 0, 30);
|
||||
logln("1000/0/30-> " +
|
||||
cal.get(YEAR) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(DATE));
|
||||
cal.clear();
|
||||
cal.set(1, 0, 30);
|
||||
logln("1/0/30 -> " +
|
||||
cal.get(YEAR) + "/" +
|
||||
cal.get(MONTH) + "/" +
|
||||
cal.get(DATE));
|
||||
}
|
||||
|
||||
public void TestCoverage() {
|
||||
|
||||
{
|
||||
// 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(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(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");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// 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 then = cal.getTime();
|
||||
if (!now.equals(then)) {
|
||||
errln("get/set time failed with non-civil EthiopicCalendar calendar");
|
||||
}
|
||||
|
||||
logln(then.toString());
|
||||
|
||||
cal.add(Calendar.MONTH, 1);
|
||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||
cal.add(Calendar.YEAR, 1);
|
||||
|
||||
logln(cal.getTime().toString());
|
||||
}
|
||||
|
||||
{
|
||||
// data
|
||||
EthiopicCalendar cal = new EthiopicCalendar(1997, EthiopicCalendar.MESKEREM, 1);
|
||||
Date time = cal.getTime();
|
||||
|
||||
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);
|
||||
|
||||
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() {
|
||||
EthiopicCalendar alemawiCalendar = new EthiopicCalendar();
|
||||
alemawiCalendar.setAmeteAlemEra(true);
|
||||
return alemawiCalendar;
|
||||
}
|
||||
}
|
@ -21,6 +21,8 @@ public class TestAll extends TestGroup {
|
||||
"AstroTest",
|
||||
"CalendarRegression",
|
||||
"CompatibilityTest",
|
||||
"CopticTest",
|
||||
"EthiopicTest",
|
||||
"HebrewTest",
|
||||
"IBMCalendarTest",
|
||||
"IslamicTest",
|
||||
|
304
icu4j/src/com/ibm/icu/util/CECalendar.java
Normal file
304
icu4j/src/com/ibm/icu/util/CECalendar.java
Normal file
@ -0,0 +1,304 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2005, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.util;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Base class for EthiopicCalendar and CopticCalendar.
|
||||
* @internal
|
||||
*/
|
||||
class CECalendar extends Calendar {
|
||||
|
||||
private static final int LIMITS[][] = {
|
||||
// Minimum Greatest Least Maximum
|
||||
// Minimum Maximum
|
||||
{0, 0, 1, 1 }, // ERA
|
||||
{1, 1, 5828963, 5838270 }, // YEAR
|
||||
{0, 0, 13, 13 }, // MONTH
|
||||
{1, 1, 52, 53 }, // WEEK_OF_YEAR
|
||||
{0, 0, 1, 6 }, // WEEK_OF_MONTH
|
||||
{1, 1, 5, 30 }, // DAY_OF_MONTH
|
||||
{1, 1, 365, 366 }, // DAY_OF_YEAR
|
||||
{/* */}, // DAY_OF_WEEK
|
||||
{-1, -1, 4, 6 }, // DAY_OF_WEEK_IN_MONTH
|
||||
{/* */}, // AM_PM
|
||||
{/* */}, // HOUR
|
||||
{/* */}, // HOUR_OF_DAY
|
||||
{/* */}, // MINUTE
|
||||
{/* */}, // SECOND
|
||||
{/* */}, // MILLISECOND
|
||||
{/* */}, // ZONE_OFFSET
|
||||
{/* */}, // DST_OFFSET
|
||||
{-5838270, -5838270, 5828964, 5838271}, // YEAR_WOY
|
||||
{/* */}, // DOW_LOCAL
|
||||
{-5838269, -5838269, 5828963, 5838270}, // EXTENDED_YEAR
|
||||
{/* */}, // JULIAN_DAY
|
||||
{/* */}, // MILLISECONDS_IN_DAY
|
||||
};
|
||||
|
||||
private static final int[][] ceMONTH_COUNT = {
|
||||
//len len2 st st2
|
||||
{30, 30, 0, 0}, // Meskerem
|
||||
{30, 30, 30, 30}, // Tekemt
|
||||
{30, 30, 60, 60}, // Hedar
|
||||
{30, 30, 90, 90}, // Tahsas
|
||||
{30, 30, 120, 120}, // Ter
|
||||
{30, 30, 150, 150}, // Yekatit
|
||||
{30, 30, 180, 180}, // Megabit
|
||||
{30, 30, 210, 210}, // Miazia
|
||||
{30, 30, 240, 244}, // Genbot
|
||||
{30, 30, 270, 270}, // Sene
|
||||
{30, 30, 300, 300}, // Hamle
|
||||
{30, 30, 330, 330}, // Nehasse
|
||||
{ 5, 6, 360, 360} // Pwagme
|
||||
// len length of month
|
||||
// len2 length of month in a leap year
|
||||
// st days in year before start of month
|
||||
// st2 days in year before month in leap year
|
||||
};
|
||||
|
||||
// The Coptic and Ethiopic calendars differ only in their epochs.
|
||||
// We handle this by setting the jdOffset to the difference between
|
||||
// the Julian and Coptic or Ethiopic epoch.
|
||||
// This value is set in the class initialization phase of the two
|
||||
// subclasses, CopticCalendar and EthiopicCalendar
|
||||
protected int jdEpochOffset = -1;
|
||||
|
||||
|
||||
protected int handleGetLimit(int field, int limitType) {
|
||||
return LIMITS[field][limitType];
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Constructors...
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs a default <code>CECalendar</code> using the current time
|
||||
* in the default time zone with the default locale.
|
||||
*/
|
||||
protected CECalendar() {
|
||||
this(TimeZone.getDefault(), ULocale.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>CECalendar</code> based on the current time
|
||||
* in the given time zone with the default locale.
|
||||
*
|
||||
* @param zone The time zone for the new calendar.
|
||||
*/
|
||||
protected CECalendar(TimeZone zone) {
|
||||
this(zone, ULocale.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>CECalendar</code> based on the current time
|
||||
* in the default time zone with the given locale.
|
||||
*
|
||||
* @param aLocale The locale for the new calendar.
|
||||
*/
|
||||
protected CECalendar(Locale aLocale) {
|
||||
this(TimeZone.getDefault(), aLocale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>CECalendar</code> based on the current time
|
||||
* in the default time zone with the given locale.
|
||||
*
|
||||
* @param locale The locale for the new calendar.
|
||||
*/
|
||||
protected CECalendar(ULocale locale) {
|
||||
this(TimeZone.getDefault(), locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>CECalendar</code> based on the current time
|
||||
* in the given time zone with the given locale.
|
||||
*
|
||||
* @param zone The time zone for the new calendar.
|
||||
*
|
||||
* @param aLocale The locale for the new calendar.
|
||||
*/
|
||||
protected CECalendar(TimeZone zone, Locale aLocale) {
|
||||
super(zone, aLocale);
|
||||
setTimeInMillis(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>CECalendar</code> based on the current time
|
||||
* in the given time zone with the given locale.
|
||||
*
|
||||
* @param zone The time zone for the new calendar.
|
||||
*
|
||||
* @param locale The locale for the new calendar.
|
||||
*/
|
||||
protected CECalendar(TimeZone zone, ULocale locale) {
|
||||
super(zone, locale);
|
||||
setTimeInMillis(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>CECalendar</code> with the given date set
|
||||
* in the default time zone with the default locale.
|
||||
*
|
||||
* @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
|
||||
*
|
||||
* @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
|
||||
* The value is 0-based. e.g., 0 for Tishri.
|
||||
*
|
||||
* @param date The value used to set the calendar's {@link #DATE DATE} time field.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>CECalendar</code> with the given date set
|
||||
* in the default time zone with the default locale.
|
||||
*
|
||||
* @param date The date to which the new calendar is set.
|
||||
*/
|
||||
protected CECalendar(Date date) {
|
||||
super(TimeZone.getDefault(), ULocale.getDefault());
|
||||
this.setTime(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>CECalendar</code> with the given date
|
||||
* and time set for the default time zone with the default locale.
|
||||
*
|
||||
* @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
|
||||
* @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
|
||||
* The value is 0-based. e.g., 0 for Tishri.
|
||||
* @param date The value used to set the calendar's {@link #DATE DATE} time field.
|
||||
* @param hour The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field.
|
||||
* @param minute The value used to set the calendar's {@link #MINUTE MINUTE} time field.
|
||||
* @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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Calendar system Converstion methods...
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected int handleComputeMonthStart(int eyear,
|
||||
int emonth,
|
||||
boolean useMonth) {
|
||||
|
||||
return ceToJD(eyear, emonth, 0, jdEpochOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected int handleGetExtendedYear() {
|
||||
int year;
|
||||
if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR) {
|
||||
year = internalGet(EXTENDED_YEAR, 1); // Default to year 1
|
||||
} else {
|
||||
year = internalGet(YEAR, 1); // Default to year 1
|
||||
}
|
||||
return year;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected void handleComputeFields(int julianDay) {
|
||||
Integer[] date = getDateFromJD(julianDay, jdEpochOffset);
|
||||
int _year = date[0].intValue();
|
||||
int _month = date[1].intValue();
|
||||
int _day = date[2].intValue();
|
||||
int ceyear = 0;
|
||||
|
||||
// Do we want to use EthiopicCalendar.AA, .AM here?
|
||||
int era = GregorianCalendar.AD;
|
||||
if (_year < 1) {
|
||||
era = GregorianCalendar.BC;
|
||||
ceyear = 1 - _year;
|
||||
}
|
||||
internalSet(MONTH, _month);
|
||||
internalSet(DAY_OF_MONTH, _day);
|
||||
internalSet(DAY_OF_YEAR, (30 * _month) + _day);
|
||||
internalSet(EXTENDED_YEAR, ceyear);
|
||||
internalSet(ERA, era);
|
||||
internalSet(YEAR, _year);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
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
|
||||
|
||||
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?
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @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
|
||||
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(r4, 365) // number of regular years?
|
||||
- quotient(r4, 1460) // number of 4 year periods?
|
||||
- 1;
|
||||
|
||||
int _year = (int) (aprime + 1);
|
||||
int _month = (int) (quotient(n, 30));
|
||||
int _day = mod(n, 30) + 1;
|
||||
|
||||
return new Integer[]{ new Integer(_year), new Integer(_month), new Integer(_day) };
|
||||
}
|
||||
|
||||
/**
|
||||
* These utility functions can be replaced by equivalent
|
||||
* functions from ICU if available.
|
||||
*/
|
||||
static int mod(long i, int j) {
|
||||
return (int) (i - (long) j * quotient(i, j));
|
||||
}
|
||||
|
||||
static int quotient(long i, int j) {
|
||||
return (int) Math.floor((double) i / j);
|
||||
}
|
||||
}
|
||||
|
132
icu4j/src/com/ibm/icu/util/CopticCalendar.java
Normal file
132
icu4j/src/com/ibm/icu/util/CopticCalendar.java
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2005, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.util;
|
||||
|
||||
import java.util.Date;
|
||||
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.
|
||||
*/
|
||||
public static final int TOUT = 0;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int HATOR = 2;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
public static final int BARAMOUDA = 7;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int PAONA = 9;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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,
|
||||
* the 13th month of the Coptic year.
|
||||
*/
|
||||
public static final int NASIE = 12;
|
||||
|
||||
private static final int JD_EPOCH_OFFSET = 1824665;
|
||||
|
||||
// init base class value, common to all constructors
|
||||
{
|
||||
jdEpochOffset = JD_EPOCH_OFFSET;
|
||||
}
|
||||
|
||||
public CopticCalendar() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CopticCalendar(TimeZone zone) {
|
||||
super(zone);
|
||||
}
|
||||
|
||||
public CopticCalendar(Locale aLocale) {
|
||||
super(aLocale);
|
||||
}
|
||||
|
||||
public CopticCalendar(ULocale locale) {
|
||||
super(locale);
|
||||
}
|
||||
|
||||
public CopticCalendar(TimeZone zone, Locale aLocale) {
|
||||
super(zone, aLocale);
|
||||
}
|
||||
|
||||
public CopticCalendar(TimeZone zone, ULocale locale) {
|
||||
super(zone, locale);
|
||||
}
|
||||
|
||||
public CopticCalendar(int year, int month, int date) {
|
||||
super(year, month, date);
|
||||
}
|
||||
|
||||
public CopticCalendar(Date date) {
|
||||
super(date);
|
||||
}
|
||||
|
||||
public CopticCalendar(int year, int month, int date, int hour,
|
||||
int minute, int 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 Integer[] getDateFromJD(int julianDay) {
|
||||
return getDateFromJD(julianDay, JD_EPOCH_OFFSET);
|
||||
}
|
||||
}
|
||||
|
165
icu4j/src/com/ibm/icu/util/EthiopicCalendar.java
Normal file
165
icu4j/src/com/ibm/icu/util/EthiopicCalendar.java
Normal file
@ -0,0 +1,165 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2005, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.util;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class EthiopicCalendar extends CECalendar
|
||||
{
|
||||
/**
|
||||
* Constant for \u1218\u1235\u12a8\u1228\u121d, the 1st month of the Ethiopic year.
|
||||
*/
|
||||
public static final int MESKEREM = 0;
|
||||
|
||||
/**
|
||||
* Constant for \u1325\u1245\u121d\u1275, the 2nd month of the Ethiopic year.
|
||||
*/
|
||||
public static final int TEKEMT = 1;
|
||||
|
||||
/**
|
||||
* Constant for \u1285\u12f3\u122d, the 3rd month of the Ethiopic year.
|
||||
*/
|
||||
public static final int HEDAR = 2;
|
||||
|
||||
/**
|
||||
* Constant for \u1273\u1285\u1223\u1225, the 4th month of the Ethiopic year.
|
||||
*/
|
||||
public static final int TAHSAS = 3;
|
||||
|
||||
/**
|
||||
* Constant for \u1325\u122d, the 5th month of the Ethiopic year.
|
||||
*/
|
||||
public static final int TER = 4;
|
||||
|
||||
/**
|
||||
* Constant for \u12e8\u12ab\u1272\u1275, the 6th month of the Ethiopic year.
|
||||
*/
|
||||
public static final int YEKATIT = 5;
|
||||
|
||||
/**
|
||||
* Constant for \u1218\u130b\u1262\u1275, the 7th month of the Ethiopic year.
|
||||
*/
|
||||
public static final int MEGABIT = 6;
|
||||
|
||||
/**
|
||||
* Constant for \u121a\u12eb\u12dd\u12eb, the 8th month of the Ethiopic year.
|
||||
*/
|
||||
public static final int MIAZIA = 7;
|
||||
|
||||
/**
|
||||
* Constant for \u130d\u1295\u1266\u1275, the 9th month of the Ethiopic year.
|
||||
*/
|
||||
public static final int GENBOT = 8;
|
||||
|
||||
/**
|
||||
* Constant for \u1230\u1294, the 10th month of the Ethiopic year.
|
||||
*/
|
||||
public static final int SENE = 9;
|
||||
|
||||
/**
|
||||
* Constant for \u1210\u121d\u120c, the 11th month of the Ethiopic year.
|
||||
*/
|
||||
public static final int HAMLE = 10;
|
||||
|
||||
/**
|
||||
* Constant for \u1290\u1210\u1234, the 12th month of the Ethiopic year.
|
||||
*/
|
||||
public static final int NEHASSE = 11;
|
||||
|
||||
/**
|
||||
* Constant for \u1333\u1309\u121c\u1295, the 13th month of the Ethiopic year.
|
||||
*/
|
||||
public static final int PAGUMEN = 12;
|
||||
|
||||
// Up until the end of the 19th century the prevailant convention was to
|
||||
// reference the Ethiopic Calendar from the creation of the world,
|
||||
// \u12d3\u1218\u1270\u1361\u12d3\u1208\u121d
|
||||
// (Amete Alem 5500 BC). As Ethiopia modernized the reference epoch from
|
||||
// the birth of Christ (\u12d3\u1218\u1270\u1361\u121d\u1215\u1228\u1275)
|
||||
// began to displace the creation of the
|
||||
// world reference point. However, years before the birth of Christ are
|
||||
// still referenced in the creation of the world system.
|
||||
// Thus -100 \u12d3/\u121d
|
||||
// would be rendered as 5400 \u12d3/\u12d3.
|
||||
//
|
||||
// The creation of the world in Ethiopic cannon was
|
||||
// Meskerem 1, -5500 \u12d3/\u121d 00:00:00
|
||||
// applying the birth of Christ reference and Ethiopian time conventions. This is
|
||||
// 6 hours less than the Julian epoch reference point (noon). In Gregorian
|
||||
// the date and time was July 18th -5493 BC 06:00 AM.
|
||||
|
||||
// Julian Days relative to the
|
||||
// \u12d3\u1218\u1270\u1361\u121d\u1215\u1228\u1275 epoch
|
||||
private static final int JD_EPOCH_OFFSET_AMETE_ALEM = -285019;
|
||||
|
||||
// Julian Days relative to the
|
||||
// \u12d3\u1218\u1270\u1361\u12d3\u1208\u121d epoch
|
||||
private static final int JD_EPOCH_OFFSET_AMETE_MIHRET = 1723856;
|
||||
|
||||
// initialize base class constant, common to all constructors
|
||||
{
|
||||
jdEpochOffset = JD_EPOCH_OFFSET_AMETE_MIHRET;
|
||||
}
|
||||
|
||||
public EthiopicCalendar() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EthiopicCalendar(TimeZone zone) {
|
||||
super(zone);
|
||||
}
|
||||
|
||||
public EthiopicCalendar(Locale aLocale) {
|
||||
super(aLocale);
|
||||
}
|
||||
|
||||
public EthiopicCalendar(ULocale locale) {
|
||||
super(locale);
|
||||
}
|
||||
|
||||
public EthiopicCalendar(TimeZone zone, Locale aLocale) {
|
||||
super(zone, aLocale);
|
||||
}
|
||||
|
||||
public EthiopicCalendar(TimeZone zone, ULocale locale) {
|
||||
super(zone, locale);
|
||||
}
|
||||
|
||||
public EthiopicCalendar(int year, int month, int date) {
|
||||
super(year, month, date);
|
||||
}
|
||||
|
||||
public EthiopicCalendar(Date date) {
|
||||
super(date);
|
||||
}
|
||||
|
||||
public EthiopicCalendar(int year, int month, int date, int hour,
|
||||
int minute, int second)
|
||||
{
|
||||
super(year, month, date, hour, minute, second);
|
||||
}
|
||||
|
||||
public static int EthiopicToJD(long year, int month, int date) {
|
||||
return ceToJD(year, month, date, JD_EPOCH_OFFSET_AMETE_MIHRET);
|
||||
}
|
||||
|
||||
public static Integer[] getDateFromJD(int julianDay) {
|
||||
return getDateFromJD(julianDay, JD_EPOCH_OFFSET_AMETE_MIHRET);
|
||||
}
|
||||
|
||||
public void setAmeteAlemEra(boolean onOff) {
|
||||
this.jdEpochOffset = onOff
|
||||
? JD_EPOCH_OFFSET_AMETE_ALEM
|
||||
: JD_EPOCH_OFFSET_AMETE_MIHRET;
|
||||
}
|
||||
|
||||
public boolean isAmeteAlemEra() {
|
||||
return this.jdEpochOffset == JD_EPOCH_OFFSET_AMETE_ALEM;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user