12ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/* GENERATED SOURCE. DO NOT MODIFY. */
2f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// © 2016 and later: Unicode, Inc. and others.
3f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html#License
42ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/*
52ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller *******************************************************************************
62ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Copyright (C) 2005-2011, International Business Machines Corporation and    *
72ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * others. All Rights Reserved.                                                *
82ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller *******************************************************************************
92ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */
102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpackage android.icu.util;
112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.util.Date;
132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.util.Locale;
142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.util.ULocale.Category;
162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/**
182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Base class for EthiopicCalendar and CopticCalendar.
192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */
202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerabstract class CECalendar extends Calendar {
212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    // jdk1.4.2 serialver
222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private static final long serialVersionUID = -999547623066414271L;
232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private static final int LIMITS[][] = {
252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // Minimum  Greatest    Least  Maximum
262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        //           Minimum  Maximum
272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {        0,        0,       1,       1 }, // ERA
282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {        1,        1, 5000000, 5000000 }, // YEAR
292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {        0,        0,      12,      12 }, // MONTH
302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {        1,        1,      52,      53 }, // WEEK_OF_YEAR
312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // WEEK_OF_MONTH
322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {        1,        1,       5,      30 }, // DAY_OF_MONTH
332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {        1,        1,     365,     366 }, // DAY_OF_YEAR
342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // DAY_OF_WEEK
352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {       -1,       -1,       1,       5 }, // DAY_OF_WEEK_IN_MONTH
362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // AM_PM
372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // HOUR
382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // HOUR_OF_DAY
392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // MINUTE
402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // SECOND
412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // MILLISECOND
422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // ZONE_OFFSET
432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // DST_OFFSET
442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        { -5000000, -5000000, 5000000, 5000000 }, // YEAR_WOY
452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // DOW_LOCAL
462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        { -5000000, -5000000, 5000000, 5000000 }, // EXTENDED_YEAR
472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // JULIAN_DAY
482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {/*                                  */}, // MILLISECONDS_IN_DAY
492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    };
502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    //-------------------------------------------------------------------------
522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    // Constructors...
532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    //-------------------------------------------------------------------------
542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Constructs a default <code>CECalendar</code> using the current time
572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * in the default time zone with the default <code>FORMAT</code> locale.
582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected CECalendar() {
602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT));
612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Constructs a <code>CECalendar</code> based on the current time
652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * in the given time zone with the default <code>FORMAT</code> locale.
662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param zone The time zone for the new calendar.
682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected CECalendar(TimeZone zone) {
702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this(zone, ULocale.getDefault(Category.FORMAT));
712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Constructs a <code>CECalendar</code> based on the current time
752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * in the default time zone with the given locale.
762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param aLocale The locale for the new calendar.
782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected CECalendar(Locale aLocale) {
802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this(TimeZone.getDefault(), aLocale);
812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Constructs a <code>CECalendar</code> based on the current time
852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * in the default time zone with the given locale.
862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param locale The locale for the new calendar.
882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected CECalendar(ULocale locale) {
902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this(TimeZone.getDefault(), locale);
912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Constructs a <code>CECalendar</code> based on the current time
952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * in the given time zone with the given locale.
962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param zone The time zone for the new calendar.
982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param aLocale The locale for the new calendar.
1002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected CECalendar(TimeZone zone, Locale aLocale) {
1022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        super(zone, aLocale);
1032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        setTimeInMillis(System.currentTimeMillis());
1042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Constructs a <code>CECalendar</code> based on the current time
1082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * in the given time zone with the given locale.
1092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
1102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param zone The time zone for the new calendar.
1112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
1122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param locale The locale for the new calendar.
1132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected CECalendar(TimeZone zone, ULocale locale) {
1152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        super(zone, locale);
1162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        setTimeInMillis(System.currentTimeMillis());
1172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Constructs a <code>CECalendar</code> with the given date set
1212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * in the default time zone with the default <code>FORMAT</code> locale.
1222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
1232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param year      The value used to set the calendar's {@link #YEAR YEAR} time field.
1242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
1252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param month     The value used to set the calendar's {@link #MONTH MONTH} time field.
1262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *                  The value is 0-based. e.g., 0 for Tishri.
1272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
1282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param date      The value used to set the calendar's {@link #DATE DATE} time field.
1292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected CECalendar(int year, int month, int date) {
1312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT));
1322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this.set(year, month, date);
1332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Constructs a <code>CECalendar</code> with the given date set
1372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * in the default time zone with the default <code>FORMAT</code> locale.
1382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
1392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param date      The date to which the new calendar is set.
1402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected CECalendar(Date date) {
1422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT));
1432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this.setTime(date);
1442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Constructs a <code>CECalendar</code> with the given date
1482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * and time set for the default time zone with the default <code>FORMAT</code> locale.
1492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *
1502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param year      The value used to set the calendar's {@link #YEAR YEAR} time field.
1512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param month     The value used to set the calendar's {@link #MONTH MONTH} time field.
1522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     *                  The value is 0-based. e.g., 0 for Tishri.
1532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param date      The value used to set the calendar's {@link #DATE DATE} time field.
1542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param hour      The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field.
1552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param minute    The value used to set the calendar's {@link #MINUTE MINUTE} time field.
1562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param second    The value used to set the calendar's {@link #SECOND SECOND} time field.
1572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected CECalendar(int year, int month, int date, int hour,
1592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                         int minute, int second)
1602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    {
1612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT));
1622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this.set(year, month, date, hour, minute, second);
1632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    //-------------------------------------------------------------------------
1662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    // Calendar framework
1672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    //-------------------------------------------------------------------------
1682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * The Coptic and Ethiopic calendars differ only in their epochs.
1712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * This method must be implemented by CECalendar subclasses to
1722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * return the date offset from Julian.
173ea97dc324dbed4b234b76f07b9ea4bbd2cc10f99Paul Duffin     * @hide unsupported on Android
1742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    abstract protected int getJDEpochOffset();
1762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Return JD of start of given month/extended year
1792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected int handleComputeMonthStart(int eyear,
1812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                                          int emonth,
1822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                                          boolean useMonth) {
1832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return ceToJD(eyear, emonth, 0, getJDEpochOffset());
1842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Calculate the limit for a specified type of limit and field
1882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected int handleGetLimit(int field, int limitType) {
1902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return LIMITS[field][limitType];
1912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    // (The following method is not called because all existing subclasses
1942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    // override it.
1952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    ///CLOVER:OFF
1962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Return the number of days in the given month of the given extended
1982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * year of this calendar system.  Subclasses should override this
1992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * method if they can provide a more correct or more efficient
2002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * implementation than the default implementation in Calendar.
2012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
2022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    protected int handleGetMonthLength(int extendedYear, int month)
2032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    {
2042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // The Ethiopian and Coptic calendars have 13 months, 12 of 30 days each and
2062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // an intercalary month at the end of the year of 5 or 6 days, depending whether
2072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // the year is a leap year or not. The Leap Year follows the same rules as the
2082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // Julian Calendar so that the extra month always has six days in the year before
2092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // a Julian Leap Year.
2102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if ((month + 1) % 13 != 0)
2112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {
2122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            // not intercalary month
2132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            return 30;
2142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
2152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        else
2162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        {
2172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            // intercalary month 5 days + possible leap day
2182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            return ((extendedYear % 4) / 3) + 5;
2192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
2202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
2222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    ///CLOVER:ON
2232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    //-------------------------------------------------------------------------
2252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    // Calendar framework
2262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    //-------------------------------------------------------------------------
2272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
2292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Convert an Coptic/Ethiopic year, month and day to a Julian day
2302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param year the extended year
2312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param month the month
2322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param day the day
2332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @return Julian day
234ea97dc324dbed4b234b76f07b9ea4bbd2cc10f99Paul Duffin     * @hide unsupported on Android
2352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
2362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public static int ceToJD(long year, int month, int day, int jdEpochOffset) {
2372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // Julian<->Ethiopic algorithms from:
2392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // "Calendars in Ethiopia", Berhanu Beyene, Manfred Kudlek, International Conference
2402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // of Ethiopian Studies XV, Hamburg, 2003
2412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // handle month > 12, < 0 (e.g. from add/set)
2432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if ( month >= 0 ) {
2442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            year += month/13;
2452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            month %= 13;
2462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        } else {
2472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            ++month;
2482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            year += month/13 - 1;
2492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            month = month%13 + 12;
2502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
2512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return (int) (
2522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            jdEpochOffset           // difference from Julian epoch to 1,1,1
2532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            + 365 * year            // number of days from years
2542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            + floorDivide(year, 4)  // extra day of leap year
2552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            + 30 * month            // number of days from months (months are 0-based)
2562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            + day - 1               // number of days for present month (1 based)
2572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            );
2582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
2592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
2612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Convert a Julian day to an Coptic/Ethiopic year, month and day
262ea97dc324dbed4b234b76f07b9ea4bbd2cc10f99Paul Duffin     * @hide unsupported on Android
2632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
2642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public static void jdToCE(int julianDay, int jdEpochOffset, int[] fields) {
2652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        int c4; // number of 4 year cycle (1461 days)
2662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        int[] r4 = new int[1]; // remainder of 4 year cycle, always positive
2672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        c4 = floorDivide(julianDay - jdEpochOffset, 1461, r4);
2692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // exteded year
2712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        fields[0] = 4 * c4 + (r4[0]/365 - r4[0]/1460); // 4 * <number of 4year cycle> + <years within the last cycle>
2722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        int doy = (r4[0] == 1460) ? 365 : (r4[0] % 365); // days in present year
2742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // month
2762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        fields[1] = doy / 30; // 30 -> Coptic/Ethiopic month length up to 12th month
2772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // day
2782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        fields[2] = (doy % 30) + 1; // 1-based days in a month
2792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
2802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller}
281