Class DateParser


  • public class DateParser
    extends java.lang.Object
    Parses dates
    Author:
    Michel Kraemer
    • Constructor Summary

      Constructors 
      Constructor Description
      DateParser()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static CSLDate toDate​(java.lang.String dateString)
      Converts a given date string to a CSLDate object.
      static CSLDate toDate​(java.lang.String year, java.lang.String month)
      Parses the given year and month to a CSLDate object.
      static CSLDate toDateRange​(java.lang.String year, java.lang.String month)
      Parses the given year and month to a CSLDate object.
      static CSLDate toDateSingle​(java.lang.String year, java.lang.String month)
      Parses the given year and month to a CSLDate object.
      static int toMonth​(java.lang.String month)
      Parses the given month string
      • Methods inherited from class java.lang.Object

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

      • DateParser

        public DateParser()
    • Method Detail

      • toDate

        public static CSLDate toDate​(java.lang.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​(java.lang.String year,
                                     java.lang.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​(java.lang.String year,
                                          java.lang.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​(java.lang.String year,
                                           java.lang.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​(java.lang.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