Search in sources :

Example 1 with HebrewCalendar

use of com.ibm.icu.util.HebrewCalendar in project mycore by MyCoRe-Org.

the class MCRCalendar method getCalendarFromHebrewDate.

/**
 * This method convert a HebrewCalendar date to a HebrewCalendar value. The
 * syntax for the hebrew input is [[t]t.][m]m.][yyy]y] or
 * [[yyy]y-[[m]m]-[[t]t].
 *
 * @param datestr
 *            the date as string.
 * @param last
 *            the value is true if the date should be filled with the
 *            highest value of month or day like 13 or 30 else it fill the
 *            date with the lowest value 1 for month and day.
 *
 * @return the HebewCalendar date value or null if an error was occurred.
 * @exception MCRException if parsing has an error
 */
protected static HebrewCalendar getCalendarFromHebrewDate(String datestr, boolean last) {
    try {
        int start = 0;
        datestr = datestr.trim();
        // german or ISO?
        start = 0;
        boolean iso = false;
        String token = ".";
        if (datestr.indexOf("-", start + 1) != -1) {
            iso = true;
            token = "-";
        }
        // 
        int firstdot = datestr.indexOf(token, start + 1);
        int secdot = -1;
        if (firstdot != -1) {
            secdot = datestr.indexOf(token, firstdot + 1);
        }
        int day = 0;
        int mon = 0;
        int year = 0;
        if (secdot != -1) {
            if (iso) {
                year = Integer.parseInt(datestr.substring(start, firstdot));
                mon = Integer.parseInt(datestr.substring(firstdot + 1, secdot)) - 1;
                day = Integer.parseInt(datestr.substring(secdot + 1, datestr.length()));
            } else {
                day = Integer.parseInt(datestr.substring(start, firstdot));
                mon = Integer.parseInt(datestr.substring(firstdot + 1, secdot)) - 1;
                year = Integer.parseInt(datestr.substring(secdot + 1, datestr.length()));
            }
        } else {
            if (firstdot != -1) {
                if (iso) {
                    year = Integer.parseInt(datestr.substring(start, firstdot));
                    mon = Integer.parseInt(datestr.substring(firstdot + 1, datestr.length())) - 1;
                } else {
                    mon = Integer.parseInt(datestr.substring(start, firstdot)) - 1;
                    year = Integer.parseInt(datestr.substring(firstdot + 1, datestr.length()));
                }
                if (last) {
                    if (mon == 0 || mon == 4 || mon == 7 || mon == 9 || mon == 11) {
                        day = 30;
                    } else {
                        day = 29;
                    }
                } else {
                    day = 1;
                }
            } else {
                year = Integer.parseInt(datestr.substring(start, datestr.length()));
                if (last) {
                    mon = 11;
                    day = 29;
                } else {
                    mon = 0;
                    day = 1;
                }
            }
        }
        HebrewCalendar hcal = new HebrewCalendar();
        hcal.set(year, mon, day);
        return hcal;
    } catch (Exception e) {
        throw new MCRException("The ancient hebrew date is false.", e);
    }
}
Also used : HebrewCalendar(com.ibm.icu.util.HebrewCalendar)

Aggregations

HebrewCalendar (com.ibm.icu.util.HebrewCalendar)1