1 package com.github.mygreen.cellformatter.lang;
2
3 import java.util.Calendar;
4 import java.util.Date;
5 import java.util.TimeZone;
6
7
8
9
10
11
12
13
14 public class EraPeriod {
15
16
17
18
19
20
21 public static final EraPeriodg/EraPeriod.html#EraPeriod">EraPeriod UNKNOWN_PERIOD = new EraPeriod() {
22
23 @Override
24 public boolean isUnknown() {
25 return true;
26 }
27
28 };
29
30
31
32 private String abbrevRomanName;
33
34
35 private String abbrevName;
36
37
38 private String name;
39
40
41 private Date startDate;
42
43
44 private Date endDate;
45
46
47
48
49
50
51
52 public boolean contains(final Date date) {
53
54 ArgUtils.notNull(date, "date");
55
56 if(startDate == null) {
57 return endDate.compareTo(date) >= 0;
58
59 } else if(endDate == null) {
60 return startDate.compareTo(date) <= 0;
61
62 } else {
63 return (endDate.compareTo(date) >= 0) && (startDate.compareTo(date) <= 0);
64 }
65
66 }
67
68
69
70
71
72
73
74 public int getEraYear(final Calendar cal) {
75 ArgUtils.notNull(cal, "cal");
76
77 final Calendar startCal = Calendar.getInstance(TimeZone.getTimeZone("GMT-00:00"));
78 startCal.setTime(startDate);
79
80 final int diff = cal.get(Calendar.YEAR) - startCal.get(Calendar.YEAR) + 1;
81 return diff;
82
83 }
84
85 @Override
86 public String toString() {
87
88 StringBuilder sb = new StringBuilder();
89 sb.append(EraPeriod.class.getSimpleName()).append("[").append(getName()).append("]");
90 if(startDate != null) {
91 sb.append("[start=").append(ExcelDateUtils.formatDate(startDate)).append("]");
92 }
93
94 if(endDate != null) {
95 sb.append("[end=").append(ExcelDateUtils.formatDate(endDate)).append("]");
96 }
97
98 return sb.toString();
99
100 }
101
102
103
104
105
106 public String getAbbrevRomanName() {
107 return abbrevRomanName;
108 }
109
110
111
112
113
114 void setAbbrevRomanName(String abbrevRomanName) {
115 this.abbrevRomanName = abbrevRomanName;
116 }
117
118
119
120
121
122
123 public String getAbbrevName() {
124 return abbrevName;
125 }
126
127
128
129
130
131 void setAbbrevName(String abbrevName) {
132 this.abbrevName = abbrevName;
133 }
134
135
136
137
138
139 public String getName() {
140 return name;
141 }
142
143
144
145
146
147 void setName(String name) {
148 this.name = name;
149 }
150
151
152
153
154
155 public Date getStartDate() {
156 return startDate;
157 }
158
159
160
161
162
163 void setStartDate(Date startDate) {
164 this.startDate = startDate;
165 }
166
167
168
169
170
171 void setEndDate(Date endDate) {
172 this.endDate = endDate;
173 }
174
175
176
177
178
179 public Date getEndDate() {
180 return endDate;
181 }
182
183
184
185
186
187
188 public boolean isUnknown() {
189 return false;
190 }
191
192 }