Class CalendarUtil


  • @Scriptable
    public final class CalendarUtil
    extends Object
    • Method Detail

      • modifyDate

        public static Date modifyDate​(Date p_dt,
                                      String p_strRules,
                                      TimeZone p_tz)
        Calls modifyDate(Date, String, TimeZone, boolean) with the fourth parameter set to false, so that the millisecond field of the date is not being touched if the given rules do not specify a rule for the millisecond field.
        Parameters:
        p_dt - The date to be modified.
        p_strRules - The rules (must neither be null nor empty).
        p_tz - The time zone to be used.
      • modifyDate

        public static Date modifyDate​(Date p_dt,
                                      String p_strRules,
                                      TimeZone p_tz,
                                      boolean p_bClearMillis)
        Modify the given date according to the rules specified in the p_strRules parameter.

        The rules consist of up to seven rules for each of the calendar fields YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND, in that order, and separated by commas. Each rule specifies either a positive or negative offset (e.g. -1, or +1), or an absolute value for the field (e.g. 15). Other than in the Java Calendar API, the month values are, 1-based, i.e. 1 = January, 2 = February, ...

        Example:
        +1,1,1,12,30,0,0 means the given date plus one year, the first of January, 12:30:00.0 on the 24-hour clock.

        Parameters:
        p_dt - The date to be modified.
        p_strRules - The rules (must neither be null nor empty).
        p_tz - The time zone to be used.
        p_bClearMillis - true if the calendar's millisecond field should be set to zero if the rule does not specify the millisecond field, or false otherwise.
        Returns:
        The date modified according to the given rules.
        Throws:
        IllegalArgumentException - If p_strRules is null or empty.
      • modifyDateInMillis

        public static long modifyDateInMillis​(Date p_dt,
                                              String p_strRules,
                                              TimeZone p_tz,
                                              boolean p_bClearMillis)
        Modify the given date according to the rules specified in the p_strRules parameter.

        The rules consist of up to seven rules for each of the calendar fields YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND, in that order, and separated by commas. Each rule specifies either a positive or negative offset (e.g. -1, or +1), or an absolute value for the field (e.g. 15). Other than in the Java Calendar API, the month values are, 1-based, i.e. 1 = January, 2 = February, ...

        Example:
        +1,1,1,12,30,0,0 means the given date plus one year, the first of January, 12:30:00.0 on the 24-hour clock.

        Parameters:
        p_dt - The date to be modified.
        p_strRules - The rules (must neither be null nor empty).
        p_tz - The time zone to be used.
        p_bClearMillis - true if the calendar's millisecond field should be set to zero if the rule does not specify the millisecond field, or false otherwise.
        Returns:
        The date in milliseconds since 1970-01-01 00:00:00 UTC, modified according to the given rules.
        Throws:
        IllegalArgumentException - If p_strRules is null or empty.
      • modifyCalendar

        public static <T extends Calendar> T modifyCalendar​(T p_cal,
                                                            String p_strRules)
        Calls modifyCalendar(Calendar, String, boolean) with the third parameter set to false, so that the millisecond field of the calendar is not being touched if the given rules do not specify a rule for the millisecond field.
        Parameters:
        p_cal - The calendar to be modified.
        p_strRules - The rules (must neither be null nor empty).
        Returns:
        The given calendar p_cal.
      • modifyCalendar

        public static <T extends Calendar> T modifyCalendar​(T p_cal,
                                                            String p_strRules,
                                                            boolean p_bClearMillis)
        Modify the given calendar according to the rules specified in the p_strRules parameter.

        The rules consist of up to seven rules for each of the calendar fields YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY, MINUTE, SECOND, and MILLISECOND, in that order, and separated by commas. Each rule specifies either a positive or negative offset (e.g. -1, or +1), or an absolute value for the field (e.g. 15). Other than in the Java Calendar API, the month values are, 1-based, i.e. 1 = January, 2 = February, ...

        Example:
        +1,1,1,12,30,0,0 means the given date plus one year, the first of January, 12:30:00.0 on the 24-hour clock.

        Parameters:
        p_cal - The calendar to be modified.
        p_strRules - The rules (must neither be null nor empty).
        p_bClearMillis - true if the calendar's millisecond field should be set to zero if the rule does not specify the millisecond field, or false otherwise.
        Returns:
        The given calendar p_cal.
        Throws:
        IllegalArgumentException - If p_strRules is null or empty.
      • getISO8601WeekNumber

        public static int getISO8601WeekNumber​(Date p_dt,
                                               TimeZone p_tz)
        Get the week number as defined in DIN 1355/ISO 8601.
        Parameters:
        p_dt - The date.
        p_tz - The time zone to be used.
        Returns:
        The week number as defined in DIN 1355/ISO 8601.
      • getISO8601WeekNumber

        public static int getISO8601WeekNumber​(int p_iYear,
                                               int p_iMonth,
                                               int p_iDay)
        Get the week number as defined in DIN 1355/ISO 8601.
        Parameters:
        p_iYear - The year.
        p_iMonth - The month (0 for January, ...).
        p_iDay - The day of month.
        Returns:
        The week number as defined in DIN 1355/ISO 8601.
      • getISO8601WeekStartOffset

        public static int getISO8601WeekStartOffset​(int p_iYear,
                                                    int p_iWeek)
        Get the offset in days of the first day of the given week, calculated from first of January of the given year.
        Parameters:
        p_iYear - The year.
        p_iWeek - The week (1 is the first week of the year, 2 the second ..., 0 ist the last week of the year before, ...).
        Returns:
        The offset in days.
      • getStartOfWeek

        public static Date getStartOfWeek​(Date p_dt,
                                          int p_iFirstDayOfWeek,
                                          TimeZone p_tz)
        Get the start of the week that contains the given date. Hour, minute, seconds, and fractions of seconds are set to zero.
        Parameters:
        p_dt - The date.
        p_iFirstDayOfWeek - The day the weeks starts with (1 for Sunday, 2 for Monday, ..., 7 for Saturday).
        p_tz - The time zone.
        Returns:
        The date that represents the requested start of the week.
      • getStartOfWeekInMillis

        public static long getStartOfWeekInMillis​(Date p_dt,
                                                  int p_iFirstDayOfWeek,
                                                  TimeZone p_tz)
        Get the start of the week that contains the given date. Hour, minute, seconds, and fractions of seconds are set to zero.
        Parameters:
        p_dt - The date.
        p_iFirstDayOfWeek - The day the weeks starts with (1 for Sunday, 2 for Monday, ..., 7 for Saturday).
        p_tz - The time zone.
        Returns:
        The time (in milliseconds since 1970-01-01Z00:00:00Z) that represents the requested start of the week.
        Throws:
        IllegalArgumentException - If p_iFirstDayOfWeek has an invalid value.
      • setStartOfWeek

        public static void setStartOfWeek​(Calendar p_cal,
                                          int p_iFirstDayOfWeek)
        Set the given calendar to the start of the week. Hour, minute, seconds, and fractions of seconds are set to zero.
        Parameters:
        p_cal - The calendar.
        p_iFirstDayOfWeek - The day the weeks starts with (1 for Sunday, 2 for Monday, ..., 7 for Saturday).
        Throws:
        IllegalArgumentException - If p_iFirstDayOfWeek has an invalid value.
        Since:
        Intrexx 7.0.
      • getQuarter

        public static int getQuarter​(Date p_dt,
                                     TimeZone p_tz)
        Get the quarter that contains the given date.
        Parameters:
        p_dt - The date.
        p_tz - The time zone.
        Returns:
        The quarter, i.e. either 1, 2, 3, or 4.
        Since:
        Intrexx 7.0.
      • getStartOfQuarter

        public static Date getStartOfQuarter​(Date p_dt,
                                             TimeZone p_tz)
        Get the start of the quarter that contains the given date. Hour, minute, seconds, and fractions of seconds are set to zero.
        Parameters:
        p_dt - The date.
        p_tz - The time zone.
        Returns:
        The date that represents the requested start of the quarter.
        Since:
        Intrexx 7.0.
      • getStartOfQuarterInMillis

        public static long getStartOfQuarterInMillis​(Date p_dt,
                                                     TimeZone p_tz)
        Get the start of the quarter that contains the given date. Hour, minute, seconds, and fractions of seconds are set to zero.
        Parameters:
        p_dt - The date.
        p_tz - The time zone.
        Returns:
        The time (in milliseconds since 1970-01-01Z00:00:00Z) that represents the requested start of the quarter.
        Since:
        Intrexx 7.0.
      • getNumberOfMidnightsBetween

        public static long getNumberOfMidnightsBetween​(Date p_dt1,
                                                       Date p_dt2,
                                                       TimeZone p_tz)
        Get the number of midnights between two dates in the give time zone.

        The result may be negative if the second date is before the first date.

        Parameters:
        p_dt1 - The first date.
        p_dt2 - The second date.
        p_tz - The time zone.
        Returns:
        Get the number of midnights between two dates.
      • getLunationNumber

        public static long getLunationNumber​(Date p_dt)
        Get the Brown Lunation Number.

        See Wikipedia: Lunation Number

        Parameters:
        p_dt - The date for which the lunation number should be calculated.
        Returns:
        The Brown Lunation Number.
      • getLunationNumber

        public static long getLunationNumber​(long p_lTime)
        Get the Brown Lunation Number.

        See Wikipedia: Lunation Number

        Parameters:
        p_lTime - The date for which the lunation number should be calculated.
        Returns:
        The Brown Lunation Number.
      • getMeeusLunationNumber

        public static long getMeeusLunationNumber​(Date p_dt)
        Get the Meeus Lunation Number.

        See Wikipedia: Lunation Number

        Parameters:
        p_dt - The date for which the lunation number should be calculated.
        Returns:
        The Brown Lunation Number.
      • getMeeusLunationNumber

        public static long getMeeusLunationNumber​(long p_lTime)
        Get the Meeus Lunation Number.

        See Wikipedia: Lunation Number

        Parameters:
        p_lTime - The date for which the lunation number should be calculated.
        Returns:
        The Brown Lunation Number.
      • getPhaseOfTheMoon

        public static double getPhaseOfTheMoon​(Date p_dt)
        Get the phase of the moon.

        The result is a value greater or equal zero, and less than one, representing the phase of the moon from new moon to new moon.

        Parameters:
        p_dt - The date for which the phase of the moon should be calculated.
        Returns:
        A value greater or equal zero, and less than one.
      • getPhaseOfTheMoon

        public static double getPhaseOfTheMoon​(long p_lTime)
        Get the phase of the moon.

        The result is a value greater or equal zero, and less than one, representing the phase of the moon from new moon to new moon.

        Parameters:
        p_lTime - The date for which the phase of the moon should be calculated.
        Returns:
        A value greater or equal zero, and less than one.
      • getShroveMondayDate

        public static Date getShroveMondayDate​(int p_iYear,
                                               TimeZone p_tz)
        Get the Shrove Monday (Rosenmontag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Shrove Monday date.
      • getShroveMondayDateInMillis

        public static long getShroveMondayDateInMillis​(int p_iYear,
                                                       TimeZone p_tz)
        Get the Shrove Monday (Rosenmontag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Shrove Monday date in milliseconds since January 1, 1970, 00:00:00 UTC.
      • getShroveMondayDate

        public static Date getShroveMondayDate​(Date p_dt,
                                               TimeZone p_tz)
        Get the Shrove Monday (Rosenmontag) date in the given year.
        Parameters:
        p_dt - The date to take the year from.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Shrove Monday date.
      • getAshWednesdayDate

        public static Date getAshWednesdayDate​(int p_iYear,
                                               TimeZone p_tz)
        Get the Ash Wednesday (Aschermittwoch) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Ash Wednesday date.
      • getAshWednesdayDateInMillis

        public static long getAshWednesdayDateInMillis​(int p_iYear,
                                                       TimeZone p_tz)
        Get the Ash Wednesday (Aschermittwoch) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Ash Wednesday date in milliseconds since January 1, 1970, 00:00:00 UTC.
      • getAshWednesdayDate

        public static Date getAshWednesdayDate​(Date p_dt,
                                               TimeZone p_tz)
        Get the Ash Wednesday (Aschermittwoch) date in the given year.
        Parameters:
        p_dt - The to take the year from.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Ash Wednesday date.
      • getMaundyThursdayDate

        public static Date getMaundyThursdayDate​(int p_iYear,
                                                 TimeZone p_tz)
        Get the Maundy Thursday (Gründonnerstag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Maundy Thursday date.
      • getMaundyThursdayDateInMillis

        public static long getMaundyThursdayDateInMillis​(int p_iYear,
                                                         TimeZone p_tz)
        Get the Maundy Thursday (Gründonnerstag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Maundy Thursday date in milliseconds since January 1, 1970, 00:00:00 UTC.
      • getMaundyThursdayDate

        public static Date getMaundyThursdayDate​(Date p_dt,
                                                 TimeZone p_tz)
        Get the Maundy Thursday (Gründonnerstag) date in the given year.
        Parameters:
        p_dt - The date to take the year from.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Maundy Thursday date.
      • getGoodFridayDate

        public static Date getGoodFridayDate​(int p_iYear,
                                             TimeZone p_tz)
        Get the Good Friday (Karfreitag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Good Friday date.
      • getGoodFridayDateInMillis

        public static long getGoodFridayDateInMillis​(int p_iYear,
                                                     TimeZone p_tz)
        Get the Good Friday (Karfreitag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Good Friday date in milliseconds since January 1, 1970, 00:00:00 UTC.
      • getGoodFridayDate

        public static Date getGoodFridayDate​(Date p_dt,
                                             TimeZone p_tz)
        Get the Good Friday (Karfreitag) date in the given year.
        Parameters:
        p_dt - The date to take the year from.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Good Friday date.
      • getEasterDate

        public static Date getEasterDate​(int p_iYear,
                                         TimeZone p_tz)
        Get the Easter (Ostersonntag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Easter date.
      • getEasterDateInMillis

        public static long getEasterDateInMillis​(int p_iYear,
                                                 TimeZone p_tz)
        Get the Easter (Ostersonntag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Easter date in milliseconds since January 1, 1970, 00:00:00 UTC.
      • getEasterDate

        public static Date getEasterDate​(Date p_dt,
                                         TimeZone p_tz)
        Get the Easter (Ostersonntag) date in the given year.
        Parameters:
        p_dt - The date to take the year from.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Easter date.
      • getEasterMondayDate

        public static Date getEasterMondayDate​(int p_iYear,
                                               TimeZone p_tz)
        Get the Easter Monday (Ostermontag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Easter Monday date.
      • getEasterMondayDateInMillis

        public static long getEasterMondayDateInMillis​(int p_iYear,
                                                       TimeZone p_tz)
        Get the Easter Monday (Ostermontag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Easter Monday date in milliseconds since January 1, 1970, 00:00:00 UTC.
      • getEasterMondayDate

        public static Date getEasterMondayDate​(Date p_dt,
                                               TimeZone p_tz)
        Get the Easter Monday (Ostermontag) date in the given year.
        Parameters:
        p_dt - The date to take the year from.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Easter Monday date.
      • getAscensionDate

        public static Date getAscensionDate​(int p_iYear,
                                            TimeZone p_tz)
        Get the Ascension Day (Christi Himmelfahrt) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Ascension Day date.
      • getAscensionDateInMillis

        public static long getAscensionDateInMillis​(int p_iYear,
                                                    TimeZone p_tz)
        Get the Ascension Day (Christi Himmelfahrt) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Ascension Day date in milliseconds since January 1, 1970, 00:00:00 UTC.
      • getAscensionDate

        public static Date getAscensionDate​(Date p_dt,
                                            TimeZone p_tz)
        Get the Ascension Day (Christi Himmelfahrt) date in the given year.
        Parameters:
        p_dt - The date to take the year from.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Ascension Day date.
      • getWhitSundayDate

        public static Date getWhitSundayDate​(int p_iYear,
                                             TimeZone p_tz)
        Get the Whit Sunday (Pfingstsonntag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Whit Sunday date.
      • getWhitSundayDateInMillis

        public static long getWhitSundayDateInMillis​(int p_iYear,
                                                     TimeZone p_tz)
        Get the Whit Sunday (Pfingstsonntag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Whit Sunday date in milliseconds since January 1, 1970, 00:00:00 UTC.
      • getWhitSundayDate

        public static Date getWhitSundayDate​(Date p_dt,
                                             TimeZone p_tz)
        Get the Whit Sunday (Pfingstsonntag) date in the given year.
        Parameters:
        p_dt - The date to take the year from.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Whit Sunday date.
      • getWhitMondayDate

        public static Date getWhitMondayDate​(int p_iYear,
                                             TimeZone p_tz)
        Get the Whit Monday (Pfingstmontag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Whit Monday date.
      • getWhitMondayDateInMillis

        public static long getWhitMondayDateInMillis​(int p_iYear,
                                                     TimeZone p_tz)
        Get the Whit Monday (Pfingstmontag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Whit Monday date in milliseconds since January 1, 1970, 00:00:00 UTC.
      • getWhitMondayDate

        public static Date getWhitMondayDate​(Date p_dt,
                                             TimeZone p_tz)
        Get the Whit Monday (Pfingstmontag) date in the given year.
        Parameters:
        p_dt - The date to take the year from.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Whit Monday date.
      • getPentecostDate

        public static Date getPentecostDate​(int p_iYear,
                                            TimeZone p_tz)
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Pentecost date.
      • getPentecostDateInMillis

        public static long getPentecostDateInMillis​(int p_iYear,
                                                    TimeZone p_tz)
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Pentecost date in milliseconds since January 1, 1970, 00:00:00 UTC.
      • getPentecostDate

        public static Date getPentecostDate​(Date p_dt,
                                            TimeZone p_tz)
        Parameters:
        p_dt - The date to take the year from.
        p_tz - The time zone in which this date should be created.
        Returns:
        The date.
      • getCorpusChristiDate

        public static Date getCorpusChristiDate​(int p_iYear,
                                                TimeZone p_tz)
        Get the Corpus Christi (Fronleichnam) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Corpus Christi date.
      • getCorpusChristiDateInMillis

        public static long getCorpusChristiDateInMillis​(int p_iYear,
                                                        TimeZone p_tz)
        Get the Corpus Christi (Fronleichnam) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Corpus Christi date in milliseconds since January 1, 1970, 00:00:00 UTC.
      • getCorpusChristiDate

        public static Date getCorpusChristiDate​(Date p_dt,
                                                TimeZone p_tz)
        Get the Corpus Christi (Fronleichnam) date in the given year.
        Parameters:
        p_dt - The date to take the year from.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Corpus Christi date.
      • getPenanceDayDate

        public static Date getPenanceDayDate​(int p_iYear,
                                             TimeZone p_tz)
        Get the Penance Day (Buß- und Bettag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Penance Day date.
      • getPenanceDayDateInMillis

        public static long getPenanceDayDateInMillis​(int p_iYear,
                                                     TimeZone p_tz)
        Get the Penance Day (Buß- und Bettag) date in the given year.
        Parameters:
        p_iYear - The year.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Penance Day date in milliseconds since January 1, 1970, 00:00:00 UTC.
      • getPenanceDayDate

        public static Date getPenanceDayDate​(Date p_dt,
                                             TimeZone p_tz)
        Get the Penance Day (Buß- und Bettag) date in the given year.
        Parameters:
        p_dt - The date to take the year from.
        p_tz - The time zone in which this date should be created.
        Returns:
        The Penance Day date.