Search in sources :

Example 1 with EthiopicCalendar

use of android.icu.util.EthiopicCalendar in project j2objc by google.

the class CopticTest method TestYear.

@Test
public void TestYear() {
    // Gregorian Calendar
    Calendar gCal = new GregorianCalendar();
    Date gToday = gCal.getTime();
    gCal.add(GregorianCalendar.MONTH, 2);
    Date gFuture = gCal.getTime();
    DateFormat gDF = DateFormat.getDateInstance(gCal, DateFormat.FULL);
    logln("gregorian calendar: " + gDF.format(gToday) + " + 2 months = " + gDF.format(gFuture));
    // Coptic Calendar
    CopticCalendar cCal = new CopticCalendar();
    Date cToday = cCal.getTime();
    cCal.add(CopticCalendar.MONTH, 2);
    Date cFuture = cCal.getTime();
    DateFormat cDF = DateFormat.getDateInstance(cCal, DateFormat.FULL);
    logln("coptic calendar: " + cDF.format(cToday) + " + 2 months = " + cDF.format(cFuture));
    // EthiopicCalendar
    EthiopicCalendar eCal = new EthiopicCalendar();
    Date eToday = eCal.getTime();
    // add 2 months
    eCal.add(EthiopicCalendar.MONTH, 2);
    eCal.setAmeteAlemEra(false);
    Date eFuture = eCal.getTime();
    DateFormat eDF = DateFormat.getDateInstance(eCal, DateFormat.FULL);
    logln("ethiopic calendar: " + eDF.format(eToday) + " + 2 months = " + eDF.format(eFuture));
}
Also used : EthiopicCalendar(android.icu.util.EthiopicCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) CopticCalendar(android.icu.util.CopticCalendar) EthiopicCalendar(android.icu.util.EthiopicCalendar) Calendar(android.icu.util.Calendar) SimpleDateFormat(android.icu.text.SimpleDateFormat) DateFormat(android.icu.text.DateFormat) GregorianCalendar(android.icu.util.GregorianCalendar) CopticCalendar(android.icu.util.CopticCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 2 with EthiopicCalendar

use of android.icu.util.EthiopicCalendar in project j2objc by google.

the class EthiopicTest method TestBasic.

@Test
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));
}
Also used : EthiopicCalendar(android.icu.util.EthiopicCalendar) Test(org.junit.Test)

Example 3 with EthiopicCalendar

use of android.icu.util.EthiopicCalendar in project j2objc by google.

the class EthiopicTest method TestJD.

@Test
public void TestJD() {
    int jd = EthiopicCalendar.EthiopicToJD(1567, 8, 9);
    EthiopicCalendar cal = new EthiopicCalendar();
    cal.clear();
    cal.set(Calendar.JULIAN_DAY, jd);
    if (cal.get(Calendar.EXTENDED_YEAR) == 1567 && cal.get(Calendar.MONTH) == 8 && cal.get(Calendar.DAY_OF_MONTH) == 9) {
        logln("EthiopicCalendar.getDateFromJD tested");
    } else {
        errln("EthiopicCalendar.getDateFromJD failed");
    }
}
Also used : EthiopicCalendar(android.icu.util.EthiopicCalendar) Test(org.junit.Test)

Example 4 with EthiopicCalendar

use of android.icu.util.EthiopicCalendar in project j2objc by google.

the class EthiopicTest method TestAddSet.

@Test
public void TestAddSet() {
    class TestAddSetItem {

        private int startYear;

        // 0-based
        private int startMonth;

        // 1-based
        private int startDay;

        private int fieldToChange;

        private int fieldDelta;

        private int endYear;

        private int endMonth;

        private int endDay;

        TestAddSetItem(int sYr, int sMo, int sDa, int field, int delta, int eYr, int eMo, int eDa) {
            startYear = sYr;
            startMonth = sMo;
            startDay = sDa;
            fieldToChange = field;
            fieldDelta = delta;
            endYear = eYr;
            endMonth = eMo;
            endDay = eDa;
        }

        public int getStartYear() {
            return startYear;
        }

        public int getStartMonth() {
            return startMonth;
        }

        public int getStartDay() {
            return startDay;
        }

        public int getField() {
            return fieldToChange;
        }

        public int getDelta() {
            return fieldDelta;
        }

        public int getEndYear() {
            return endYear;
        }

        public int getEndMonth() {
            return endMonth;
        }

        public int getEndDay() {
            return endDay;
        }
    }
    final TestAddSetItem[] tests = { new TestAddSetItem(2000, 12, 1, Calendar.MONTH, +1, 2001, 0, 1), new TestAddSetItem(2000, 12, 1, Calendar.MONTH, +9, 2001, 8, 1), // 1999 is a leap year
    new TestAddSetItem(1999, 12, 2, Calendar.MONTH, +1, 2000, 0, 2), new TestAddSetItem(1999, 12, 2, Calendar.MONTH, +9, 2000, 8, 2), new TestAddSetItem(2001, 0, 1, Calendar.MONTH, -1, 2000, 12, 1), new TestAddSetItem(2001, 0, 1, Calendar.MONTH, -6, 2000, 7, 1), new TestAddSetItem(2000, 12, 1, Calendar.DATE, +8, 2001, 0, 4), // 1999 is a leap year
    new TestAddSetItem(1999, 12, 1, Calendar.DATE, +8, 2000, 0, 3), new TestAddSetItem(2000, 0, 1, Calendar.DATE, -1, 1999, 12, 6) };
    EthiopicCalendar testCalendar = new EthiopicCalendar();
    for (int i = 0; i < tests.length; i++) {
        TestAddSetItem item = tests[i];
        testCalendar.set(item.getStartYear(), item.getStartMonth(), item.getStartDay(), 9, 0);
        testCalendar.add(item.getField(), item.getDelta());
        int endYear = testCalendar.get(Calendar.YEAR);
        int endMonth = testCalendar.get(Calendar.MONTH);
        int endDay = testCalendar.get(Calendar.DATE);
        if (endYear != item.getEndYear() || endMonth != item.getEndMonth() || endDay != item.getEndDay()) {
            errln("EToJD FAILS: field " + item.getField() + " delta " + item.getDelta() + " expected yr " + item.getEndYear() + " mo " + item.getEndMonth() + " da " + item.getEndDay() + " got yr " + endYear + " mo " + endMonth + " da " + endDay);
        }
    }
}
Also used : EthiopicCalendar(android.icu.util.EthiopicCalendar) Test(org.junit.Test)

Example 5 with EthiopicCalendar

use of android.icu.util.EthiopicCalendar in project j2objc by google.

the class EthiopicTest method TestLimits.

/**
 * Test limits of the Coptic calendar
 */
@Test
public void TestLimits() {
    Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 1);
    EthiopicCalendar ethiopic = new EthiopicCalendar();
    doLimitsTest(ethiopic, null, cal.getTime());
    doTheoreticalLimitsTest(ethiopic, true);
}
Also used : EthiopicCalendar(android.icu.util.EthiopicCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) EthiopicCalendar(android.icu.util.EthiopicCalendar) Calendar(android.icu.util.Calendar) Test(org.junit.Test)

Aggregations

EthiopicCalendar (android.icu.util.EthiopicCalendar)8 Test (org.junit.Test)7 GregorianCalendar (android.icu.util.GregorianCalendar)3 SimpleDateFormat (android.icu.text.SimpleDateFormat)2 Calendar (android.icu.util.Calendar)2 Date (java.util.Date)2 DateFormat (android.icu.text.DateFormat)1 CopticCalendar (android.icu.util.CopticCalendar)1