Top Description Fields Constructors Methods
de.undercouch.citeproc.bibtex

public Class DateParser

extends Object
Class Inheritance
Imports
de.undercouch.citeproc.csl.CSLDate, .CSLDateBuilder, org.apache.commons.lang3.StringUtils, java.text.DateFormatSymbols, java.util.HashMap, .Locale, .Map, java.util.concurrent.ConcurrentHashMap

Parses dates
Author
Michel Kraemer

Field Summary

Modifier and TypeField and Description
private static final Map<Locale, Map<String, Integer>>
MONTH_NAMES_CACHE

A cache for month names

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static Map<String, Integer>

Returns:

the map of month names (short and long) and the corresponding month numbers. All names are converted to upper case.
getMonthNames
(Locale
the locale
locale
)

Retrieves and caches a map of month names and numbers for a given locale

private static CSLDate

Returns:

the merged date
merge
(CSLDate
the first date
d1
,
CSLDate
the second date
d2
)

Merges two dates

public static CSLDate

Returns:

the CSLDate object
toDate
(String
the string
dateString
)

Converts a given date string to a CSLDate object.

public static CSLDate

Returns:

the CSLDate object or null if both, the year and the month, could not be parsed
toDate
(String
the year to parse. Should be a four-digit number or a String whose last four characters are digits.
year
,
String
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.
month
)

Parses the given year and month to a CSLDate object.

public static CSLDate

Returns:

the CSLDate object or null if both, the year and the month, could not be parsed
toDateRange
(String
the year to parse. Should be a four-digit number or a String whose last four characters are digits.
year
,
String
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.
month
)

Parses the given year and month to a CSLDate object.

public static CSLDate

Returns:

the CSLDate object or null if both, the year and the month, could not be parsed
toDateSingle
(String
the year to parse. Should be a four-digit number or a String whose last four characters are digits.
year
,
String
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.
month
)

Parses the given year and month to a CSLDate object.

public static int

Returns:

the month's number (1-12) or -1 if the string could not be parsed
toMonth
(String
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.
month
)

Parses the given month string

private static int

Returns:

the month's number (1-12) or -1 if the string could not be parsed
tryParseMonth
(String
the month string
month
,
Locale
the locale
locale
)

Tries to parse the given month string using the month names of the given locale

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MONTH_NAMES_CACHEback to summary
private static final Map<Locale, Map<String, Integer>> MONTH_NAMES_CACHE

A cache for month names

See Also
getMonthNames(Locale)

Constructor Detail

DateParserback to summary
public DateParser()

Method Detail

getMonthNamesback to summary
private static Map<String, Integer> getMonthNames(Locale locale)

Retrieves and caches a map of month names and numbers for a given locale

Parameters
locale:Locale

the locale

Returns:Map<String, Integer>

the map of month names (short and long) and the corresponding month numbers. All names are converted to upper case.

mergeback to summary
private static CSLDate merge(CSLDate d1, CSLDate d2)

Merges two dates

Parameters
d1:CSLDate

the first date

d2:CSLDate

the second date

Returns:CSLDate

the merged date

toDateback to summary
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:String

the string

Returns:CSLDate

the CSLDate object

toDateback to summary
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:String

the year to parse. Should be a four-digit number or a String whose last four characters are digits.

month:String

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:CSLDate

the CSLDate object or null if both, the year and the month, could not be parsed

toDateRangeback to summary
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:String

the year to parse. Should be a four-digit number or a String whose last four characters are digits.

month:String

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:CSLDate

the CSLDate object or null if both, the year and the month, could not be parsed

toDateSingleback to summary
public static CSLDate toDateSingle(String year, String month)

Parses the given year and month to a CSLDate object. Does not handle ranges.

Parameters
year:String

the year to parse. Should be a four-digit number or a String whose last four characters are digits.

month:String

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:CSLDate

the CSLDate object or null if both, the year and the month, could not be parsed

toMonthback to summary
public static int toMonth(String month)

Parses the given month string

Parameters
month:String

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:int

the month's number (1-12) or -1 if the string could not be parsed

tryParseMonthback to summary
private static int tryParseMonth(String month, Locale locale)

Tries to parse the given month string using the month names of the given locale

Parameters
month:String

the month string

locale:Locale

the locale

Returns:int

the month's number (1-12) or -1 if the string could not be parsed