Project

General

Profile

Download (1.4 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.vaadin.util.formatter;
10

    
11
import org.apache.commons.lang.StringUtils;
12

    
13
import eu.etaxonomy.cdm.model.common.TimePeriod;
14

    
15
/**
16
 *
17
 * FIXME move into cdmlib
18
 *
19
 * @author a.kohlbecker
20
 * @since Apr 26, 2017
21
 *
22
 */
23
public class TimePeriodFormatter {
24

    
25
    private PartialFormatter partialFormatter;
26

    
27
    public TimePeriodFormatter(DateTimeFormat format) {
28
        partialFormatter = new PartialFormatter(format);
29
    }
30

    
31
    public String print(TimePeriod timePeriod) {
32

    
33
        if ( StringUtils.isNotBlank(timePeriod.getFreeText())){
34
           return timePeriod.getFreeText();
35
        }else{
36
            StringBuffer sb = new StringBuffer();
37
            if (timePeriod.getStart() != null && timePeriod.getStart().getFields().length > 0) {
38
                sb.append(partialFormatter.print(timePeriod.getStart()));
39
            }
40
            if (timePeriod.getEnd() != null && timePeriod.getEnd().getFields().length > 0) {
41
                if (sb.length() > 0) {
42
                    sb.append(" - ");
43
                }
44
                sb.append(partialFormatter.print(timePeriod.getEnd()));
45
            }
46
            return sb.toString();
47
        }
48
    }
49

    
50
}
(3-3/3)