Project

General

Profile

Download (1.63 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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

    
10
package eu.etaxonomy.cdm.strategy.cache.common;
11

    
12
import org.joda.time.ReadablePartial;
13
import org.joda.time.format.DateTimeFormatter;
14

    
15
import eu.etaxonomy.cdm.model.common.TimePeriod;
16

    
17
/**
18
 * Formatter for {@link TimePeriod} instances.
19
 * @author a.mueller
20
 * @since 14-Jul-2013 (formerly inner class in TimePeriod)
21
 *
22
 */
23
public class TimePeriodPartialFormatter extends DateTimeFormatter{
24
	
25
	public static TimePeriodPartialFormatter NewInstance(){
26
		return new TimePeriodPartialFormatter();
27
	}
28
	
29
	private TimePeriodPartialFormatter(){
30
		super(null, null);
31
	}
32
	
33
	@Override
34
    public String print(ReadablePartial partial){
35
		//TODO
36
		String result = "";
37
		String year = (partial.isSupported(TimePeriod.YEAR_TYPE))? String.valueOf(partial.get(TimePeriod.YEAR_TYPE)):null;
38
		String month = (partial.isSupported(TimePeriod.MONTH_TYPE))? String.valueOf(partial.get(TimePeriod.MONTH_TYPE)):null;;
39
		String day = (partial.isSupported(TimePeriod.DAY_TYPE))? String.valueOf(partial.get(TimePeriod.DAY_TYPE)):null;;
40

    
41
		if (month !=null){
42
			if (year == null){
43
				year = "xxxx";
44
			}
45
		}
46
		if (day != null){
47
			if (month == null){
48
				month = "xx";
49
			}
50
			if (year == null){
51
				year = "xxxx";
52
			}
53
		}
54
		result = (day != null)? day + "." : "";
55
		result += (month != null)? month + "." : "";
56
		result += (year != null)? year : "";
57

    
58
		return result;
59
	}
60

    
61
}
(4-4/4)