Top Description Inners Fields Constructors Methods
de.undercouch.citeproc.helper.time

public Class AnyDateParser

extends Object
Class Inheritance
Imports
java.text.DateFormat, .DateFormatSymbols, .SimpleDateFormat, java.time.temporal.TemporalAccessor, java.util.Arrays, .HashMap, .List, .Locale, .Map, java.util.regex.Matcher, .Pattern, java.util.stream.Collectors

Parses strings containing dates in almost any known international format.
Author
Michel Kraemer

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final Map<String, Long>
private static final List<AnyDateParser.CompiledPattern>
private static final int
FD

Pattern contains day group

private static final int
FLY

Pattern contains long year group

private static final int
FM

Pattern contains month digit group

private static final int
FMN

Pattern contains month name group

private static final int
FS

Pattern contains day and month that might be switched if locale demands it

private static final int
FSY

Pattern contains short year group

private static final String
private static final String
private static final String
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static boolean

Returns:

true if the day should be given before the month, false otherwise
dayBeforeMonth
(Locale
the locale
locale
)

Returns true if the given locale prefers that the day should be given before the month

private static Map<String, Long>

Returns:

the map
makeMonthIndexes
(Locale
the locale
locale
)

Create a map that maps short and long month names from a given locale to their ordinal

private static List<AnyDateParser.CompiledPattern>

Returns:

the patterns
makePatterns
(Locale
the locale
locale
)

Creates regular expression patterns for the given locale

public static TemporalAccessor

Returns:

the parsed date
parse
(String
the string containing the date
date
)

Parse a string containing a date in almost any known international format.

public static TemporalAccessor

Returns:

the parsed date
parse
(String
the string containing the date
date
,
Locale
the locale to use for parsing (used to parse month names and to determine if the locale prefers the month to be given before the day in the string to parse or the other way around)
locale
)

Parse a string containing a date in almost any known international format.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

englishMonthIndexesback to summary
private static final Map<String, Long> englishMonthIndexes
englishPatternsback to summary
private static final List<AnyDateParser.CompiledPattern> englishPatterns
FDback to summary
private static final int FD

Pattern contains day group

FLYback to summary
private static final int FLY

Pattern contains long year group

FMback to summary
private static final int FM

Pattern contains month digit group

FMNback to summary
private static final int FMN

Pattern contains month name group

FSback to summary
private static final int FS

Pattern contains day and month that might be switched if locale demands it

FSYback to summary
private static final int FSY

Pattern contains short year group

GROUPNAME_DAYback to summary
private static final String GROUPNAME_DAY
GROUPNAME_LONGYEARback to summary
private static final String GROUPNAME_LONGYEAR
GROUPNAME_MONTHback to summary
private static final String GROUPNAME_MONTH
GROUPNAME_MONTHNAMEback to summary
private static final String GROUPNAME_MONTHNAME
GROUPNAME_SHORTYEARback to summary
private static final String GROUPNAME_SHORTYEAR

Constructor Detail

AnyDateParserback to summary
public AnyDateParser()

Method Detail

dayBeforeMonthback to summary
private static boolean dayBeforeMonth(Locale locale)

Returns true if the given locale prefers that the day should be given before the month

Parameters
locale:Locale

the locale

Returns:boolean

true if the day should be given before the month, false otherwise

makeMonthIndexesback to summary
private static Map<String, Long> makeMonthIndexes(Locale locale)

Create a map that maps short and long month names from a given locale to their ordinal

Parameters
locale:Locale

the locale

Returns:Map<String, Long>

the map

makePatternsback to summary
private static List<AnyDateParser.CompiledPattern> makePatterns(Locale locale)

Creates regular expression patterns for the given locale

Parameters
locale:Locale

the locale

Returns:List<AnyDateParser.CompiledPattern>

the patterns

parseback to summary
public static TemporalAccessor parse(String date) throws IllegalArgumentException

Parse a string containing a date in almost any known international format. Parses at most year, month, and date and returns them in a TemporalAccessor object. This object may not contain all fields if the string does not contain them as well. For example, if the string is "2014-10", the object will only contain a year and a month but not a day.

Parameters
date:String

the string containing the date

Returns:TemporalAccessor

the parsed date

Exceptions
IllegalArgumentException:
if the date could not be parsed
parseback to summary
public static TemporalAccessor parse(String date, Locale locale) throws IllegalArgumentException

Parse a string containing a date in almost any known international format. Parses at most year, month, and date and returns them in a TemporalAccessor object. This object may not contain all fields if the string does not contain them as well. For example, if the string is "2014-10", the object will only contain a year and a month but not a day.

Parameters
date:String

the string containing the date

locale:Locale

the locale to use for parsing (used to parse month names and to determine if the locale prefers the month to be given before the day in the string to parse or the other way around)

Returns:TemporalAccessor

the parsed date

Exceptions
IllegalArgumentException:
if the date could not be parsed
de.undercouch.citeproc.helper.time back to summary

private Class AnyDateParser.CompiledPattern

extends Object
Class Inheritance
  • java.lang.Object
  • de.undercouch.citeproc.helper.time.AnyDateParser.CompiledPattern

Field Summary

Modifier and TypeField and Description
pack-priv final int
groupNames

A bitmask specifying which group names are used in the pattern

pack-priv final Pattern
p

The pattern

Constructor Summary

AccessConstructor and Description
pack-priv
CompiledPattern(Pattern p, int groupNames)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

groupNamesback to summary
pack-priv final int groupNames

A bitmask specifying which group names are used in the pattern

pback to summary
pack-priv final Pattern p

The pattern

Constructor Detail

CompiledPatternback to summary
pack-priv CompiledPattern(Pattern p, int groupNames)