Package org.openl.rules.util
Class Dates
- java.lang.Object
-
- org.openl.rules.util.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 DateDate(int year, int month, int day)Creates Date object using human numbers for the year and the month.static DateDate(int year, int month, int day, int hours, int minutes)Creates Date object with hours,and minutes.static DateDate(int year, int month, int day, int hours, int minutes, int seconds)Creates Date object with hours, minutes and seconds.static DateDate(int year, int month, int day, int hours, int minutes, int seconds, int milliseconds)Creates Date object with hours, minutes, seconds and milliseconds.static DoubledateDif(Date startDate, Date endDate, String unitName)Calculate difference between two datesstatic BooleanisLeap(Integer year)Check if date is in the leap yearstatic BooleanisLeap(Date date)Check if date is in the leap yearstatic DatesetDate(Date date, int year, int month, int day)Set date in yyyy-mm-dd without changing the timestatic DatesetTime(Date date, int hours, int minutes)Set time in hh:mm:00.000 without changing the datestatic DatesetTime(Date date, int hours, int minutes, int seconds)Set time in hh:mm:ss.000 without changing the datestatic DatesetTime(Date date, int hours, int minutes, int seconds, int milliseconds)Set time in hh:mm:ss.xxx without changing the datestatic DatetoDate(String str)Converts a string to a date using a default pattern.static DatetoDate(String str, String pattern)Converts a string to a date using a pattern.static StringtoString(Date date)Converts a date to a string using a default pattern.static StringtoString(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.
-
toString
public static String toString(Date date, String pattern)
Converts a date to a string using a pattern.- See Also:
SimpleDateFormat
-
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.
-
toDate
public static Date toDate(String str, String pattern)
Converts a string to a date using a pattern.- See Also:
SimpleDateFormat
-
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
-
-