1
|
package eu.dnetlib.index.utils;
|
2
|
|
3
|
import java.text.ParseException;
|
4
|
import java.text.SimpleDateFormat;
|
5
|
import java.util.Arrays;
|
6
|
import java.util.List;
|
7
|
|
8
|
/**
|
9
|
* The Class IndexDateUtility.
|
10
|
*/
|
11
|
public class IndexDateUtility {
|
12
|
|
13
|
/**
|
14
|
* The Constant dateFormats.
|
15
|
*/
|
16
|
private final static List<String> dateFormats = Arrays.asList("yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd", "dd-MM-yyyy", "dd/MM/yyyy", "yyyy");
|
17
|
|
18
|
/**
|
19
|
* The Constant outFormat.
|
20
|
*/
|
21
|
private static final String outFormat = new String("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
22
|
|
23
|
/**
|
24
|
* method return a solr-compatible string representation of a date.
|
25
|
*
|
26
|
* @param date the date
|
27
|
* @return the parsed date field
|
28
|
*/
|
29
|
public static String getParsedDateField(final String date) {
|
30
|
for (String formatString : dateFormats) {
|
31
|
try {
|
32
|
return new SimpleDateFormat(outFormat).format(new SimpleDateFormat(formatString).parse(date));
|
33
|
} catch (ParseException e) {}
|
34
|
}
|
35
|
throw new IllegalStateException("unable to parse date: " + date);
|
36
|
}
|
37
|
|
38
|
}
|