Class OBDateUtils


  • public class OBDateUtils
    extends Object
    Utilities to manage dates.
    • Constructor Detail

      • OBDateUtils

        public OBDateUtils()
    • 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