Class MCRCalendar

java.lang.Object
org.mycore.common.MCRCalendar

public class MCRCalendar extends Object
This class implements all methods for handling calendars in MyCoRe objects and data models. It is licensed by ICU License.
Version:
$Revision: 1.8 $ $Date: 2008/05/28 13:43:31 $
Author:
Jens Kupferschmidt, Thomas Junge
See Also:
  • Field Details

    • TAG_BUDDHIST

      public static final String TAG_BUDDHIST
      Tag for Buddhistic calendar
      See Also:
    • TAG_CHINESE

      public static final String TAG_CHINESE
      Tag for Chinese calendar
      See Also:
    • TAG_COPTIC

      public static final String TAG_COPTIC
      Tag for Coptic calendar
      See Also:
    • TAG_ETHIOPIC

      public static final String TAG_ETHIOPIC
      Tag for Ethiopic calendar
      See Also:
    • TAG_GREGORIAN

      public static final String TAG_GREGORIAN
      Tag for Gregorian calendar
      See Also:
    • TAG_HEBREW

      public static final String TAG_HEBREW
      Tag for Hebrew calendar
      See Also:
    • TAG_ISLAMIC

      public static final String TAG_ISLAMIC
      Tag for Islamic calendar
      See Also:
    • TAG_JAPANESE

      public static final String TAG_JAPANESE
      Tag for Japanese calendar
      See Also:
    • TAG_JULIAN

      public static final String TAG_JULIAN
      Tag for Julian calendar
      See Also:
    • TAG_PERSIC

      public static final String TAG_PERSIC
      Tag for Persic calendar
      See Also:
    • TAG_ARMENIAN

      public static final String TAG_ARMENIAN
      Tag for Armenian calendar
      See Also:
    • TAG_EGYPTIAN

      public static final String TAG_EGYPTIAN
      Tag for Egyptian calendar
      See Also:
    • MIN_JULIAN_DAY_NUMBER

      public static final int MIN_JULIAN_DAY_NUMBER
      Minimum Julian Day number is 0 = 01.01.4713 BC
      See Also:
    • MAX_JULIAN_DAY_NUMBER

      public static final int MAX_JULIAN_DAY_NUMBER
      Maximum Julian Day number is 3182057 = 28.01.4000
      See Also:
    • CALENDARS_LIST

      public static final List<String> CALENDARS_LIST
      a list of calendar tags they are supported in this class
    • FIRST_ARMENIAN_DAY

      public static final int FIRST_ARMENIAN_DAY
      the Julian day of the first day in the armenian calendar, 1.1.1 arm = 13.7.552 greg
    • FIRST_EGYPTIAN_DAY

      public static final int FIRST_EGYPTIAN_DAY
      the Julian day of the first day in the egyptian calendar, 1.1.1 eg = 18.2.747 BC greg
  • Constructor Details

    • MCRCalendar

      public MCRCalendar()
  • Method Details

    • getHistoryDateAsCalendar

      public static com.ibm.icu.util.Calendar getHistoryDateAsCalendar(String input, boolean last, MCRCalendar.CalendarType calendarType)
      See Also:
    • getHistoryDateAsCalendar

      public static com.ibm.icu.util.Calendar getHistoryDateAsCalendar(String dateString, boolean last, String calendarString) throws MCRException
      This method check an ancient date string for the given calendar. For syntax of the date string see javadocs of calendar methods.
      Parameters:
      dateString - the date as string.
      last - the value is true if the date should be filled with the highest value of month or day like 12 or 31 else it fill the date with the lowest value 1 for month and day.
      calendarString - the calendar name as String, kind of the calendars are ('gregorian', 'julian', 'islamic', 'buddhist', 'coptic', 'ethiopic', 'persic', 'japanese', 'armenian' or 'egyptian' )
      Returns:
      the ICU Calendar instance of the concrete calendar type or null if an error was occurred.
      Throws:
      MCRException - if parsing has an error
    • getCalendarFromGregorianDate

      protected static com.ibm.icu.util.GregorianCalendar getCalendarFromGregorianDate(String dateString, boolean last) throws MCRException
      This method convert a ancient date to a general Calendar value. The syntax for the gregorian input is:
      • [[[t]t.][m]m.][yyy]y [v. Chr.]
      • [[[t]t.][m]m.][yyy]y [AD|BC]
      • [-|AD|BC] [[[t]t.][m]m.][yyy]y
      • [[[t]t/][m]m/][yyy]y [AD|BC]
      • [-|AD|BC] [[[t]t/][m]m/][yyy]y
      • y[yyy][-m[m][-t[t]]] [v. Chr.]
      • y[yyy][-m[m][-t[t]]] [AD|BC]
      • [-|AD|BC] y[yyy][-m[m][-t[t]]]
      Parameters:
      dateString - the date as string.
      last - the value is true if the date should be filled with the highest value of month or day like 12 or 31 else it fill the date with the lowest value 1 for month and day.
      Returns:
      the GregorianCalendar date value or null if an error was occurred.
      Throws:
      MCRException - if parsing has an error
    • getCalendarFromJulianDate

      protected static com.ibm.icu.util.Calendar getCalendarFromJulianDate(String dateString, boolean last) throws MCRException
      This method convert a JulianCalendar date to a general Calendar value. The syntax for the julian input is:
      • [[[t]t.][m]m.][yyy]y [v. Chr.|n. Chr.]
      • [[[t]t.][m]m.][yyy]y [AD|BC]
      • [-|AD|BC] [[[t]t.][m]m.][yyy]y
      • [[[t]t/][m]m/][yyy]y [AD|BC]
      • [-|AD|BC] [[[t]t/][m]m/][yyy]y
      • y[yyy][-m[m][-t[t]]] [v. Chr.|n. Chr.]
      • y[yyy][-m[m][-t[t]]] [AD|BC]
      • [-|AD|BC] y[yyy][-m[m][-t[t]]]
      Parameters:
      dateString - the date as string.
      last - the value is true if the date should be filled with the highest value of month or day like 12 or 31 else it fill the date with the lowest value 1 for month and day.
      Returns:
      the GregorianCalendar date value or null if an error was occurred.
      Throws:
      MCRException - if parsing has an error
    • getCalendarFromIslamicDate

      protected static com.ibm.icu.util.IslamicCalendar getCalendarFromIslamicDate(String dateString, boolean last)
      This method converts an islamic calendar date to a IslamicCalendar value civil mode. The syntax for the islamic input is:
      • [[[t]t.][m]m.][yyy]y [H.|h.]
      • [.ه | .ه .ق] [[[t]t.][m]m.][yyy]y
      • y[yyy][-m[m][-t[t]]] H.|h.
      Parameters:
      dateString - the date as string.
      last - the value is true if the date should be filled with the highest value of month or day like 12 or 30 else it fill the date with the lowest value 1 for month and day.
      Returns:
      the IslamicCalendar date value or null if an error was occurred.
      Throws:
      MCRException - if parsing has an error
    • getCalendarFromHebrewDate

      protected static com.ibm.icu.util.HebrewCalendar getCalendarFromHebrewDate(String datestr, boolean last)
      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].
      Parameters:
      datestr - the date as string.
      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.
      Returns:
      the HebrewCalendar date value or null if an error was occurred.
      Throws:
      MCRException - if parsing has an error
    • getCalendarFromCopticDate

      protected static com.ibm.icu.util.CopticCalendar getCalendarFromCopticDate(String dateString, boolean last)
      This method convert a CopticCalendar date to a CopticCalendar value. The syntax for the coptic input is:
      • [[[t]t.][m]m.][yyy]y [[A.|a.]M.]
      • y[yyy][-m[m][-t[t]]] [A.|a.]M.]
      Parameters:
      dateString - the date as string.
      last - the value is true if the date should be filled with the highest value of month or day like 12 or 30 else it fill the date with the lowest value 1 for month and day.
      Returns:
      the CopticCalendar date value or null if an error was occurred.
      Throws:
      MCRException - if parsing has an error
    • getCalendarFromEthiopicDate

      protected static com.ibm.icu.util.EthiopicCalendar getCalendarFromEthiopicDate(String dateString, boolean last)
      This method convert a EthiopicCalendar date to a EthiopicCalendar value. The syntax for the ethiopic input is:
      • [[[t]t.][m]m.][yyy]y [E.E.]
      • y[yyy][-m[m][-t[t]]] [E.E.]
      Parameters:
      dateString - the date as string.
      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.
      Returns:
      the EthiopicCalendar date value or null if an error was occurred.
      Throws:
      MCRException - if parsing has an error
    • getCalendarFromJapaneseDate

      protected static com.ibm.icu.util.JapaneseCalendar getCalendarFromJapaneseDate(String datestr, boolean last)
      This method convert a JapaneseCalendar date to a JapaneseCalendar value. The syntax for the japanese input is:
      • [[[t]t.][m]m.][H|M|S|T|R][yyy]y
        H: Heisei; M: Meiji, S: Showa, T: Taiso, R: Reiwa
      • [H|M|S|T|R]y[yyy][-m[m][-t[t]]]
      Parameters:
      datestr - the date as string.
      last - the value is true if the date should be filled with the highest value of month or day like 12 or 30 else it fill the date with the lowest value 1 for month and day.
      Returns:
      the JapaneseCalendar date value or null if an error was occurred.
      Throws:
      MCRException - if parsing has an error
    • getCalendarFromBuddhistDate

      protected static com.ibm.icu.util.BuddhistCalendar getCalendarFromBuddhistDate(String datestr, boolean last)
      This method convert a BuddhistCalendar date to a IslamicCalendar value. The syntax for the buddhist input is:
      • [-][[[t]t.][m]m.][yyy]y [B.E.]
      • [-] [[[t]t.][m]m.][yyy]y
      • [-] y[yyy][-m[m][-t[t]]] [B.E.]
      • [-] y[yyy][-m[m][-t[t]]]
      Parameters:
      datestr - the date as string.
      last - the value is true if the date should be filled with the highest value of month or day like 12 or 31 else it fill the date with the lowest value 1 for month and day.
      Returns:
      the BuddhistCalendar date value or null if an error was occurred.
      Throws:
      MCRException - if parsing has an error
    • getCalendarFromPersicDate

      protected static com.ibm.icu.util.GregorianCalendar getCalendarFromPersicDate(String datestr, boolean last)
      This method convert a PersicCalendar date to a GregorianCalendar value. The syntax for the persian input is:
      • [-] [[[t]t.][m]m.][yyy]y
      • [-] y[yyy][-m[m][-t[t]]]
      Parameters:
      datestr - the date as string.
      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.
      Returns:
      the GregorianCalendar date value or null if an error was occurred.
      Throws:
      MCRException - if parsing has an error
    • getCalendarFromArmenianDate

      protected static com.ibm.icu.util.GregorianCalendar getCalendarFromArmenianDate(String datestr, boolean last)
      This method convert a ArmenianCalendar date to a GregorianCalendar value. The syntax for the Armenian input is [-][[t]t.][m]m.][yyy]y] or [-][[yyy]y-[[m]m]-[[t]t].
      • [-] [[[t]t.][m]m.][yyy]y
      • [-] y[yyy][-m[m][-t[t]]]
      Parameters:
      datestr - the date as string.
      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.
      Returns:
      the GregorianCalendar date value or null if an error was occurred.
      Throws:
      MCRException - if parsing has an error
    • getCalendarFromEgyptianDate

      protected static com.ibm.icu.util.GregorianCalendar getCalendarFromEgyptianDate(String datestr, boolean last)
      This method convert a EgyptianCalendar date to a GregorianCalendar value. The syntax for the egyptian (Nabonassar) input is:
      • [-][[[t]t.][m]m.][yyy]y [A.N.]
      • [-] [[[t]t.][m]m.][yyy]y
      • [-] y[yyy][-m[m][-t[t]]] [A.N.]
      • [-] y[yyy][-m[m][-t[t]]]

      For calculating the resulting Gregorian date, February, 18 747 BC is used as initial date for Egyptian calendar.

      Parameters:
      datestr - the date as string.
      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.
      Returns:
      the GregorianCalendar date value or null if an error was occurred.
    • getJulianDayNumber

      public static int getJulianDayNumber(com.ibm.icu.util.Calendar calendar)
      This method return the Julian Day number for a given Calendar instance.
      Returns:
      the Julian Day number as Integer
    • getJulianDayNumberAsString

      public static String getJulianDayNumberAsString(com.ibm.icu.util.Calendar calendar)
      This method return the Julian Day number for a given Calendar instance.
      Returns:
      the Julian Day number as String
    • getGregorianCalendarOfACalendar

      public static com.ibm.icu.util.GregorianCalendar getGregorianCalendarOfACalendar(com.ibm.icu.util.Calendar calendar)
      This method get the Gregorian calendar form a given calendar
      Parameters:
      calendar - an instance of a Calendar
      Returns:
      a Gregorian calendar
    • getCalendarDateToFormattedString

      public static String getCalendarDateToFormattedString(com.ibm.icu.util.Calendar calendar)
      This method returns the date as string in format 'yy-MM-dd G'.
      Returns:
      the date string
    • getCalendarDateToFormattedString

      public static String getCalendarDateToFormattedString(com.ibm.icu.util.Calendar calendar, String format)
      This method returns the date as string.
      Parameters:
      calendar - the Calendar date
      format - the format of the date as String
      Returns:
      the date string in the format. If the format is wrong dd.MM.yyyy G is set. If the date is wrong an empty string will be returned. The output is depending on calendar type. For Calendar it will use the Julian Calendar to 05.10.1582. Then it use the Gregorian Calendar.
    • getISODateToFormattedString

      public static String getISODateToFormattedString(String date, boolean useLastValue, String calendarName)
      The method get a date String in format yyyy-MM-ddThh:mm:ssZ for ancient date values.
      Parameters:
      date - the date string
      useLastValue - as boolean - true if incomplete dates should be filled up with last month or last day
      calendarName - the name if the calendar defined in MCRCalendar
      Returns:
      the date in format yyyy-MM-ddThh:mm:ssZ
    • getCalendarTypeString

      public static String getCalendarTypeString(com.ibm.icu.util.Calendar calendar)
      This method returns the calendar type as string.
      Parameters:
      calendar - the Calendar date
      Returns:
      The calendar type as string. If Calendar is empty an empty string will be returned.
    • parseDateString

      public static int[] parseDateString(String dateString, boolean last, MCRCalendar.CalendarType calendarType)
      Parses a clean date string in German (d.m.y), English (d/m/y) or ISO (y-m-d) form and returns the year, month and day as an array.
      Parameters:
      dateString - the date to parse
      last - flag to determine if the last month or day of a month is to be used when no month or day is given
      calendarType - the calendar type to parse the date string for
      Returns:
      a field containing year, month and day statements
    • isoFormat

      public static boolean isoFormat(String input)
      Returns true if the given input date is in ISO format (xx-xx-xx), otherwise false.
      Parameters:
      input - the input date to check
      Returns:
      true if the given input date is in ISO format (xx-xx-xx), otherwise false
    • cleanDate

      public static String cleanDate(String input, MCRCalendar.CalendarType calendarType)
      Cleans a given date by removing era statements like -, AD, B.E. etc.
      Parameters:
      input - the date to clean
      calendarType - the calendar type of the given date
      Returns:
      the cleaned date containing only day, month and year statements
    • calculateEgyptianDateBorders

      public static int[] calculateEgyptianDateBorders(String datestr)
      Calculates the borders of an egyptian date.
      Parameters:
      datestr - the egyptian date contain era statements like -, A.N.
      Returns:
      the indexes of the date string containing the date without era statements
    • calculateArmenianDateBorders

      public static int[] calculateArmenianDateBorders(String input)
      Calculates the borders of an armenian date.
      Parameters:
      input - the armenian date contain era statements like -
      Returns:
      the indexes of the date string containing the date without era statements
    • calculateJapaneseDateBorders

      public static int[] calculateJapaneseDateBorders(String input)
      Calculates the borders of a japanese date.
      Parameters:
      input - the japanese date contain era statements like -
      Returns:
      the indexes of the date string containing the date without era statements
    • calculatePersianDateBorders

      public static int[] calculatePersianDateBorders(String dateStr)
      Calculates the borders of a persian date.
      Parameters:
      dateStr - the persina date contain era statements like -
      Returns:
      the indexes of the date string containing the date without era statements
    • calculateCopticDateBorders

      public static int[] calculateCopticDateBorders(String input)
      Calculates the borders of a coptic/ethiopian date.
      Parameters:
      input - the coptic/ethiopian date contain era statements like -, A.M, A.E.
      Returns:
      the indexes of the date string containing the date without era statements
    • calculateHebrewDateBorders

      public static int[] calculateHebrewDateBorders(String input)
      Calculates the borders of a hebrew date.
      Parameters:
      input - the hebrew date contain era statements like -
      Returns:
      the indexes of the date string containing the date without era statements
    • calculateIslamicDateBorders

      public static int[] calculateIslamicDateBorders(String dateString)
      Calculates the borders of an islamic date.
      Parameters:
      dateString - the islamic date contain era statements like -
      Returns:
      the indexes of the date string containing the date without era statements
    • calculateGregorianDateBorders

      public static int[] calculateGregorianDateBorders(String dateString)
      Calculates the date borders for a Gregorian date in the form d.m.y [N. CHR|V.CHR|AD|BC]
      Parameters:
      dateString - the date string to parse
      Returns:
      a field containing the start position of the date string in index 0 and the end position in index 1
    • calculateBuddhistDateBorders

      public static int[] calculateBuddhistDateBorders(String datestr)
      Calculates the date borders for a Buddhist date in the form d.m.y [B.E.]
      Parameters:
      datestr - the date string to parse
      Returns:
      a field containing the start position of the date string in index 0 and the end position in index 1
    • delimiter

      public static String delimiter(String input)
      Returns the delimiter for the given date input: ., - or /.
      Parameters:
      input - the date input to check
      Returns:
      the delimiter for the given date input
    • beforeZero

      public static boolean beforeZero(String input, MCRCalendar.CalendarType calendarType)
      Returns true if the given date input is before the year zero of the given calendar type.

      Examples:

      • 1 BC is before zero for gregorian/julian calendars
      • -1 is before zero for all calendar types
      • 1 AD is after zero for gregorian/julian calendars
      • 1 is after zero for all calendar types
      Parameters:
      input - the input date to check
      calendarType - the calendar type
      Returns:
      true if the given input date is for the calendars zero date
    • getLastDayOfMonth

      public static int getLastDayOfMonth(int month, int year, MCRCalendar.CalendarType calendarType)
      Returns the last day number for the given month, e.g. Calendar.FEBRUARY has 28 in normal years and 29 days in leap years.
      Parameters:
      month - the month number
      year - the year
      calendarType - the calendar type to evaluate the last day for
      Returns:
      the last day number for the given month
    • getFirstMonth

      public static int getFirstMonth(MCRCalendar.CalendarType calendarType)
      Returns the first month of a year for the given calendar type, e.g. January for gregorian calendars.
      Parameters:
      calendarType - the calendar type to evaluate the first month for
      Returns:
      the first month of a year for the given calendar type
    • getLastMonth

      public static int getLastMonth(int year, MCRCalendar.CalendarType calendarType)
      Returns the last month number of the given year for the given calendar type.
      Parameters:
      year - the year to calculate last month number for
      calendarType - the calendar type
      Returns:
      the last month number of the given year for the given calendar type
    • isLeapYear

      public static boolean isLeapYear(int year, MCRCalendar.CalendarType calendarType)
      Returns true, if the given year is a leap year in the given calendar type.
      Parameters:
      year - the year to analyse
      calendarType - the calendar type
      Returns:
      true, if the given year is a leap year in the given calendar type; otherwise false