1
|
/**
|
2
|
* Copyright (C) 2020 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.format.common;
|
10
|
|
11
|
import org.apache.commons.lang3.StringUtils;
|
12
|
import org.joda.time.DateTimeFieldType;
|
13
|
import org.joda.time.format.DateTimeFormatter;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.common.ExtendedTimePeriod;
|
16
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
17
|
|
18
|
/**
|
19
|
* @author a.mueller
|
20
|
* @since 27.06.2020
|
21
|
*/
|
22
|
public class ExtendedTimePeriodFormatter {
|
23
|
|
24
|
public static final DateTimeFieldType YEAR_TYPE = DateTimeFieldType.year();
|
25
|
public static final DateTimeFieldType MONTH_TYPE = DateTimeFieldType.monthOfYear();
|
26
|
public static final DateTimeFieldType DAY_TYPE = DateTimeFieldType.dayOfMonth();
|
27
|
public static final DateTimeFieldType HOUR_TYPE = DateTimeFieldType.hourOfDay();
|
28
|
public static final DateTimeFieldType MINUTE_TYPE = DateTimeFieldType.minuteOfHour();
|
29
|
|
30
|
private static final TimePeriodFormatter timePeriodFormatter = TimePeriodFormatter.NewDefaultInstance();
|
31
|
|
32
|
public static final ExtendedTimePeriodFormatter NewDefaultInstance(){
|
33
|
return new ExtendedTimePeriodFormatter();
|
34
|
}
|
35
|
|
36
|
private ExtendedTimePeriodFormatter(){}
|
37
|
|
38
|
public String format (ExtendedTimePeriod tp){
|
39
|
if (StringUtils.isNotBlank(tp.getFreeText())){
|
40
|
return tp.getFreeText();
|
41
|
}else{
|
42
|
String result = timePeriodFormatter.getTimePeriod(tp);
|
43
|
DateTimeFormatter formatter = TimePeriodPartialFormatter.NewInstance();
|
44
|
if (tp.getExtremeStart() != null){
|
45
|
result = "(" + tp.getExtremeStart().toString(formatter) + TimePeriod.SEP + ")" + result;
|
46
|
}
|
47
|
if (tp.getExtremeEnd() != null){
|
48
|
result += "(" + TimePeriod.SEP + tp.getExtremeEnd().toString(formatter)+")";
|
49
|
}
|
50
|
return result;
|
51
|
}
|
52
|
}
|
53
|
}
|