Class Dates


  • public final class Dates
    extends Object
    A set of util methods to work with dates. Note: Days and months begin from 1 (not like in Java from 0). Years begin from 0000. Note: For OpenL rules only! Don't use it in Java code.
    Author:
    Yury Molchan, Vladyslav Pikus
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Date Date​(int year, int month, int day)
      Creates Date object using human numbers for the year and the month.
      static Date Date​(int year, int month, int day, int hours, int minutes)
      Creates Date object with hours,and minutes.
      static Date Date​(int year, int month, int day, int hours, int minutes, int seconds)
      Creates Date object with hours, minutes and seconds.
      static Date Date​(int year, int month, int day, int hours, int minutes, int seconds, int milliseconds)
      Creates Date object with hours, minutes, seconds and milliseconds.
      static Double dateDif​(Date startDate, Date endDate, String unitName)
      Calculate difference between two dates
      static Boolean isLeap​(Integer year)
      Check if date is in the leap year
      static Boolean isLeap​(Date date)
      Check if date is in the leap year
      static Date setDate​(Date date, int year, int month, int day)
      Set date in yyyy-mm-dd without changing the time
      static Date setTime​(Date date, int hours, int minutes)
      Set time in hh:mm:00.000 without changing the date
      static Date setTime​(Date date, int hours, int minutes, int seconds)
      Set time in hh:mm:ss.000 without changing the date
      static Date setTime​(Date date, int hours, int minutes, int seconds, int milliseconds)
      Set time in hh:mm:ss.xxx without changing the date
      static Date toDate​(String str)
      Converts a string to a date using a default pattern.
      static Date toDate​(String str, String pattern)
      Converts a string to a date using a pattern.
      static String toString​(Date date)
      Converts a date to a string using a default pattern.
      static String toString​(Date date, String pattern)
      Converts a date to a string using a pattern.
    • Method Detail

      • Date

        public static Date Date​(int year,
                                int month,
                                int day)
        Creates Date object using human numbers for the year and the month. Also validates correctness of the date.
        See Also:
        SimpleDateFormat
      • Date

        public static Date Date​(int year,
                                int month,
                                int day,
                                int hours,
                                int minutes)
        Creates Date object with hours,and minutes. Also validates correctness of the date.
        See Also:
        SimpleDateFormat
      • Date

        public static Date Date​(int year,
                                int month,
                                int day,
                                int hours,
                                int minutes,
                                int seconds)
        Creates Date object with hours, minutes and seconds. Also validates correctness of the date.
        See Also:
        SimpleDateFormat
      • Date

        public static Date Date​(int year,
                                int month,
                                int day,
                                int hours,
                                int minutes,
                                int seconds,
                                int milliseconds)
        Creates Date object with hours, minutes, seconds and milliseconds. Also validates correctness of the date.
        See Also:
        SimpleDateFormat
      • toString

        public static String toString​(Date date)
        Converts a date to a string using a default pattern. The default pattern is system and setting dependent.
      • toDate

        public static Date toDate​(String str)
        Converts a string to a date using a default pattern. The default pattern is system and setting dependent.
      • setTime

        public static Date setTime​(Date date,
                                   int hours,
                                   int minutes)
        Set time in hh:mm:00.000 without changing the date
      • setTime

        public static Date setTime​(Date date,
                                   int hours,
                                   int minutes,
                                   int seconds)
        Set time in hh:mm:ss.000 without changing the date
      • setTime

        public static Date setTime​(Date date,
                                   int hours,
                                   int minutes,
                                   int seconds,
                                   int milliseconds)
        Set time in hh:mm:ss.xxx without changing the date
      • setDate

        public static Date setDate​(Date date,
                                   int year,
                                   int month,
                                   int day)
        Set date in yyyy-mm-dd without changing the time
      • isLeap

        public static Boolean isLeap​(Date date)
        Check if date is in the leap year
        Parameters:
        date - date
        Returns:
        true if year is leap, otherwise false
      • isLeap

        public static Boolean isLeap​(Integer year)
        Check if date is in the leap year
        Parameters:
        year - year
        Returns:
        true if year is leap, otherwise false
      • dateDif

        public static Double dateDif​(Date startDate,
                                     Date endDate,
                                     String unitName)
        Calculate difference between two dates
        Parameters:
        startDate - start date
        endDate - end date
        unitName - method type
        Returns:
        difference between two dates