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.joda.time.DateTimeFieldType;
|
12
|
import org.joda.time.Partial;
|
13
|
import org.junit.Assert;
|
14
|
import org.junit.Before;
|
15
|
import org.junit.Test;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
18
|
|
19
|
/**
|
20
|
* @author a.kohlbecker
|
21
|
* @since Apr 28, 2017
|
22
|
*
|
23
|
*/
|
24
|
public class PartialAndTimePeriodFormatterTest extends Assert {
|
25
|
|
26
|
Partial dmy;
|
27
|
Partial my;
|
28
|
Partial y;
|
29
|
|
30
|
@Before
|
31
|
public void init(){
|
32
|
dmy = new Partial(new DateTimeFieldType[]{
|
33
|
DateTimeFieldType.year(),
|
34
|
DateTimeFieldType.monthOfYear(),
|
35
|
DateTimeFieldType.dayOfMonth()
|
36
|
|
37
|
}, new int[] {1969, 04, 12});
|
38
|
|
39
|
my = new Partial(new DateTimeFieldType[]{
|
40
|
DateTimeFieldType.year(),
|
41
|
DateTimeFieldType.monthOfYear()
|
42
|
|
43
|
}, new int[] {1969, 04});
|
44
|
|
45
|
y = new Partial(new DateTimeFieldType[]{
|
46
|
DateTimeFieldType.year()
|
47
|
|
48
|
}, new int[] {1969});
|
49
|
}
|
50
|
|
51
|
@Test
|
52
|
public void test_Partial_ISO8601_DATE() {
|
53
|
PartialFormatter f = new PartialFormatter(DateTimeFormat.ISO8601_DATE);
|
54
|
assertEquals("1969-04-12", f.print(dmy));
|
55
|
assertEquals("1969-04", f.print(my));
|
56
|
assertEquals("1969", f.print(y));
|
57
|
}
|
58
|
|
59
|
@Test
|
60
|
public void test_Partial_DMY_DOT() {
|
61
|
PartialFormatter f = new PartialFormatter(DateTimeFormat.DMY_DOT);
|
62
|
assertEquals("12.04.1969", f.print(dmy));
|
63
|
assertEquals("04.1969", f.print(my));
|
64
|
assertEquals("1969", f.print(y));
|
65
|
}
|
66
|
|
67
|
@Test
|
68
|
public void test_TimePeriod_ISO8601_DATE() {
|
69
|
TimePeriodFormatter f = new TimePeriodFormatter(DateTimeFormat.ISO8601_DATE);
|
70
|
|
71
|
TimePeriod p1 = TimePeriod.NewInstance();
|
72
|
p1.setStart(my);
|
73
|
assertEquals("1969-04", f.print(p1));
|
74
|
|
75
|
TimePeriod p2 = TimePeriod.NewInstance();
|
76
|
p2.setEnd(dmy);
|
77
|
assertEquals("1969-04-12", f.print(p2));
|
78
|
|
79
|
TimePeriod p3 = TimePeriod.NewInstance(my, dmy);
|
80
|
assertEquals("1969-04 - 1969-04-12", f.print(p3));
|
81
|
|
82
|
TimePeriod p4 = TimePeriod.NewInstance(my, dmy);
|
83
|
p4.setFreeText("in April 1969");
|
84
|
assertEquals("in April 1969", f.print(p4));
|
85
|
}
|
86
|
|
87
|
@Test
|
88
|
public void test_TimePeriod_DMY_DOT() {
|
89
|
TimePeriodFormatter f = new TimePeriodFormatter(DateTimeFormat.DMY_DOT);
|
90
|
|
91
|
TimePeriod p1 = TimePeriod.NewInstance();
|
92
|
p1.setStart(my);
|
93
|
assertEquals("04.1969", f.print(p1));
|
94
|
|
95
|
TimePeriod p2 = TimePeriod.NewInstance();
|
96
|
p2.setEnd(dmy);
|
97
|
assertEquals("12.04.1969", f.print(p2));
|
98
|
|
99
|
TimePeriod p3 = TimePeriod.NewInstance(my, dmy);
|
100
|
assertEquals("04.1969 - 12.04.1969", f.print(p3));
|
101
|
|
102
|
TimePeriod p4 = TimePeriod.NewInstance(my, dmy);
|
103
|
p4.setFreeText("in April 1969");
|
104
|
assertEquals("in April 1969", f.print(p4));
|
105
|
}
|
106
|
|
107
|
}
|