Class DateParser


  • public class DateParser
    extends Object
    Parses dates
    Author:
    Michel Kraemer
    • Constructor Detail

      • DateParser

        public DateParser()
    • Method Detail

      • toDate

        public static CSLDate toDate​(String dateString)
        Converts a given date string to a CSLDate object. Does not parse the string but saves it in the CSLDate's raw field.
        Parameters:
        dateString - the string
        Returns:
        the CSLDate object
      • toDate

        public static CSLDate toDate​(String year,
                                     String month)
        Parses the given year and month to a CSLDate object. Handles date ranges such as xx-xx or xx/xx and even xx-xx/yy-yy.
        Parameters:
        year - the year to parse. Should be a four-digit number or a String whose last four characters are digits.
        month - the month to parse. May be a number (1-12), a short month name (Jan to Dec), or a long month name (January to December). This method is also able to recognize month names in several locales.
        Returns:
        the CSLDate object or null if both, the year and the month, could not be parsed
      • toDateRange

        public static CSLDate toDateRange​(String year,
                                          String month)
        Parses the given year and month to a CSLDate object. Handles date ranges such as xx-xx.
        Parameters:
        year - the year to parse. Should be a four-digit number or a String whose last four characters are digits.
        month - the month to parse. May be a number (1-12), a short month name (Jan to Dec), or a long month name (January to December). This method is also able to recognize month names in several locales.
        Returns:
        the CSLDate object or null if both, the year and the month, could not be parsed
      • toDateSingle

        public static CSLDate toDateSingle​(String year,
                                           String month)
        Parses the given year and month to a CSLDate object. Does not handle ranges.
        Parameters:
        year - the year to parse. Should be a four-digit number or a String whose last four characters are digits.
        month - the month to parse. May be a number (1-12), a short month name (Jan to Dec), or a long month name (January to December). This method is also able to recognize month names in several locales.
        Returns:
        the CSLDate object or null if both, the year and the month, could not be parsed
      • toMonth

        public static int toMonth​(String month)
        Parses the given month string
        Parameters:
        month - the month to parse. May be a number (1-12), a short month name (Jan to Dec), or a long month name (January to December). This method is also able to recognize month names in several locales.
        Returns:
        the month's number (1-12) or -1 if the string could not be parsed