Class RhinoDate

java.lang.Object
io.higson.runtime.rhino.RhinoDate

public class RhinoDate extends Object

This is utility class for working with dates that are supported in Higson.

Author:
przemek hertel
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final String
     
    static final String
     
    static final String
     
    static final RhinoDate
     
    static final String
     
    static final String
     
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Date
    addDay(Object date, int amount)
    Adds amount to 'day' field that is based on given date.
    static Date
    addDay(Object date, Object amount)
    Adds amount to 'day' field that is based on given date.
    static Date
    addDay(Date date, int amount)
    Adds amount to 'day' field that is based on given date.
    static Date
    addHour(Object date, int amount)
    Adds amount to 'hour' field that is based on given date.
    static Date
    addHour(Object date, Object amount)
    Adds amount to 'hour' field that is based on given date.
    static Date
    addHour(Date date, int amount)
    Adds amount to 'hour' field that is based on given date.
    static Date
    addMinute(Object date, int amount)
    Adds amount to 'minute' field that is based on given date.
    1) If amount > 0, it will add minutes,
    2) If amount < 0, it will subtract minutes from date.
    When given date is: String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd HH:mm:ss.SSS formats, instance of DateHolder - it will try to retrieve date from holder, instance of other type - it will try to convert date to proper ValueHolder and then retrieve date. This method doesn't modify input date, but creates new instance of date type.
    static Date
    addMinute(Object date, Object amount)
    Adds amount to 'minute' field that is based on given date.
    static Date
    addMinute(Date date, int amount)
    Adds amount to 'minute' field that is based on given date.
    1) If amount > 0, it will add minutes,
    2) If amount < 0, it will subtract minutes from date.
    This method doesn't modify input date, but creates new instance of date type.
    static Date
    addMonth(Object date, int amount)
    Adds amount to 'month' field that is based on given date.
    static Date
    addMonth(Object date, Object amount)
    Adds amount to 'month' field that is based on given date.
    static Date
    addMonth(Date date, int amount)
    Adds amount to 'month' field that is based on given date.
    static Date
    addMonthOracle(Object date, int amount)
    Adds amount to 'month' field that is based on given date, but if day is last day of a given month, then moves day to the last possible day of a calculated month.
    1) If amount > 0, it will add months,
    2) If amount < 0, it will subtract months from date.
    When given date is: String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats, instance of DateHolder od NumberHolder - it will try to retrieve date from holder, instance of other type - it will try to convert date to proper ValueHolder and then retrieve date. This method doesn't modify input date, but creates new instance of date type.
    static Date
    addMonthOracle(Object date, Object amount)
    Adds amount to 'month' field that is based on given date, but if day is last day of a given month, then moves day to the last possible day of a calculated month.
    1) If amount > 0, it will add months,
    2) If amount < 0, it will subtract months from date.
    When given date is: String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats, instance of DateHolder od NumberHolder - it will try to retrieve date from holder, instance of other type - it will try to convert date to proper ValueHolder and then retrieve date. When given amount is: int type - If amount is positive it will add months, but if negative it will subtract months from date, instance of Number - it will try to retrieve int from number, instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer. This method doesn't modify input date, but creates new instance of date type.
    static Date
    addMonthOracle(Date date, int amount)
    Adds amount to 'month' field that is based on given date, but if day is last day of a given month, then moves day to the last possible day of a calculated month.
    1) If amount > 0, it will add months,
    2) If amount < 0, it will subtract months from date.
    This method doesn't modify input date, but creates new instance of date type.
    static Date
    addSecond(Object date, int amount)
    Adds amount to 'second' field that is based on given date.
    1) If amount > 0, it will add seconds,
    2) If amount < 0, it will subtract seconds from date.
    When given date is: String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd HH:mm:ss.SSS formats, instance of DateHolder - it will try to retrieve date from holder, instance of other type - it will try to convert date to proper ValueHolder and then retrieve date. This method doesn't modify input date, but creates new instance of date type.
    static Date
    addSecond(Object date, Object amount)
    Adds amount to 'second' field that is based on given date.
    1) If amount > 0, it will add seconds,
    2) If amount < 0, it will subtract seconds from date.
    When given date is: String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd HH:mm:ss.SSS formats, instance of DateHolder - it will try to retrieve date from holder, instance of other type - it will try to convert date to proper ValueHolder and then retrieve date. When given amount is: int type - If amount is positive it will add seconds, but if negative it will subtract seconds from date, instance of Number - it will try to retrieve int from number, instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer. This method doesn't modify input date, but creates new instance of date type.
    static Date
    addSecond(Date date, int amount)
    Adds amount to 'second' field that is based on given date.
    1) If amount > 0, it will add seconds,
    2) If amount < 0, it will subtract seconds from date.
    This method doesn't modify input date, but creates new instance of date type.
    static Date
    addYear(Object date, int amount)
    Adds amount to 'year' field that is based on given date.
    static Date
    addYear(Object date, Object amount)
    Adds amount to 'year' field that is based on given date.
    static Date
    addYear(Date date, int amount)
    Adds amount to 'year' field that is based on given date.
    static int
    compareYMD(Date date1, Date date2)
    Compares two dates by year, month, date.
    static Date
    copy(Date date)
    Creates copy of given date.
    static Date
    Deprecated.
    static Date
    Return current date with time set to 00:00:00.
    static Date
    Return current date with time.
    static String
    format(Date date)
    Returns String from date using yyyy-MM-dd format.
    static String
    format(Date date, String pattern)
    Returns String in given pattern from date.
    static String
    Returns String in dd-MM-yyyy pattern from date.
    static String
    formatTimestamp(long timestamp)
    Returns String from timestamp as long using yyyy-MM-dd HH:mm:ss.SSS format.
    static String
    Returns String from date using yyyy-MM-dd HH:mm:ss.SSS format.
    static Date
    fromInt(int date)
    It will try to convert given date as int to proper date instance.
    static int
    Calculates full years intervals between date1 and date2.
    static Date
    getDate(int year, int month, int day)
    Creates new date from given parameters without time.
    static Date
    getDate(int year, int month, int day, int hour, int minute)
    Creates new date from given parameters.
    static Date
    getDate(int year, int month, int day, int hour, int minute, int second)
    Creates new date from given parameters.
    static int
    getDay(Object date)
    Get day from date, but date must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats.
    static int
    getDayDiff(Object date1, Object date2)
    Returns difference of days between givens dates.
    static int
    getDayDiff(Object date1, Object date2, String pattern)
    Returns difference of days between givens dates.
    static int
    Deprecated.
    will be removed in future, use getDayDiff(java.lang.Object, java.lang.Object)
    static int
    getDaysBetween(Date date1, Date date2)
    Calculates full days intervals between date1 and date2.
    static int
    getDaysInYear(int year)
    Number of days in a given year.
    static Date
    Create new date based on given date, but set to first day of a month.
    static Date
    Create date with a beginning for a given year.
    static Date
    Create new date based on given date, but set to first day of a year.
    static Date
    Create date, that is set to the first work day of beginning of given year.
    static int
    getFullYearDiff(Date date1, Date date2)
    The same as getAbsoluteYearDiff(Object, Object), but it is not null safe.
    static int
    Get hour from date, but date must be in yyyy-MM-dd HH:mm:ss format.
    static int
    getHourDiff(Object date1, Object date2)
    Deprecated.
    Will be removed in the future
    static Date
    Create new date based on given date, but set to last day of a month.
    static Date
    Create new date based on given date, but set to last day of a year.
    static int
    Get minutes from date, but date must be in yyyy-MM-dd HH:mm:ss format.
    static int
    getMinuteDiff(Object date1, Object date2)
    Deprecated.
    Will be removed in the future
    static int
    Get month from date, but date must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats.
    static int
    getMonthDiff(Object date1, Object date2)
    Returns difference of months between givens dates.
    static int
    Deprecated.
    static int
    getMonthsBetween(Date date1, Date date2)
    Calculates full months intervals between date1 and date2.
    static Date
    Get closets work day from given date, but if given date is work date, it will return same instance.
    static Date
    Get next work day based on given date, but also verify polish holidays, and consider them during verification.
    static Date
    Get next working date from given date.
    static Set<Date>
    Returns set of polish holidays for given year, except these years that happen to occur during weekend.
    static int
    Get seconds from date, but date must be in yyyy-MM-dd HH:mm:ss format.
    Returns instance of SimpleDateFormat that is currently used in active Thread.
    static Date
    Deprecated.
    Will be removed in the future
    static int
    Get year from date, but date must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats.
    static int
    getYearDiff(Object date1, Object date2)
    Returns difference of years between givens dates.
    Possible outcomes: negative result if date1 > date2, positive result if date1 < date2, zero if there is no difference or any of given dates are null.
    static int
    getYearsBetween(Date date1, Date date2)
    Calculates full years intervals between date1 and date2.
    static boolean
    Checks if given date is both a first day of a month and a work day.
    static boolean
    isInPeriod(long d, long d1, long d2)
    Works the same as isInPeriod(Date, Date, Date), but for longs.
    static boolean
    isInPeriod(Date dateToCheck, Date minDateInclusive, Date maxDateExclusive)
    Checks if given dateToCheck is within boundaries.
    static boolean
    isInPeriodInclusive(long d, long d1, long d2)
    Works the same as isInPeriodInclusive(Date, Date, Date), but for longs.
    static boolean
    isInPeriodInclusive(Date dateToCheck, Date minDateInclusive, Date maxDateInclusive)
    Checks if given dateToCheck is within boundaries.
    static boolean
    Checks if given date is last date of a month.
    static boolean
    isLeapYear(int year)
    Verifies if given year is a leap year.
    static boolean
    Checks if given date is work date.
    static int
    julianDay(int year, int month, int day)
    Read more about here: http://en.wikipedia.org/wiki/Julian_day
    static int
    Read more about here: http://en.wikipedia.org/wiki/Julian_day
    static int
    julianDayDiff(Date date1, Date date2)
    Read more about here: http://en.wikipedia.org/wiki/Julian_day Difference between to julian days.
    static Date
    max(Date d1, Date d2)
    Checks which one of given dates is greater then the other.
    static Date
    max(Date d1, Date d2, Date d3)
    Checks which one of given dates is greater then the others.
    static Date
    min(Date d1, Date d2)
    Checks which one of given dates is smaller then the other.
    static Date
    min(Date d1, Date d2, Date d3)
    Checks which one of given dates is the earliest.
    static Date
    parse(Object date)
    Tries to parse given date with default pattern yyyy-MM-dd.
    static Date
    parse(Object date, Object pattern)
    Tries to parse given date for given object pattern.
    static Date
    parse(String dateStr)
    Tries to parse String for multiple supported formats and return date.
    static Date
    parse(String dateStr, String pattern)
    Tries to parse String for given format, then return date.
    static Date
    parseDMY(String dateString)
    Tries to parse given String in dd-MM-yyyy format.
    static Date
    Tries to parse given object in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats.
    static Date
    Tries to parse given date with default pattern yyyy-MM-dd.
    static Date
    parseNoEx(String date, String pattern)
    Tries to parse given date for given pattern String.
    static Date
    parseYMD(String dateString)
    Tries to parse given String in yyyy-MM-dd format.
    static Date
    rollDay(Object date, Object amount)
    Adds amount to the 'day' field without changing other fields.
    static Date
    rollHour(Object date, Object amount)
    Adds amount to the 'hour' field without changing other fields.
    static Date
    rollMinute(Object date, Object amount)
    Adds amount to the 'minute' field without changing other fields.
    static Date
    rollMonth(Object date, Object amount)
    Adds amount to the 'month' field without changing other fields.
    static Date
    rollSecond(Object date, Object amount)
    Adds amount to the 'second' field without changing other fields.
    static Date
    rollYear(Object date, Object amount)
    Adds amount to the 'year' field without changing other fields.
    static Date
    setDay(Object date, Object amount)
    Sets day for given date.
    static Date
    setHour(Object date, Object amount)
    Sets hour for given date.
    static Date
    setMinute(Object date, Object amount)
    Sets minute for given date.
    static Date
    setMonth(Object date, Object amount)
    Sets month for given date.
    static Date
    setSecond(Object date, Object amount)
    Sets second for given date.
    static Date
    setYear(Object date, Object amount)
    Sets year for given date.
    static Date
    Deprecated.
    will be removed in the future, use addYear(Date, int) with -1 amount.
    static int
    toInt(Date date)
    It will try to convert given date to int representation.
    static Date
    trim(Date date)
    Clearing time part of a given date.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • parse

      public static Date parse(String dateStr)
      Tries to parse String for multiple supported formats and return date. supported formats:
      • yyyy-MM-dd
      • yyyy.MM.dd
      • yyyy/MM/dd
      • dd-MM-yyyy
      • dd.MM.yyyy
      • dd/MM/yyyy

      Example:

      
       	DateType type = higson.getDateType();
       	assertThat(RhinoDate.parse("2018-10-29"), is(type.getDate("2018-10-29"));
       
      Parameters:
      dateStr - 10-characters date String
      Returns:
      Date parsed from String
      Throws:
      IllegalArgumentException - if Higson was not able to parse given String
    • parse

      public static Date parse(String dateStr, String pattern)
      Tries to parse String for given format, then return date.

      Example:

      
       	DateType type = higson.getDateType();
       	assertThat(RhinoDate.parse("2018-10-29", "yyyy-MM-dd"), is(type.getDate("2018-10-29"));
       
      Parameters:
      dateStr - date as String
      pattern - that matches given dateStr
      Returns:
      Date parsed from String
      Throws:
      IllegalArgumentException - if Higson was not able to parse given String
    • current

      @Deprecated public static Date current()
      Deprecated.
      Return current date with time.

      Example:

      
        Date date = RhinoDate.current();
       
      Returns:
      current date with time
    • currentDate

      public static Date currentDate()
      Return current date with time set to 00:00:00.

      Example:

      
        Date currentDate = RhinoDate.currentDate();
       
      Returns:
      current date with time set to 00:00:00
    • currentDatetime

      public static Date currentDatetime()
      Return current date with time.

      Example:

      
        Date date = RhinoDate.currentDatetime();
       
      Returns:
      current date with time
    • getSimpleDateFormat

      public static SimpleDateFormat getSimpleDateFormat(String pattern)
      Returns instance of SimpleDateFormat that is currently used in active Thread. If there was no such pattern used, then new instance is created and stored in memory.

      Example:

      
        SimpleDateFormat sdf = RhinoDate.getSimpleDateFormat("yyyy-MM-dd");
       
      Parameters:
      pattern - to be matched when looking for SimpleDateFormat instance
      Returns:
      same instance of SimpleDateFormat if exists, or fetches new instance
      Throws:
      IllegalArgumentException - if given pattern is invalid
    • parseDMY

      public static Date parseDMY(String dateString)
      Tries to parse given String in dd-MM-yyyy format.

      Example:

      
        Date date = RhinoDate.parseDMY("29-10-2018");
       
      Parameters:
      dateString - date as String
      Returns:
      current date with time
      Throws:
      IllegalArgumentException - if Higson was not able to parse given String
    • parseYMD

      public static Date parseYMD(String dateString)
      Tries to parse given String in yyyy-MM-dd format.

      Example:

      
        Date date = RhinoDate.parseDMY("2018-10-29");
       
      Parameters:
      dateString - date as String
      Returns:
      current date with time
      Throws:
      IllegalArgumentException - if Higson was not able to parse given String
    • parseLong

      public static Date parseLong(Object date)
      Tries to parse given object in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats.

      Example:

      
        Date date = RhinoDate.parseLong("2018-10-29");  // valid
        Date date = RhinoDate.parseLong("2018-10-29 12:45:66");  // valid
      
        Date input = RhinoDate.currentDate();
        Date date = RhinoDate.parseLong(input);         // valid
       
      Parameters:
      date - object to be parsed as date
      Returns:
      parsed date or null if parsing was not successful
    • parse

      public static Date parse(Object date)
      Tries to parse given date with default pattern yyyy-MM-dd. If given date is different type than String, then toString() on this object is invoked.

      Example:

      
        Date date = RhinoDate.parse("2018-10-29");  // valid
      
        Date input = RhinoDate.currentDate();
        Date date = RhinoDate.parse(input);         // valid
       
      Parameters:
      date - object to be parsed as date
      Returns:
      parsed date or null if parsing was not successful
    • parse

      public static Date parse(Object date, Object pattern)
      Tries to parse given date for given object pattern. Object pattern might be type of DateFormat or simple String format. If given date is different type than String, then toString() on this object is invoked.

      Example:

      
        Date date = RhinoDate.parse("2018-10-29", "yyyy-MM-dd");  // valid
      
        Date input = RhinoDate.currentDate();
        Date date = date.parse(input, "yyyy-MM-dd");         // valid
      
        Date input = RhinoDate.currentDate();
        CustomDateFormat cdf = ...;                // custom date format implementation
       	Date date = RhinoDate.parse(input, cdf);         // valid
       
      Parameters:
      date - object to be parsed as date
      pattern - object to be used for parsing date
      Returns:
      parsed date or null if parsing was not successful
      Throws:
      IllegalArgumentException - if given pattern is invalid
    • parseNoEx

      public static Date parseNoEx(String date)
      Tries to parse given date with default pattern yyyy-MM-dd.

      Example:

      
        Date date = RhinoDate.parseNoEx("2018-10-29");  // valid
        Date date = RhinoDate.parseNoEx("29-10-2018");  // valid, but return null
       
      Parameters:
      date - as String to be parsed
      Returns:
      parsed date or null if parsing was not successful
    • parseNoEx

      public static Date parseNoEx(String date, String pattern)
      Tries to parse given date for given pattern String.

      Example:

      
        Date date = RhinoDate.parseNoEx("2018-10-29", "yyyy-MM-dd");  // valid
        Date date = RhinoDate.parseNoEx("2018-10-29", "dd-MM-yyyy");  // null
       
      Parameters:
      date - as String to be parsed
      pattern - used for parsing date String
      Returns:
      parsed date or null if parsing was not successful
      Throws:
      IllegalArgumentException - if given pattern is invalid
    • format

      public static String format(Date date)
      Returns String from date using yyyy-MM-dd format.

      Example:

      
        Date date = higson.getDateType().decode("2018-10-29").getDate();
        String dateAsString = RhinoDate.format(date);
        assertThat(dateAsString, is("2018-10-29"));
       
      Parameters:
      date - to be formatted as String
      Returns:
      String from date using proper format
    • formatTimestamp

      public static String formatTimestamp(Date date)
      Returns String from date using yyyy-MM-dd HH:mm:ss.SSS format.

      Example:

      
        Date date = ctx.getDatetimeType().decode("2017-01-03 18:11:31.840").getValue();
        String dateAsString = RhinoDate.format(date);
        assertThat(dateAsString, is("2017-01-03 18:11:31.840"));
       
      Parameters:
      date - to be formatted as String
      Returns:
      String from date using proper format
    • formatTimestamp

      public static String formatTimestamp(long timestamp)
      Returns String from timestamp as long using yyyy-MM-dd HH:mm:ss.SSS format.

      Example:

      
        long timestamp = 1432894454862L;
        assertThat(RhinoDate.formatTimestamp(timestamp), is("2015-05-29 12:14:14.862"));
       
      Parameters:
      timestamp - to be formatted as String
      Returns:
      String from date using proper format
    • format

      public static String format(Date date, String pattern)
      Returns String in given pattern from date.

      Example:

      
        Date date = higson.getDatetimeType().decode("25-11-2018").getValue();
        String dateAsString = RhinoDate.format(date, "dd-MM-yyyy");
        assertThat(dateAsString, is("25-11-2018"));
       
      Parameters:
      date - to be formatted as String
      pattern - that date should be formatted against
      Returns:
      String from date using proper format
    • formatDMY

      public static String formatDMY(Date date)
      Returns String in dd-MM-yyyy pattern from date.

      Example:

      
        Date date = higson.getDatetimeType().decode("25-11-2018").getValue();
        String dateAsString = RhinoDate.formatDMY(date);
        assertThat(dateAsString, is("25-11-2018"));
       
      Parameters:
      date - to be formatted as String
      Returns:
      String from date using format
    • getYear

      public static int getYear(Object date)
      Get year from date, but date must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats.

      Example:

      
        int year = RhinoDate.getYear("2018-10-29");  // valid
        int year = RhinoDate.getYear("2018-10-29 18:11:31");  // valid
        int yearAsZero = RhinoDate.getYear("29-10-2018");  // not valid format
      
        assertThat(year, is(2018));
        assertThat(yearAsZero, is(0));
       
      Parameters:
      date - from which year is extracted
      Returns:
      0 if date is not properly parsed, otherwise year as int
    • getMonth

      public static int getMonth(Object date)
      Get month from date, but date must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats.

      Example:

      
        int month = RhinoDate.getMonth("2018-10-29");  // valid
        int month = RhinoDate.getMonth("2018-10-29 18:11:31");  // valid
        int monthAsZero = RhinoDate.getMonth("29-10-2018");  // not valid format
      
        assertThat(month, is(10));
        assertThat(monthAsZero, is(0));
       
      Parameters:
      date - from which month is extracted
      Returns:
      0 if date is not properly parsed, otherwise month as int
    • getDay

      public static int getDay(Object date)
      Get day from date, but date must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats.

      Example:

      
        int day = RhinoDate.getDay("2018-10-29");  // valid
        int day = RhinoDate.getDay("2018-10-29 18:11:31");  // valid
        int dayAsZero = RhinoDate.getDay("29-10-2018");  // not valid format
      
        assertThat(day, is(29));
        assertThat(dayAsZero, is(0));
       
      Parameters:
      date - from which day is extracted
      Returns:
      0 if date is not properly parsed, otherwise day as int
    • getHour

      public static int getHour(Object date)
      Get hour from date, but date must be in yyyy-MM-dd HH:mm:ss format.

      Example:

      
        int hour = RhinoDate.getHour("2018-10-29 18:11:31");  // valid
        int hourAsZero = RhinoDate.getHour("29-10-2018");  // not valid format
      
        assertThat(hour, is(18));
        assertThat(hourAsZero, is(0));
       
      Parameters:
      date - from which hour is extracted
      Returns:
      0 if hour is not properly parsed, otherwise hour as int
    • getMinute

      public static int getMinute(Object date)
      Get minutes from date, but date must be in yyyy-MM-dd HH:mm:ss format.

      Example:

      
        int minutes = RhinoDate.getMinute("2018-10-29 18:11:31");  // valid
        int minutesAsZero = RhinoDate.getMinute("29-10-2018");  // not valid format
      
        assertThat(minutes, is(11));
        assertThat(minutesAsZero, is(0));
       
      Parameters:
      date - from which minutes are extracted
      Returns:
      0 if minutes are not properly parsed, otherwise minutes as int
    • getSecond

      public static int getSecond(Object date)
      Get seconds from date, but date must be in yyyy-MM-dd HH:mm:ss format.

      Example:

      
        int seconds = RhinoDate.getSecond("2018-10-29 18:11:31");  // valid
        int secondsAsZero = RhinoDate.getSecond("29-10-2018");  // not valid format
      
        assertThat(seconds, is(31));
        assertThat(secondsAsZero, is(0));
       
      Parameters:
      date - from which seconds are extracted
      Returns:
      0 if seconds are not properly parsed, otherwise seconds as int
    • addYear

      public static Date addYear(Object date, Object amount)
      Adds amount to 'year' field that is based on given date.
      
       1) If amount > 0, it will add years,<br>
       2) If amount < 0, it will subtract years from date.<br>
       
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats,
      • instance of DateHolder od NumberHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      When given amount is:
      • int type - If amount is positive it will add years, but if negative it will subtract years from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = addYear("2018-11-13", 2);
        Date resultForNegativeAmount = addYear("2018-11-13", -2);
      
        assertThat(date.format(result), is("2020-11-13"));
        assertThat(date.format(resultForNegativeAmount), is("2016-11-13"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addYear

      public static Date addYear(Object date, int amount)
      Adds amount to 'year' field that is based on given date.
      
       1) If amount > 0, it will add years,
       2) If amount < 0, it will subtract years from date.
       
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats,
      • instance of DateHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = addYear("2018-11-13", 2);
        Date resultForNegativeAmount = addYear("2018-11-13", -2);
      
        assertThat(RhinoDate.format(result), is("2020-11-13"));
        assertThat(RhinoDate.format(resultForNegativeAmount), is("2016-11-13"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addYear

      public static Date addYear(Date date, int amount)
      Adds amount to 'year' field that is based on given date.
      
       1) If amount > 0, it will add years,<br>
       2) If amount < 0, it will subtract years from date.<br>
       
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date input = date.parse("2018-11-13");
        Date result = RhinoDate.addYear(input, 2);
        Date resultForNegativeAmount = RhinoDate.addYear(input, -2);
      
        assertThat(RhinoDate.format(result), is("2020-11-13"));
        assertThat(RhinoDate.format(resultForNegativeAmount), is("2016-11-13"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
    • addMonth

      public static Date addMonth(Object date, Object amount)
      Adds amount to 'month' field that is based on given date.
      
       1) If amount > 0, it will add months,<br>
       2) If amount < 0, it will subtract months from date.<br>
       
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats,
      • instance of DateHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      When given amount is:
      • int type - If amount is positive it will add months, but if negative it will subtract months from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.addMonth("2018-11-13", 2);
        Date resultForNegativeAmount = RhinoDate.addMonth("2018-11-13", -2);
      
        assertThat(RhinoDate.format(result), is("2019-01-13"));
        assertThat(RhinoDate.format(resultForNegativeAmount), is("2018-09-13"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addMonth

      public static Date addMonth(Object date, int amount)
      Adds amount to 'month' field that is based on given date.
      
       1) If amount > 0, it will add months,<br>
       2) If amount < 0, it will subtract months from date.<br>
       
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats,
      • instance of DateHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.addMonth("2018-11-13", 2);
        Date resultForNegativeAmount = RhinoDate.addMonth("2018-11-13", -2);
      
        assertThat(RhinoDate.format(result), is("2019-01-13"));
        assertThat(RhinoDate.format(resultForNegativeAmount), is("2018-09-13"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addMonth

      public static Date addMonth(Date date, int amount)
      Adds amount to 'month' field that is based on given date.
      
       1) If amount > 0, it will add months,<br>
       2) If amount < 0, it will subtract months from date.<br>
       
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date inputDate = new Date()
      
        Date result = RhinoDate.addMonth(inputDate, 2);
        Date resultForNegativeAmount = RhinoDate.addMonth(inputDate, -2);
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
    • addDay

      public static Date addDay(Object date, Object amount)
      Adds amount to 'day' field that is based on given date.
      
       1) If amount > 0, it will add days,<br>
       2) If amount < 0, it will subtract days from date.<br>
       
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats,
      • instance of DateHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      When given amount is:
      • int type - If amount is positive it will add days, but if negative it will subtract days from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.addDay("2018-11-13", 2);
       	Date resultForNegativeAmount = RhinoDate.addDay("2018-11-13", -2);
      
        assertThat(RhinoDate.format(result), is("2018-11-15"));
        assertThat(RhinoDate.format(resultForNegativeAmount), is("2018-11-11"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addDay

      public static Date addDay(Object date, int amount)
      Adds amount to 'day' field that is based on given date.
      
       1) If amount > 0, it will add days,<br>
       2) If amount < 0, it will subtract days from date.<br>
       
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats,
      • instance of DateHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.addDay("2018-11-13", 2);
        Date resultForNegativeAmount = RhinoDate.addDay("2018-11-13", -2);
      
        assertThat(RhinoDate.format(result), is("2018-11-15"));
        assertThat(RhinoDate.format(resultForNegativeAmount), is("2018-11-11"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addDay

      public static Date addDay(Date date, int amount)
      Adds amount to 'day' field that is based on given date.
      
       1) If amount > 0, it will add days,<br>
       2) If amount < 0, it will subtract days from date.<br>
       
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date inputDate = new Date()
      
        Date result = RhinoDate.addDay(inputDate, 2);
        Date resultForNegativeAmount = RhinoDate.addDay(inputDate, -2);
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
    • addHour

      public static Date addHour(Object date, Object amount)
      Adds amount to 'hour' field that is based on given date.
      
       1) If amount > 0, it will add hours,<br>
       2) If amount < 0, it will subtract hours from date.<br>
       
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd HH:mm:ss.SSS formats,
      • instance of DateHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      When given amount is:
      • int type - If amount is positive it will add days, but if negative it will subtract days from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.addHour("2018-01-03 18:11:31", 2);
        Date resultForNegativeAmount = RhinoDate.addHour("2018-01-03 18:11:31.840", -2);
      
        assertThat(RhinoDate.format(result), is("2018-01-03 20:11:31"));
        assertThat(RhinoDate.format(resultForNegativeAmount), is("2018-01-03 16:11:31.840"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addHour

      public static Date addHour(Object date, int amount)
      Adds amount to 'hour' field that is based on given date.
      
       1) If amount > 0, it will add hours,<br>
       2) If amount < 0, it will subtract hours from date.<br>
       
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd HH:mm:ss.SSS formats,
      • instance of DateHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.addHour("2018-01-03 18:11:31", 2);
       	Date resultForNegativeAmount = RhinoDate.addHour("2018-01-03 18:11:31.840", -2);
      
        assertThat(RhinoDate.format(result), is("2018-01-03 20:11:31"));
        assertThat(RhinoDate.format(resultForNegativeAmount), is("2018-01-03 16:11:31.840"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addHour

      public static Date addHour(Date date, int amount)
      Adds amount to 'hour' field that is based on given date.
      
       1) If amount > 0, it will add hours,
       2) If amount < 0, it will subtract hours from date.
       
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
       	Date inputDate = new Date();
        Date result = RhinoDate.addHour(inputDate, 2);
        Date resultForNegativeAmount = RhinoDate.addHour(inputDate, -2);
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
    • addMinute

      public static Date addMinute(Object date, Object amount)
      Adds amount to 'minute' field that is based on given date.
      
       1) If amount > 0, it will add minutes,<br>
       2) If amount < 0, it will subtract minutes from date.<br>
       
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd HH:mm:ss.SSS formats,
      • instance of DateHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      When given amount is:
      • int type - If amount is positive it will add minutes, but if negative it will subtract minutes from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.addMinute("2018-01-03 18:11:31", 20);
       	Date resultForNegativeAmount = RhinoDate.addMinute("2018-01-03 18:11:31.840", -20);
      
       	assertThat(RhinoDate.format(result), is("2018-01-03 18:31:31"));
       	assertThat(RhinoDate.format(resultForNegativeAmount), is("2018-01-03 17:51:31.840"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addMinute

      public static Date addMinute(Object date, int amount)
      Adds amount to 'minute' field that is based on given date.
      1) If amount > 0, it will add minutes,
      2) If amount < 0, it will subtract minutes from date.
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd HH:mm:ss.SSS formats,
      • instance of DateHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.addMinute("2018-01-03 18:11:31", 20);
       	Date resultForNegativeAmount = RhinoDate.addMinute("2018-01-03 18:11:31.840", -20);
      
        assertThat(RhinoDate.format(result), is("2018-01-03 18:31:31"));
        assertThat(RhinoDate.format(resultForNegativeAmount), is("2018-01-03 17:51:31.840"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addMinute

      public static Date addMinute(Date date, int amount)
      Adds amount to 'minute' field that is based on given date.
      1) If amount > 0, it will add minutes,
      2) If amount < 0, it will subtract minutes from date.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date inputDate = new Date();
        Date result = RhinoDate.addMinute(inputDate, 20);
        Date resultForNegativeAmount = RhinoDate.addMinute(inputDate, -20);
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
    • addSecond

      public static Date addSecond(Object date, Object amount)
      Adds amount to 'second' field that is based on given date.
      1) If amount > 0, it will add seconds,
      2) If amount < 0, it will subtract seconds from date.
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd HH:mm:ss.SSS formats,
      • instance of DateHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      When given amount is:
      • int type - If amount is positive it will add seconds, but if negative it will subtract seconds from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.addSecond("2018-01-03 18:11:31", 20);
        Date resultForNegativeAmount = RhinoDate.addSecond("2018-01-03 18:11:31.840", -20);
      
        assertThat(RhinoDate.format(result), is("2018-01-03 18:31:51"));
        assertThat(RhinoDate.format(resultForNegativeAmount), is("2018-01-03 18:11:11.840"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addSecond

      public static Date addSecond(Object date, int amount)
      Adds amount to 'second' field that is based on given date.
      1) If amount > 0, it will add seconds,
      2) If amount < 0, it will subtract seconds from date.
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd HH:mm:ss.SSS formats,
      • instance of DateHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.addSecond("2018-01-03 18:11:31", 20);
        Date resultForNegativeAmount = RhinoDate.addSecond("2018-01-03 18:11:31.840", -20);
      
        assertThat(RhinoDate.format(result), is("2018-01-03 18:31:51"));
        assertThat(RhinoDate.format(resultForNegativeAmount), is("2018-01-03 18:11:11.840"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addSecond

      public static Date addSecond(Date date, int amount)
      Adds amount to 'second' field that is based on given date.
      1) If amount > 0, it will add seconds,
      2) If amount < 0, it will subtract seconds from date.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date inputDate = new Date();
        Date result = RhinoDate.addMinute(inputDate, 20);
        Date resultForNegativeAmount = RhinoDate.addMinute(inputDate, -20);
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
    • setYear

      public static Date setYear(Object date, Object amount)
      Sets year for given date. Supported formats are yyyy-MM-dd HH:mm:ss or yyyy-MM-dd.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.setYear("2018-01-03 18:11:31", 2019);
        assertThat(RhinoDate.format(result), is("2019-01-03 18:11:31"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - int value, that is used for setting field
      Returns:
      new instance, that is combination of given date and amount
    • setMonth

      public static Date setMonth(Object date, Object amount)
      Sets month for given date. Supported formats are yyyy-MM-dd HH:mm:ss or yyyy-MM-dd.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.setMonth("2018-01-03 18:11:31", 5);
        assertThat(RhinoDate.format(result), is("2018-05-03 18:11:31"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - int value, that is used for setting field
      Returns:
      new instance, that is combination of given date and amount
    • setDay

      public static Date setDay(Object date, Object amount)
      Sets day for given date. Supported formats are yyyy-MM-dd HH:mm:ss or yyyy-MM-dd.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.setDay("2018-01-03 18:11:31", 5);
        assertThat(RhinoDate.format(result), is("2018-01-05 18:11:31"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - int value, that is used for setting field
      Returns:
      new instance, that is combination of given date and amount
    • setHour

      public static Date setHour(Object date, Object amount)
      Sets hour for given date. Supported formats are yyyy-MM-dd HH:mm:ss or yyyy-MM-dd.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.setHour("2018-01-03 18:11:31", 12);
        assertThat(RhinoDate.format(result), is("2018-01-03 12:11:31"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - int value, that is used for setting field
      Returns:
      new instance, that is combination of given date and amount
    • setMinute

      public static Date setMinute(Object date, Object amount)
      Sets minute for given date. Supported formats are yyyy-MM-dd HH:mm:ss or yyyy-MM-dd.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.setMinute("2018-01-03 18:11:31", 12);
        assertThat(RhinoDate.format(result), is("2018-01-03 18:12:31"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - int value, that is used for setting field
      Returns:
      new instance, that is combination of given date and amount
    • setSecond

      public static Date setSecond(Object date, Object amount)
      Sets second for given date. Supported formats are yyyy-MM-dd HH:mm:ss or yyyy-MM-dd.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.setSecond("2018-01-03 18:11:31", 12);
        assertThat(RhinoDate.format(result), is("2018-01-03 18:11:12"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - int value, that is used for setting field
      Returns:
      new instance, that is combination of given date and amount
    • rollYear

      public static Date rollYear(Object date, Object amount)
      Adds amount to the 'year' field without changing other fields. A negative roll amount means to subtract from year without changing other fields. If the specified amount is 0, this method performs nothing.
      When given date is:
      • String type - must be in yyyy-MM-dd or yyyy-MM-dd HH:mm:ss formats.
      • Date type - no need for parsing
      When given amount is:
      • int type - If amount is positive it will add years, but if negative it will subtract years from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      Date date = parse("2018-01-02"); assertThat(rollYear(date, 2), is(parse("2020-01-02")));
      Parameters:
      date - based on which new date will be created with change
      amount - int value, that is used for setting field
      Returns:
      new instance, that is combination of given date and amount
    • rollMonth

      public static Date rollMonth(Object date, Object amount)
      Adds amount to the 'month' field without changing other fields. A negative roll amount means to subtract from month without changing other fields. If the specified amount is 0, this method performs nothing.
      When given date is:
      • String type - must be in yyyy-MM-dd or yyyy-MM-dd HH:mm:ss formats.
      • Date type - no need for parsing
      When given amount is:
      • int type - If amount is positive it will add months, but if negative it will subtract months from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      Date date = parse("2018-01-02"); assertThat(rollMonth(date, 5), is(parse("2018-06-02"))); assertThat(rollMonth(date, 12), is(parse("2018-01-02")));
      Parameters:
      date - based on which new date will be created with change
      amount - int value, that is used for setting field
      Returns:
      new instance, that is combination of given date and amount
    • rollDay

      public static Date rollDay(Object date, Object amount)
      Adds amount to the 'day' field without changing other fields. A negative roll amount means to subtract from day without changing other fields. If the specified amount is 0, this method performs nothing. When given date is:
      • String type - must be in yyyy-MM-dd or yyyy-MM-dd HH:mm:ss formats.
      • Date type - no need for parsing
      When given amount is:
      • int type - If amount is positive it will add days, but if negative it will subtract days from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.

      Example:

      
        Date date = parse("2018-01-02");
        assertThat(rollDay(date, 10), is(parse("2018-01-12")));
       
      This method doesn't modify input date, but creates new instance of date type.
      Parameters:
      date - based on which new date will be created with change
      amount - int value, that is used for setting field
      Returns:
      new instance, that is combination of given date and amount
    • rollHour

      public static Date rollHour(Object date, Object amount)
      Adds amount to the 'hour' field without changing other fields. A negative roll amount means to subtract from hour without changing other fields. If the specified amount is 0, this method performs nothing. When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss formats.
      • Date type - no need for parsing
      When given amount is:
      • int type - If amount is positive it will add hours, but if negative it will subtract hours from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date datetime = type.getDatetime("2018-01-02 12:21:22.000");
        assertThat(rollHour(datetime, 10), is(type.getDatetime("2018-01-02 22:21:22.000")));
       
      Parameters:
      date - based on which new date will be created with change
      amount - int value, that is used for setting field
      Returns:
      new instance, that is combination of given date and amount
    • rollMinute

      public static Date rollMinute(Object date, Object amount)
      Adds amount to the 'minute' field without changing other fields. A negative roll amount means to subtract from minute without changing other fields. If the specified amount is 0, this method performs nothing. When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss formats.
      • Date type - no need for parsing
      When given amount is:
      • int type - If amount is positive it will add minutes, but if negative it will subtract minutes from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date datetime = type.getDatetime("2018-01-02 12:21:22.000");
        assertThat(rollMinute(datetime, 20), is(type.getDatetime("2018-01-02 12:41:22.000")));
        assertThat(rollMinute(datetime, 60), is(type.getDatetime("2018-01-02 12:21:22.000")));
       
      Parameters:
      date - based on which new date will be created with change
      amount - int value, that is used for setting field
      Returns:
      new instance, that is combination of given date and amount
    • rollSecond

      public static Date rollSecond(Object date, Object amount)
      Adds amount to the 'second' field without changing other fields. A negative roll amount means to subtract from second without changing other fields. If the specified amount is 0, this method performs nothing. When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss formats.
      • Date type - no need for parsing
      When given amount is:
      • int type - If amount is positive it will add seconds, but if negative it will subtract seconds from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        String datetimeAsString = "2018-01-02 12:21:22.000";
        assertThat(rollSecond(datetimeAsString, 10), is(type.getDatetime("2018-01-02 12:21:32.000")));
        assertThat(rollSecond(datetimeAsString, 60), is(type.getDatetime("2018-01-02 12:21:22.000")));
       
      Parameters:
      date - based on which new date will be created with change
      amount - int value, that is used for setting field
      Returns:
      new instance, that is combination of given date and amount
    • getYearDiff

      public static int getYearDiff(Object date1, Object date2)
      Returns difference of years between givens dates.
      Possible outcomes:
      • negative result if date1 > date2,
      • positive result if date1 < date2,
      • zero if there is no difference or any of given dates are null.

      Example:

      
       	TypeConverter type = new TypeConverter();
       	Date d1 = type.getDate("2001-06-15");
       	Date d2 = type.getDate("2003-01-01");
      
       	assertThat(getYearDiff(d1, d2), is(2));
       	assertThat(getYearDiff(d2, d1), is(-2));
       
      Parameters:
      date1 - first date
      date2 - second date
      Returns:
      int value as defined in comment
    • getFullYearDiff

      public static int getFullYearDiff(Date date1, Date date2)
      The same as getAbsoluteYearDiff(Object, Object), but it is not null safe. If either date1 or date2 is null, HigsonException will be thrown.
      Parameters:
      date1 - first date
      date2 - second date
      Returns:
      int value as defined in comment
      Throws:
      HigsonRuntimeException - if date1 or date2 is null
      See Also:
    • getMonthDiff

      public static int getMonthDiff(Object date1, Object date2)
      Returns difference of months between givens dates. Possible outcomes:
      • negative result if date1 > date2,
      • positive result if date1 < date2,
      • zero if there is no difference or any of given dates are null.

      Example:

       
       	assertThat(getMonthDiff("2010-01-15", "2010-01-15"), is(0));
       	assertThat(getMonthDiff("2010-01-01", "2010-02-28"), is(1));
       	assertThat(getMonthDiff("2010-02-01", "2010-01-30"), is(-1));
       
      Parameters:
      date1 - first date
      date2 - second date
      Returns:
      int value as defined in comment
      See Also:
    • getMonthDiffDeprecated

      @Deprecated public static int getMonthDiffDeprecated(Object date1, Object date2)
      Deprecated.
      Parameters:
      date1 - first date
      date2 - second date
      Returns:
      int value with difference of months between givens dates.
    • getDayDiffDeprecated

      @Deprecated public static int getDayDiffDeprecated(Object date1, Object date2)
      Deprecated.
      will be removed in future, use getDayDiff(java.lang.Object, java.lang.Object)
      Parameters:
      date1 - first date
      date2 - second date
      Returns:
      int value with difference of days between givens dates.
    • getDayDiff

      public static int getDayDiff(Object date1, Object date2)
      Returns difference of days between givens dates. Possible outcomes:
      • negative result if date1 > date2,
      • positive result if date1 < date2,
      • zero if there is no difference or any of given dates are null.

      Example:

       
       	assertThat(getDayDiff("2010-01-15", "2010-01-15"), is(0));
       	assertThat(getDayDiff("2010-01-01", "2010-01-28"), is(27));
       	assertThat(getDayDiff("2010-02-05", "2010-02-03"), is(-2));
       
      Parameters:
      date1 - first date
      date2 - second date
      Returns:
      int value as defined in comment
      See Also:
    • getDayDiff

      public static int getDayDiff(Object date1, Object date2, String pattern)
      Returns difference of days between givens dates. Possible outcomes:
      • positive result if date1 < date2 or date1 > date2,
      • zero if there is no difference or any of given dates are null.

      Example:

       
        assertThat(getDayDiff("20-02-2017", "15-02-2017", "MM-DD-YYYY"), is(5));
        assertThat(getDayDiff("15-02-2017", "20-02-2017", "MM-DD-YYYY"), is(5)); // WATCH OUT!
       
      Parameters:
      date1 - first date
      date2 - second date
      pattern - used for parsing date, if they are Strings
      Returns:
      int value as defined in comment
      Throws:
      HigsonRuntimeException - if date1 or date2 was null or not properly parsed
      See Also:
    • getHourDiff

      @Deprecated public static int getHourDiff(Object date1, Object date2)
      Deprecated.
      Will be removed in the future
      Parameters:
      date1 - date
      date2 - date
      Returns:
      hour diff
    • getMinuteDiff

      @Deprecated public static int getMinuteDiff(Object date1, Object date2)
      Deprecated.
      Will be removed in the future
      Parameters:
      date1 - date
      date2 - date
      Returns:
      minute diff
    • getTime

      @Deprecated public static Date getTime(Calendar cal)
      Deprecated.
      Will be removed in the future
      Parameters:
      cal - Calendar object
      Returns:
      Date object
    • addMonthOracle

      public static Date addMonthOracle(Object date, Object amount)
      Adds amount to 'month' field that is based on given date, but if day is last day of a given month, then moves day to the last possible day of a calculated month.
      1) If amount > 0, it will add months,
      2) If amount < 0, it will subtract months from date.
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats,
      • instance of DateHolder od NumberHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      When given amount is:
      • int type - If amount is positive it will add months, but if negative it will subtract months from date,
      • instance of Number - it will try to retrieve int from number,
      • instance of other Object types - it will try to retrieve int from instance, by parsing toString() as Integer.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

       
        Date result = RhinoDate.addMonthOracle("2018-02-28", 1);
       	Date secondResult = RhinoDate.addMonthOracle("2018-02-28", 2);
        Date notChangedDay = RhinoDate.addMonthOracle("2018-02-27", 2);
      
       	assertThat(RhinoDate.format(result), is("2018-03-31"));
       	assertThat(RhinoDate.format(secondResult), is("2018-04-30"));
       	assertThat(RhinoDate.format(notChangedDay), is("2018-04-27"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addMonthOracle

      public static Date addMonthOracle(Object date, int amount)
      Adds amount to 'month' field that is based on given date, but if day is last day of a given month, then moves day to the last possible day of a calculated month.
      1) If amount > 0, it will add months,
      2) If amount < 0, it will subtract months from date.
      When given date is:
      • String type - must be in yyyy-MM-dd HH:mm:ss or yyyy-MM-dd formats,
      • instance of DateHolder od NumberHolder - it will try to retrieve date from holder,
      • instance of other type - it will try to convert date to proper ValueHolder and then retrieve date.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date result = RhinoDate.addMonthOracle("2018-02-28", 1);
       	Date secondResult = RhinoDate.addMonthOracle("2018-02-28", 2);
        Date notChangedDay = RhinoDate.addMonthOracle("2018-02-27", 2);
      
       	assertThat(RhinoDate.format(result), is("2018-03-31"));
       	assertThat(RhinoDate.format(secondResult), is("2018-04-30"));
       	assertThat(RhinoDate.format(notChangedDay), is("2018-04-27"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
      Throws:
      IllegalArgumentException - if there are any problems with date conversions
    • addMonthOracle

      public static Date addMonthOracle(Date date, int amount)
      Adds amount to 'month' field that is based on given date, but if day is last day of a given month, then moves day to the last possible day of a calculated month.
      1) If amount > 0, it will add months,
      2) If amount < 0, it will subtract months from date.
      This method doesn't modify input date, but creates new instance of date type.

      Example:

      
        Date lastDay = RhinoDate.parse("2018-02-28");
        Date notLastDay = RhinoDate.parse("2018-02-27");
      
        Date result = RhinoDate.addMonthOracle(lastDay, 1);
       	Date secondResult = RhinoDate.addMonthOracle(lastDay, 2);
        Date notChangedDay = RhinoDate.addMonthOracle(notLastDay, 2);
      
       	assertThat(RhinoDate.format(result), is("2018-03-31"));
       	assertThat(RhinoDate.format(secondResult), is("2018-04-30"));
       	assertThat(RhinoDate.format(notChangedDay), is("2018-04-27"));
       
      Parameters:
      date - based on which new date will be created with change
      amount - to be added if positive or subtract if negative
      Returns:
      new instance, that is combination of given date and amount
    • trim

      public static Date trim(Date date)
      Clearing time part of a given date. This method doesn't modify input date, but creates new instance of date type.

      Example:

      
       		assertThat(trim(type.getDatetime("2018-02-28")), is(type.getDatetime("2018-02-28")));
       		assertThat(trim(type.getDatetime("2018-02-28 18:11:31.840")), is(type.getDatetime("2018-02-28 00:00:00.000")));
       
      Parameters:
      date - to be trimmed
      Returns:
      trimmed date if not null, or null otherwise
    • getDate

      public static Date getDate(int year, int month, int day, int hour, int minute, int second)
      Creates new date from given parameters.
      Parameters:
      year - year
      month - month
      day - day
      hour - hour
      minute - minute
      second - second
      Returns:
      new date
    • getDate

      public static Date getDate(int year, int month, int day, int hour, int minute)
      Creates new date from given parameters.
      Parameters:
      year - year
      month - month
      day - day
      hour - hour
      minute - minute
      Returns:
      new date
    • getDate

      public static Date getDate(int year, int month, int day)
      Creates new date from given parameters without time.
      Parameters:
      year - year
      month - month
      day - day
      Returns:
      new date
    • getFirstDayOfMonth

      public static Date getFirstDayOfMonth(Date date)
      Create new date based on given date, but set to first day of a month.
      Parameters:
      date - that is based on
      Returns:
      new date
    • getFirstDayOfYear

      public static Date getFirstDayOfYear(Date date)
      Create new date based on given date, but set to first day of a year.
      Parameters:
      date - that is based on
      Returns:
      new date
    • getLastDayOfMonth

      public static Date getLastDayOfMonth(Date date)
      Create new date based on given date, but set to last day of a month.
      Parameters:
      date - that is based on
      Returns:
      new date
    • getLastDayOfYear

      public static Date getLastDayOfYear(Date date)
      Create new date based on given date, but set to last day of a year.
      Parameters:
      date - that is based on
      Returns:
      new date
    • getNextWorkDay

      public static Date getNextWorkDay(Date date)
      Get next working date from given date. Short examples:
      • Monday -> Tuesday
      • Tuesday -> Wednesday
      • Friday -> Monday
      • Saturday -> Monday
      • Sunday -> Monday

      Example:

      
       		assertThat(RhinoDate.getNextWorkDay(type.getDate("2018-02-28")), is(type.getDate("2018-03-01")));
       
      Parameters:
      date - to be used as starting point
      Returns:
      next work date
    • getNearestWorkDay

      public static Date getNearestWorkDay(Date date)
      Get closets work day from given date, but if given date is work date, it will return same instance.

      Example:

      
       	assertThat(RhinoDate.getNearestWorkDay(type.getDate("2018-02-28")), is(type.getDate("2018-02-28")));
       	assertThat(RhinoDate.getNearestWorkDay(type.getDate("2018-12-01")), is(type.getDate("2018-12-03")));
       
      Parameters:
      date - to be checked
      Returns:
      same instance of date if it is working date, or next work day
    • isWorkDay

      public static boolean isWorkDay(Date date)
      Checks if given date is work date.
      Parameters:
      date - to be checked
      Returns:
      true if it is work date, false otherwise
    • isLastDayOfMonth

      public static boolean isLastDayOfMonth(Date date)
      Checks if given date is last date of a month.

      Example:

      
      	Date date1 = type.getDate("2018-10-31");
      	Date date2 = type.getDate("2018-12-31");
      	Date date3 = type.getDate("2018-12-28");
      
       	assertThat(RhinoDate.isLastDayOfMonth(date1), is(true));
       	assertThat(RhinoDate.isLastDayOfMonth(date2), is(true));
       	assertThat(RhinoDate.isLastDayOfMonth(date3), is(false));
       
      Parameters:
      date - to be checked
      Returns:
      true if given date is set to last day of a month, false otherwise (event if date is null)
    • isFirstWorkDayOfMonth

      public static boolean isFirstWorkDayOfMonth(Date date)
      Checks if given date is both a first day of a month and a work day.

      Example:

      
              Date date1 = type.getDate("2018-10-01");
              Date date2 = type.getDate("2018-10-02");
              Date date3 = type.getDate("2018-12-01");
              Date date4 = type.getDate("2018-12-03");
      
              assertThat(RhinoDate.isFirstWorkDayOfMonth(date1), is(true));
              assertThat(RhinoDate.isFirstWorkDayOfMonth(date2), is(false));
              assertThat(RhinoDate.isFirstWorkDayOfMonth(date3), is(false));
              assertThat(RhinoDate.isFirstWorkDayOfMonth(date4), is(true));
       
      Parameters:
      date - to be checked
      Returns:
      true if given date pass the conditions, false otherwise
    • subtractYear

      @Deprecated public static Date subtractYear(Date date)
      Deprecated.
      will be removed in the future, use addYear(Date, int) with -1 amount.
      Parameters:
      date - date
      Returns:
      Date object
    • copy

      public static Date copy(Date date)
      Creates copy of given date.
      Parameters:
      date - to be copied
      Returns:
      null if given date was null, otherwise proper copy
    • getFirstDayOfYear

      public static Date getFirstDayOfYear(int year)
      Create date with a beginning for a given year.

      Example:

      
       	Date startDate = getFirstDayOfYear(1998) // "1998-01-01 00:00:00"
       
      Parameters:
      year - used for date creation
      Returns:
      new date instance
    • getFirstWorkingDayOfYear

      public static Date getFirstWorkingDayOfYear(int year)
      Create date, that is set to the first work day of beginning of given year.

      Example:

      
       	Date date1 = type.getDate("2018-01-02");
      	assertThat(RhinoDate.getFirstWorkingDayOfYear(2018), is(date1));
       
      Parameters:
      year - used for date creation
      Returns:
      new date instance
    • isInPeriod

      public static boolean isInPeriod(Date dateToCheck, Date minDateInclusive, Date maxDateExclusive)
      Checks if given dateToCheck is within boundaries. The simplified check looks like this:
      minDateInclusive <= dateToCheck < maxDateExclusive.
      1) If minDateInclusive is null, then it acts like Long.MIN_VALUE,
      2) If maxDateExclusive is null, then it acts like Long.MAX_VALUE,
      3) Parameter dateToCheck can't be null.

      Example:

      
       		Date minDate = type.getDate("2018-01-02");
       		Date maxDate = type.getDate("2018-01-05");
      
       		assertThat(RhinoDate.isInPeriod(type.getDate("2018-01-01"), minDate, maxDate), is(false));
       		assertThat(RhinoDate.isInPeriod(type.getDate("2018-01-02"), minDate, maxDate), is(true));
       		assertThat(RhinoDate.isInPeriod(type.getDate("2018-01-03"), minDate, maxDate), is(true));
       		assertThat(RhinoDate.isInPeriod(type.getDate("2018-01-04"), minDate, maxDate), is(true));
       		assertThat(RhinoDate.isInPeriod(type.getDate("2018-01-05"), minDate, maxDate), is(false));
       		assertThat(RhinoDate.isInPeriod(type.getDate("2018-01-06"), minDate, maxDate), is(false));
       
      Parameters:
      dateToCheck - date to be checked if it is withing boundaries
      minDateInclusive - minimal date(inclusive)
      maxDateExclusive - maximal date(exclusive)
      Returns:
      true if described conditions are met, false otherwise
    • isInPeriod

      public static boolean isInPeriod(long d, long d1, long d2)
      Works the same as isInPeriod(Date, Date, Date), but for longs.
      Parameters:
      d - lower date
      d1 - upper date
      d2 - date to be checked in period
      Returns:
      true if d2 is in period, or false
    • isInPeriodInclusive

      public static boolean isInPeriodInclusive(Date dateToCheck, Date minDateInclusive, Date maxDateInclusive)
      Checks if given dateToCheck is within boundaries. The simplified check looks like this:
      minDateInclusive <= dateToCheck <= maxDateInclusive.
      1) If minDateInclusive is null, then it acts like Long.MIN_VALUE,
      2) If maxDateInclusive is null, then it acts like Long.MAX_VALUE,
      3) Parameter dateToCheck can't be null.

      Example:

      
       		Date minDate = type.getDate("2018-01-02");
       		Date maxDate = type.getDate("2018-01-05");
      
       		assertThat(RhinoDate.isInPeriodInclusive(type.getDate("2018-01-01"), minDate, maxDate), is(false));
       		assertThat(RhinoDate.isInPeriodInclusive(type.getDate("2018-01-02"), minDate, maxDate), is(true));
       		assertThat(RhinoDate.isInPeriodInclusive(type.getDate("2018-01-03"), minDate, maxDate), is(true));
       		assertThat(RhinoDate.isInPeriodInclusive(type.getDate("2018-01-04"), minDate, maxDate), is(true));
       		assertThat(RhinoDate.isInPeriodInclusive(type.getDate("2018-01-05"), minDate, maxDate), is(true));
       		assertThat(RhinoDate.isInPeriodInclusive(type.getDate("2018-01-06"), minDate, maxDate), is(false));
       
      Parameters:
      dateToCheck - date to be checked if it is withing boundaries
      minDateInclusive - minimal date(inclusive)
      maxDateInclusive - maximal date(inclusive)
      Returns:
      true if described conditions are met, false otherwise
    • isInPeriodInclusive

      public static boolean isInPeriodInclusive(long d, long d1, long d2)
      Works the same as isInPeriodInclusive(Date, Date, Date), but for longs.
      Parameters:
      d - lower date
      d1 - upper date
      d2 - date to be checked in period
      Returns:
      true if d2 is in period, or false
    • max

      public static Date max(Date d1, Date d2)
      Checks which one of given dates is greater then the other. It doesn't create new instances, but returns the same instance from parameters. If d1 is null, then d2 is return. If d2 is null, then d1 is return. Example:
      
        Date date1 = type.getDate("2017-01-03");
       	Date date2 = type.getDate("2017-01-04");
       	assertThat(max(date1, date2), is(date2));
       
      Parameters:
      d1 - first date
      d2 - second date
      Returns:
      either d1 if it is greater or d2
    • max

      public static Date max(Date d1, Date d2, Date d3)
      Checks which one of given dates is greater then the others. It doesn't create new instances, but returns the same instance from parameters. Example:
      
        Date date1 = type.getDate("2017-01-03");
       	Date date2 = type.getDate("2017-01-05");
       	Date date3 = type.getDate("2017-01-04");
       	assertThat(max(date1, date2, date3), is(date2));
       
      Parameters:
      d1 - first date
      d2 - second date
      d3 - third date
      Returns:
      maximal date from d1, d2 or d3
    • min

      public static Date min(Date d1, Date d2)
      Checks which one of given dates is smaller then the other. It doesn't create new instances, but returns the same instance from parameters. If d1 or d2 is null, then null is return. Example:
      
        Date date1 = type.getDate("2017-01-03");
       	Date date2 = type.getDate("2017-01-04");
       	assertThat(min(date1, date2), is(date1));
       
      Parameters:
      d1 - first date
      d2 - second date
      Returns:
      null if any dates is null, or smaller date
    • min

      public static Date min(Date d1, Date d2, Date d3)
      Checks which one of given dates is the earliest. It doesn't create new instances, but returns the same instance from parameters. If d1 or d2 or d3 is null, then null is return. Example:
      
        Date date1 = type.getDate("2017-01-03");
       	Date date2 = type.getDate("2017-01-05");
       	Date date3 = type.getDate("2017-01-04");
       	assertThat(min(date1, date2, date3), is(date1));
       
      Parameters:
      d1 - first date
      d2 - second date
      d3 - third date
      Returns:
      null if any dates is null, or the earliest date
    • getPolishHolidays

      public static Set<Date> getPolishHolidays(int year)
      Returns set of polish holidays for given year, except these years that happen to occur during weekend. Supported polish holidays, where is just an example: 1.1.2018, 6.1.2018, 1.5.2018, 3.5.2018, 15.8.2018, 1.11.2018, 11.11.2018, 25.12.2018, 26.12.2018, also two other holidays: Corpus Christi and Easter , that are calculated based on year.
      Parameters:
      year - for it, holidays will be checked
      Returns:
      set of polish holidays
    • getNearestWorkDayExcludingPolishHolidays

      public static Date getNearestWorkDayExcludingPolishHolidays(Date date)
      Get next work day based on given date, but also verify polish holidays, and consider them during verification. If given date is not work day, because it is a weekend, then return given date(same instance). Example:
      
        Date date1 = RhinoDate.getNearestWorkDayExcludingPolishHolidays(RhinoDate.parse("2018-10-31"));
        Date date2 = RhinoDate.getNearestWorkDayExcludingPolishHolidays(RhinoDate.parse("2018-11-01"));
        Date date3 = RhinoDate.getNearestWorkDayExcludingPolishHolidays(RhinoDate.parse("2018-11-02"));
      
       	assertThat(date1, is(type.getDate("2018-10-31")));
       	assertThat(date2, is(type.getDate("2018-11-02")));
       	assertThat(date3, is(type.getDate("2018-11-02")));
       
      Parameters:
      date - to be used as starting date
      Returns:
      same date instance if given date is not polish holiday, or work date. Otherwise it will return next work day.
    • compareYMD

      public static int compareYMD(Date date1, Date date2)
      Compares two dates by year, month, date. Possible outcomes:
      
       -1 : if date1 < date2
       0 : if date1 = date2
       1 : if date1 > date2
       
      Supported formats are the same as parse(String) Example:
      
       		assertThat(RhinoDate.compareYMD(parse("2018-01-01"), parse("2018-01-05")), is(-1));
       		assertThat(RhinoDate.compareYMD(parse("2018-01-05"), parse("2018-01-01")), is(1));
       		assertThat(RhinoDate.compareYMD(parse("2018-01-01"), parse("2018-01-01")), is(0));
       		assertThat(RhinoDate.compareYMD(parse("01-01-2018"), parse("2018-01-01")), is(0));
       		assertThat(RhinoDate.compareYMD(parse("05-01-2018"), parse("2018-01-01")), is(1));
       		assertThat(RhinoDate.compareYMD(parse("01-01-2018"), parse("05-01-2018")), is(-1));
       
      Parameters:
      date1 - first date
      date2 - second date
      Returns:
      -1, 0 or 1 based on described conditions
    • isLeapYear

      public static boolean isLeapYear(int year)
      Verifies if given year is a leap year.
      Parameters:
      year - to be checked
      Returns:
      true if leap year, false otherwise
    • getDaysInYear

      public static int getDaysInYear(int year)
      Number of days in a given year. It does consider leap year.
      Parameters:
      year - to be checked
      Returns:
      number of days
    • toInt

      public static int toInt(Date date)
      It will try to convert given date to int representation. Example: assertThat(RhinoDate.toInt(parse("2018-01-01")), is(20180101));
      Parameters:
      date - to be converted
      Returns:
      int representation of a date, that will mimic format yyyyMMdd
    • fromInt

      public static Date fromInt(int date)
      It will try to convert given date as int to proper date instance. Given int value must mimic date format, like: yyyyMMdd

      Example:

      
       		assertThat(RhinoDate.fromInt(20180101), is(parse("2018-01-01")));
       
      Parameters:
      date - to be converted
      Returns:
      date instance or null, if parsing int was not successful
    • getMonthsBetween

      public static int getMonthsBetween(Date date1, Date date2)
      Calculates full months intervals between date1 and date2. The result is always positive value, but parameters can't be null or HigsonRuntimeException will be thrown. It also considers: 1. last day of a month (last day of April - last day of Match = 1m) 2. leap year

      Example:

      
        // date1 == date2
        assertThat(getMonthsBetween(parse("2010-01-15"), parse("2010-01-15")), is(0));
        // date1 < date2
        assertThat(getMonthsBetween("2010-01-01", "2011-03-30"), is(2 + 12));
        assertThat(getMonthsBetween("2010-01-01", "2012-03-30"), is(2 + 24));
        assertThat(getMonthsBetween("2010-01-31", "2010-02-01"), is(0));
        assertThat(getMonthsBetween("2010-01-01", "2010-02-01"), is(1));
        // date1 > date2
        assertThat(getMonthsBetween("2010-01-22", "2010-01-20"), is(0));
        assertThat(getMonthsBetween("2010-02-01", "2010-01-01"), is(1));
       
      Parameters:
      date1 - first date
      date2 - second date
      Returns:
      int value as defined in comment, but never negative value.
      See Also:
    • getDaysBetween

      public static int getDaysBetween(Date date1, Date date2)
      Calculates full days intervals between date1 and date2. The result is always positive value, but parameters can't be null or HigsonRuntimeException will be thrown. It also considers HH:MM:SS.sss part.

      Example:

      
        Date d1 = type.getDatetime("2017-01-01 12:00:00");
        Date d2 = type.getDatetime("2017-01-02 10:00:00");
        Date d3 = type.getDatetime("2017-01-02 12:01:00");
        Date d4 = type.getDatetime("2017-01-04 05:01:00");
      
        assertThat(getDaysBetween(d1, d1), is(0));
        assertThat(getDaysBetween(d1, d2), is(0));
        assertThat(getDaysBetween(d1, d3), is(1));
        assertThat(getDaysBetween(d1, d4), is(2));
       
      Parameters:
      date1 - first date
      date2 - second date
      Returns:
      int value as defined in comment, but never negative value.
      See Also:
    • getAbsoluteYearDiff

      public static int getAbsoluteYearDiff(Object date1, Object date2)
      Calculates full years intervals between date1 and date2. Possible outcomes:
      • positive value of difference in years
      • zero if there is no difference or any of given dates are null

      Example:

      
       	TypeConverter type = new TypeConverter();
       	Date d1 = type.getDate("2001-06-15");
       	Date d2 = type.getDate("2003-01-01");
      
        assertThat(getAbsoluteYearDiff(d1, d2), is(1));
        assertThat(getAbsoluteYearDiff(d2, d1), is(1));
       
      Parameters:
      date1 - first date
      date2 - second date
      Returns:
      int value as defined in comment
      See Also:
    • getYearsBetween

      public static int getYearsBetween(Date date1, Date date2)
      Calculates full years intervals between date1 and date2. The result is always positive value, but parameters can't be null or HigsonRuntimeException will be thrown.

      Example:

      
       	TypeConverter type = new TypeConverter();
       	Date d1 = type.getDate("2001-06-15");
       	Date d2 = type.getDate("2003-01-01");
      
       	assertThat(getYearsBetween(d1, d2), is(1));
       	assertThat(getYearsBetween(d2, d1), is(1));
       
      Parameters:
      date1 - first date
      date2 - second date
      Returns:
      int value as defined in comment, but never negative value.
      Throws:
      HigsonRuntimeException - if date1 or date2 is null
      See Also:
    • julianDay

      public static int julianDay(int year, int month, int day)
      Read more about here: http://en.wikipedia.org/wiki/Julian_day
      Parameters:
      year - year
      month - month
      day - day
      Returns:
      int value with Julian Day
    • julianDay

      public static int julianDay(Date date)
      Read more about here: http://en.wikipedia.org/wiki/Julian_day
      Parameters:
      date - date
      Returns:
      int value with Julian Day
    • julianDayDiff

      public static int julianDayDiff(Date date1, Date date2)
      Read more about here: http://en.wikipedia.org/wiki/Julian_day Difference between to julian days.

      Example:

      
              Date d1 = type.getDatetime("2017-01-01 12:00:00");
              Date d2 = type.getDatetime("2017-01-02 10:00:00");
              Date d3 = type.getDatetime("2017-01-02 12:01:00");
              Date d4 = type.getDatetime("2017-01-04 05:01:00");
      
              assertThat(julianDayDiff(d1, d2), is(1));
              assertThat(julianDayDiff(d1, d3), is(1));
              assertThat(julianDayDiff(d1, d4), is(3));
       
      Parameters:
      date1 - first date
      date2 - second date
      Returns:
      difference in days as int value }