Package org.mycore.common
Class MCRCalendar
java.lang.Object
org.mycore.common.MCRCalendar
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:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptiona list of calendar tags they are supported in this classstatic final int
the Julian day of the first day in the armenian calendar, 1.1.1 arm = 13.7.552 gregstatic final int
the Julian day of the first day in the egyptian calendar, 1.1.1 eg = 18.2.747 BC gregstatic final int
Maximum Julian Day number is 3182057 = 28.01.4000static final int
Minimum Julian Day number is 0 = 01.01.4713 BCstatic final String
Tag for Armenian calendarstatic final String
Tag for Buddhistic calendarstatic final String
Tag for Chinese calendarstatic final String
Tag for Coptic calendarstatic final String
Tag for Egyptian calendarstatic final String
Tag for Ethiopic calendarstatic final String
Tag for Gregorian calendarstatic final String
Tag for Hebrew calendarstatic final String
Tag for Islamic calendarstatic final String
Tag for Japanese calendarstatic final String
Tag for Julian calendarstatic final String
Tag for Persic calendar -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
beforeZero
(String input, MCRCalendar.CalendarType calendarType) Returns true if the given date input is before the year zero of the given calendar type.static int[]
Calculates the borders of an armenian date.static int[]
calculateBuddhistDateBorders
(String datestr) Calculates the date borders for a Buddhist date in the form d.m.y [B.E.]static int[]
calculateCopticDateBorders
(String input) Calculates the borders of a coptic/ethiopian date.static int[]
calculateEgyptianDateBorders
(String datestr) Calculates the borders of an egyptian date.static int[]
calculateGregorianDateBorders
(String dateString) Calculates the date borders for a Gregorian date in the form d.m.y [N.static int[]
calculateHebrewDateBorders
(String input) Calculates the borders of a hebrew date.static int[]
calculateIslamicDateBorders
(String dateString) Calculates the borders of an islamic date.static int[]
Calculates the borders of a japanese date.static int[]
calculatePersianDateBorders
(String dateStr) Calculates the borders of a persian date.static String
cleanDate
(String input, MCRCalendar.CalendarType calendarType) Cleans a given date by removing era statements like -, AD, B.E. etc.static String
Returns the delimiter for the given date input: ., - or /.static String
getCalendarDateToFormattedString
(com.ibm.icu.util.Calendar calendar) This method returns the date as string in format 'yy-MM-dd G'.static String
getCalendarDateToFormattedString
(com.ibm.icu.util.Calendar calendar, String format) This method returns the date as string.protected static com.ibm.icu.util.GregorianCalendar
getCalendarFromArmenianDate
(String datestr, boolean last) This method convert a ArmenianCalendar date to a GregorianCalendar value.protected static com.ibm.icu.util.BuddhistCalendar
getCalendarFromBuddhistDate
(String datestr, boolean last) This method convert a BuddhistCalendar date to a IslamicCalendar value.protected static com.ibm.icu.util.CopticCalendar
getCalendarFromCopticDate
(String dateString, boolean last) This method convert a CopticCalendar date to a CopticCalendar value.protected static com.ibm.icu.util.GregorianCalendar
getCalendarFromEgyptianDate
(String datestr, boolean last) This method convert a EgyptianCalendar date to a GregorianCalendar value.protected static com.ibm.icu.util.EthiopicCalendar
getCalendarFromEthiopicDate
(String dateString, boolean last) This method convert a EthiopicCalendar date to a EthiopicCalendar value.protected static com.ibm.icu.util.GregorianCalendar
getCalendarFromGregorianDate
(String dateString, boolean last) This method convert a ancient date to a general Calendar value.protected static com.ibm.icu.util.HebrewCalendar
getCalendarFromHebrewDate
(String datestr, boolean last) This method convert a HebrewCalendar date to a HebrewCalendar value.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.protected static com.ibm.icu.util.JapaneseCalendar
getCalendarFromJapaneseDate
(String datestr, boolean last) This method convert a JapaneseCalendar date to a JapaneseCalendar value.protected static com.ibm.icu.util.Calendar
getCalendarFromJulianDate
(String dateString, boolean last) This method convert a JulianCalendar date to a general Calendar value.protected static com.ibm.icu.util.GregorianCalendar
getCalendarFromPersicDate
(String datestr, boolean last) This method convert a PersicCalendar date to a GregorianCalendar value.static String
getCalendarTypeString
(com.ibm.icu.util.Calendar calendar) This method returns the calendar type as string.static int
getFirstMonth
(MCRCalendar.CalendarType calendarType) Returns the first month of a year for the given calendar type, e.g.static com.ibm.icu.util.GregorianCalendar
getGregorianCalendarOfACalendar
(com.ibm.icu.util.Calendar calendar) This method get the Gregorian calendar form a given calendarstatic com.ibm.icu.util.Calendar
getHistoryDateAsCalendar
(String dateString, boolean last, String calendarString) This method check an ancient date string for the given calendar.static com.ibm.icu.util.Calendar
getHistoryDateAsCalendar
(String input, boolean last, MCRCalendar.CalendarType calendarType) 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.static int
getJulianDayNumber
(com.ibm.icu.util.Calendar calendar) This method return the Julian Day number for a given Calendar instance.static String
getJulianDayNumberAsString
(com.ibm.icu.util.Calendar calendar) This method return the Julian Day number for a given Calendar instance.static int
getLastDayOfMonth
(int month, int year, MCRCalendar.CalendarType calendarType) Returns the last day number for the given month, e.g.static int
getLastMonth
(int year, MCRCalendar.CalendarType calendarType) Returns the last month number of the given year for the given calendar type.static boolean
isLeapYear
(int year, MCRCalendar.CalendarType calendarType) Returns true, if the given year is a leap year in the given calendar type.static boolean
Returns true if the given input date is in ISO format (xx-xx-xx), otherwise false.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.
-
Field Details
-
TAG_BUDDHIST
Tag for Buddhistic calendar- See Also:
-
TAG_CHINESE
Tag for Chinese calendar- See Also:
-
TAG_COPTIC
Tag for Coptic calendar- See Also:
-
TAG_ETHIOPIC
Tag for Ethiopic calendar- See Also:
-
TAG_GREGORIAN
Tag for Gregorian calendar- See Also:
-
TAG_HEBREW
Tag for Hebrew calendar- See Also:
-
TAG_ISLAMIC
Tag for Islamic calendar- See Also:
-
TAG_JAPANESE
Tag for Japanese calendar- See Also:
-
TAG_JULIAN
Tag for Julian calendar- See Also:
-
TAG_PERSIC
Tag for Persic calendar- See Also:
-
TAG_ARMENIAN
Tag for Armenian calendar- See Also:
-
TAG_EGYPTIAN
Tag for Egyptian calendar- See Also:
-
MIN_JULIAN_DAY_NUMBER
public static final int MIN_JULIAN_DAY_NUMBERMinimum Julian Day number is 0 = 01.01.4713 BC- See Also:
-
MAX_JULIAN_DAY_NUMBER
public static final int MAX_JULIAN_DAY_NUMBERMaximum Julian Day number is 3182057 = 28.01.4000- See Also:
-
CALENDARS_LIST
a list of calendar tags they are supported in this class -
FIRST_ARMENIAN_DAY
public static final int FIRST_ARMENIAN_DAYthe 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_DAYthe 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) -
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
- [[[t]t.][m]m.][H|M|S|T|R][yyy]y
-
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
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
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 dateformat
- 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 stringuseLastValue
- as boolean - true if incomplete dates should be filled up with last month or last daycalendarName
- the name if the calendar defined in MCRCalendar- Returns:
- the date in format yyyy-MM-ddThh:mm:ssZ
-
getCalendarTypeString
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 parselast
- flag to determine if the last month or day of a month is to be used when no month or day is givencalendarType
- the calendar type to parse the date string for- Returns:
- a field containing year, month and day statements
-
isoFormat
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
Cleans a given date by removing era statements like -, AD, B.E. etc.- Parameters:
input
- the date to cleancalendarType
- the calendar type of the given date- Returns:
- the cleaned date containing only day, month and year statements
-
calculateEgyptianDateBorders
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
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
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
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
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
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
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
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
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
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
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 checkcalendarType
- the calendar type- Returns:
- true if the given input date is for the calendars zero date
-
getLastDayOfMonth
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 numberyear
- the yearcalendarType
- the calendar type to evaluate the last day for- Returns:
- the last day number for the given month
-
getFirstMonth
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
Returns the last month number of the given year for the given calendar type.- Parameters:
year
- the year to calculate last month number forcalendarType
- the calendar type- Returns:
- the last month number of the given year for the given calendar type
-
isLeapYear
Returns true, if the given year is a leap year in the given calendar type.- Parameters:
year
- the year to analysecalendarType
- the calendar type- Returns:
- true, if the given year is a leap year in the given calendar type; otherwise false
-