Class CmsDateConverter


  • public final class CmsDateConverter
    extends java.lang.Object
    This class is an Helper with mostly static methods that convert a given date object or that convert a given String.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String AM
      A constant for am.
      static java.lang.String PM
      A constant for pm.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String cutSuffix​(java.lang.String time)
      Cuts the suffix (am or pm) from a given time String.
      static java.lang.String dateToString​(java.util.Date date)
      Formats the provided date to a date only representation.
      static java.util.Date getDateWithTime​(java.util.Date date, java.lang.String time)
      Merges a given Date object with a given time String.
      static java.lang.String getTime​(java.util.Date date)
      Returns the short time format of a given date as String.
      static boolean is12HourPresentation()
      Returns true if the current date format is in the 12 hour representation mode false otherwise.
      static boolean isAm​(java.util.Date date)
      Returns true if an am is in the given date object false otherwise.
      static java.util.Date toDate​(java.lang.String dateText)
      Parses the provided String as a date.
      static java.lang.String toDateString​(java.util.Date date)
      Formats the provided date as only a date format (dd/mm/yyyy).
      static java.util.Date toDayDate​(java.lang.String dateText)
      Parses the provided String as a date.
      static java.lang.String toString​(java.util.Date date)
      Formats the provided date.
      static boolean validateDate​(java.util.Date date)
      Validates a time String if it matches one of the two regular expressions.
      static boolean validateTime​(java.lang.String time)
      Validates a time String if it matches the regular expressions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • cutSuffix

        public static java.lang.String cutSuffix​(java.lang.String time)
        Cuts the suffix (am or pm) from a given time String.

        If the given String has less than 5 characters an dosen't contains an am or pm in it the original String is returned.

        Parameters:
        time - the time String to cut the suffix from
        Returns:
        the time String without the suffix or the original String if the format of the String is incorrect
      • dateToString

        public static java.lang.String dateToString​(java.util.Date date)
        Formats the provided date to a date only representation.

        Parameters:
        date - the date to format
        Returns:
        the formatted date as a string
      • getDateWithTime

        public static java.util.Date getDateWithTime​(java.util.Date date,
                                                     java.lang.String time)
        Merges a given Date object with a given time String.

        Returns a null if the given time format coudn't be parsed.

        The expected time String should include the am pm information if the time format is in 12 hour presentation.

        Parameters:
        date - the given Date object which time has to be set
        time - the given time String which should be inserted into the Date Object
        Returns:
        the merged date Object
      • getTime

        public static java.lang.String getTime​(java.util.Date date)
        Returns the short time format of a given date as String.

        Parameters:
        date - the date to get the short time format from
        Returns:
        the short time format of a given date
      • is12HourPresentation

        public static boolean is12HourPresentation()
        Returns true if the current date format is in the 12 hour representation mode false otherwise.

        Returns:
        true if an am or a pm is in a new Date object false otherwise
      • isAm

        public static boolean isAm​(java.util.Date date)
        Returns true if an am is in the given date object false otherwise.

        Parameters:
        date - the date to check
        Returns:
        true if an am is in the given Date object false otherwise
      • toDate

        public static java.util.Date toDate​(java.lang.String dateText)
                                     throws java.lang.Exception
        Parses the provided String as a date.

        First try to parse the String with the given time format.

        If that fails try to parse the date with the browser settings.

        Parameters:
        dateText - the string representing a date
        Returns:
        the date created, or null if there was a parse error
        Throws:
        java.lang.Exception - in case the text can not be parsed to a date
      • toDateString

        public static java.lang.String toDateString​(java.util.Date date)
        Formats the provided date as only a date format (dd/mm/yyyy). Note, a null date is a possible input.
        Parameters:
        date - the date to format
        Returns:
        the formatted date as a string
      • toDayDate

        public static java.util.Date toDayDate​(java.lang.String dateText)
                                        throws java.lang.Exception
        Parses the provided String as a date.

        First try to parse the String with the given time format.

        If that fails try to parse the date with the browser settings.

        Parameters:
        dateText - the string representing a date
        Returns:
        the date created, or null if there was a parse error
        Throws:
        java.lang.Exception - in case the text can not be parsed to a date
      • toString

        public static java.lang.String toString​(java.util.Date date)
        Formats the provided date. Note, a null date is a possible input.
        Parameters:
        date - the date to format
        Returns:
        the formatted date as a string
      • validateDate

        public static boolean validateDate​(java.util.Date date)
        Validates a time String if it matches one of the two regular expressions.

        Returns true if the given date matches to one of the regular expressions, false otherwise.

        Parameters:
        date - the date String to check
        Returns:
        true if the given time matches to one of the regular expressions, false otherwise
      • validateTime

        public static boolean validateTime​(java.lang.String time)
        Validates a time String if it matches the regular expressions.

        Returns true if the given time matches the regular expressions, false otherwise.

        Parameters:
        time - the time String to check
        Returns:
        true if the given time matches the regular expressions, false otherwise