Package org.openbravo.erpCommon.utility
Class OBDateUtils
- java.lang.Object
-
- org.openbravo.erpCommon.utility.OBDateUtils
-
public class OBDateUtils extends Object
Utilities to manage dates.
-
-
Constructor Summary
Constructors Constructor Description OBDateUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
addDaysToDate(String strDate, int days, DateFormat dateFormatter)
Adds an integer number of days to a given datestatic String
calculateLaborDays(String _strDate1, String _strDate2, DateFormat dateFormatter)
Determines the labor days between two datesstatic Date
convertDateToUTC(Date date)
Returns a new Date converted to UTCstatic String
formatDate(Date date)
Returns an String with the date in the dateFormat.java format defined in Openbravo.propertiesstatic String
formatDate(Date date, String pattern)
Returns an String with the date in the specified formatstatic String
formatDateTime(Date date)
Returns an String with the date in the dateTimeFormat.java format defined in Openbravo.propertiesstatic Date
getDate(String strDate)
Parses the string to a date using the dateFormat.java property.static DateFormat
getDateFormatter(VariablesSecureApp vars)
Determines the format of the datestatic Date
getDateTime(String strDate)
Parses the string to a date with time using the dateTimeFormat defined in Openbravo.properties.static Date
getEndOfDay(Date day)
Returns the last second of the day passed as argumentstatic boolean
isBiggerDate(String strDate1, String strDate2, DateFormat dateFormatter)
Determines if a date 1 is bigger than a date 2static boolean
isWeekendDay(String strDay, DateFormat dateFormatter)
Determines if a day is a day of the weekend, i.e., Saturday or Sundaystatic Date
truncate(Date date)
Returns a new Date with the time truncatedstatic Date
truncate(Date date, ChronoUnit unit)
Returns a new Date truncated with the value in the specified unit
-
-
-
Method Detail
-
formatDate
public static String formatDate(Date date)
Returns an String with the date in the dateFormat.java format defined in Openbravo.properties- Parameters:
date
- Date to be formatted.- Returns:
- String formatted.
- See Also:
formatDate(Date, String)
-
formatDateTime
public static String formatDateTime(Date date)
Returns an String with the date in the dateTimeFormat.java format defined in Openbravo.properties- Parameters:
date
- Date to be formatted.- Returns:
- String formatted.
- See Also:
formatDate(Date, String)
-
formatDate
public static String formatDate(Date date, String pattern)
Returns an String with the date in the specified format- Parameters:
date
- Date to be formatted.pattern
- Format expected for the output.- Returns:
- String formatted.
-
getDate
public static Date getDate(String strDate) throws ParseException
Parses the string to a date using the dateFormat.java property.- Parameters:
strDate
- String containing the date- Returns:
- the date
- Throws:
ParseException
-
getDateTime
public static Date getDateTime(String strDate) throws ParseException
Parses the string to a date with time using the dateTimeFormat defined in Openbravo.properties. If the string parameter does not have time include it will add the current hours, minutes and seconds.- Parameters:
strDate
- String date.- Returns:
- the date with time.
- Throws:
ParseException
-
calculateLaborDays
public static String calculateLaborDays(String _strDate1, String _strDate2, DateFormat dateFormatter) throws ParseException
Determines the labor days between two dates- Parameters:
_strDate1
- Date 1._strDate2
- Date 2.dateFormatter
- Format of the dates.- Returns:
- strLaborDays as the number of days between strDate1 and strDate2.
- Throws:
ParseException
-
addDaysToDate
public static String addDaysToDate(String strDate, int days, DateFormat dateFormatter) throws ParseException
Adds an integer number of days to a given date- Parameters:
strDate
- Start date.days
- Number of days to add.dateFormatter
- Format of the date.- Returns:
- strFinalDate as the sum of strDate plus strDays.
- Throws:
ParseException
-
getDateFormatter
public static DateFormat getDateFormatter(VariablesSecureApp vars)
Determines the format of the date- Parameters:
vars
- Global variables.- Returns:
- DateFormatter as the format of the date.
-
isWeekendDay
public static boolean isWeekendDay(String strDay, DateFormat dateFormatter) throws ParseException
Determines if a day is a day of the weekend, i.e., Saturday or Sunday- Parameters:
strDay
- Given Date.dateFormatter
- Format of the date.- Returns:
- true if the date is a Sunday or a Saturday.
- Throws:
ParseException
-
isBiggerDate
public static boolean isBiggerDate(String strDate1, String strDate2, DateFormat dateFormatter) throws ParseException
Determines if a date 1 is bigger than a date 2- Parameters:
strDate1
- Date 1.strDate2
- Date 2.dateFormatter
- Format of the dates.- Returns:
- true if strDate1 is bigger than strDate2.
- Throws:
ParseException
-
getEndOfDay
public static Date getEndOfDay(Date day)
Returns the last second of the day passed as argument
-
convertDateToUTC
public static Date convertDateToUTC(Date date)
Returns a new Date converted to UTC- Parameters:
date
- Date to be converted to UTC
-
truncate
public static Date truncate(Date date)
Returns a new Date with the time truncated- Parameters:
date
- Date to be truncated- Returns:
- Date truncated.
-
truncate
public static Date truncate(Date date, ChronoUnit unit)
Returns a new Date truncated with the value in the specified unit- Parameters:
date
- Date to be truncatedunit
- the unit to truncate to, not null- Returns:
- Date truncated.
-
-