1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.criteria.impl; |
21 |
|
|
22 |
|
import org.joda.time.DateTime; |
23 |
|
import org.joda.time.MutableDateTime; |
24 |
|
import org.joda.time.format.DateTimeFormat; |
25 |
|
import org.joda.time.format.DateTimeFormatter; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
|
|
| 24.7% |
Uncovered Elements: 67 (89) |
Complexity: 34 |
Complexity Density: 0.62 |
|
30 |
|
public class PeriodFactory |
31 |
|
{ |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
private static final DateTime MIN_DATE = new DateTime(1000, 1, 1, 0, 0, 0, 0); |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
private static final DateTime MAX_DATE = new DateTime(9999, 12, 31, 23, 59, 59, 999); |
41 |
|
|
42 |
|
|
43 |
|
@link@link |
44 |
|
|
45 |
|
public static final Period ALL_TIME = |
46 |
|
createPeriod(MIN_DATE.getMillis(), MAX_DATE.getMillis()); |
47 |
|
|
48 |
|
private static final DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd"); |
49 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
50 |
0 |
public PeriodFactory()... |
51 |
|
{ |
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
|
@see |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
20 |
public static Period createPeriod(long start, long end)... |
58 |
|
{ |
59 |
20 |
return new Period(start, end); |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
@param |
66 |
|
@param |
67 |
|
@return |
68 |
|
@see |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0 |
public static Period createPeriod(String start, String end)... |
71 |
|
{ |
72 |
0 |
return createPeriod(formatter.parseMillis(start), formatter.parseMillis(end)); |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
@param |
79 |
|
@return |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
81 |
1 |
public static Period createDayPeriod(long timestamp)... |
82 |
|
{ |
83 |
1 |
MutableDateTime mdt = new MutableDateTime(timestamp); |
84 |
1 |
return createPeriod(toDayStart(mdt).getMillis(), toDayEnd(mdt).getMillis()); |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
@param |
91 |
|
@return |
92 |
|
@see |
93 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
94 |
0 |
public static Period createDayPeriod(String date)... |
95 |
|
{ |
96 |
0 |
return createDayPeriod(formatter.parseMillis(date)); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
@param |
103 |
|
@return |
104 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
105 |
0 |
public static Period createHourPeriod(long timestamp)... |
106 |
|
{ |
107 |
0 |
MutableDateTime mdt = new MutableDateTime(timestamp); |
108 |
0 |
return createPeriod(toHourStart(mdt).getMillis(), toHourEnd(mdt).getMillis()); |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
@param |
115 |
|
@return |
116 |
|
@see |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
0 |
public static Period createHourPeriod(String date)... |
119 |
|
{ |
120 |
0 |
return createHourPeriod(formatter.parseMillis(date)); |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
@param |
128 |
|
@return |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
130 |
0 |
public static Period createSinceHoursPeriod(int numberOfHours)... |
131 |
|
{ |
132 |
0 |
DateTime dt = new DateTime(); |
133 |
0 |
return createPeriod(dt.minusHours(numberOfHours).getMillis(), dt.getMillis()); |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
@param |
141 |
|
@return |
142 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
143 |
0 |
public static Period createSinceDaysPeriod(int numberOfDays)... |
144 |
|
{ |
145 |
0 |
DateTime dt = new DateTime(); |
146 |
0 |
return createPeriod(dt.minusDays(numberOfDays).getMillis(), dt.getMillis()); |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
@param |
154 |
|
@return |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
156 |
0 |
public static Period createSinceWeeksPeriod(int numberOfWeeks)... |
157 |
|
{ |
158 |
0 |
DateTime dt = new DateTime(); |
159 |
0 |
return createPeriod(dt.minusWeeks(numberOfWeeks).getMillis(), dt.getMillis()); |
160 |
|
} |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
@param |
167 |
|
@return |
168 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
169 |
0 |
public static Period createSinceMonthsPeriod(int numberOfMonths)... |
170 |
|
{ |
171 |
0 |
DateTime dt = new DateTime(); |
172 |
0 |
return createPeriod(dt.minusMonths(numberOfMonths).getMillis(), dt.getMillis()); |
173 |
|
} |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
@param |
180 |
|
@return |
181 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
182 |
0 |
public static Period createSinceYearsPeriod(int numberOfYears)... |
183 |
|
{ |
184 |
0 |
DateTime dt = new DateTime(); |
185 |
0 |
return createPeriod(dt.minusYears(numberOfYears).getMillis(), dt.getMillis()); |
186 |
|
} |
187 |
|
|
188 |
|
|
189 |
|
@return |
190 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
191 |
0 |
public static Period getCurrentDay()... |
192 |
|
{ |
193 |
0 |
return createDayPeriod(new DateTime().getMillis()); |
194 |
|
} |
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
@param |
200 |
|
@return |
201 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
202 |
0 |
public static Period createWeekPeriod(long timestamp)... |
203 |
|
{ |
204 |
0 |
MutableDateTime mdt = new MutableDateTime(timestamp); |
205 |
0 |
return createPeriod(toWeekStart(mdt).getMillis(), toWeekEnd(mdt).getMillis()); |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
@param |
212 |
|
@return |
213 |
|
@see |
214 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
215 |
0 |
public static Period createWeekPeriod(String date)... |
216 |
|
{ |
217 |
0 |
return createWeekPeriod(formatter.parseMillis(date)); |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
|
@return |
222 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
223 |
0 |
public static Period getCurrentWeek()... |
224 |
|
{ |
225 |
0 |
return createWeekPeriod(new DateTime().getMillis()); |
226 |
|
} |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
@param |
232 |
|
@return |
233 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
234 |
1 |
public static Period createMonthPeriod(long timestamp)... |
235 |
|
{ |
236 |
1 |
MutableDateTime mdt = new MutableDateTime(timestamp); |
237 |
1 |
return createPeriod(toMonthStart(mdt).getMillis(), toMonthEnd(mdt).getMillis()); |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
@param |
244 |
|
@return |
245 |
|
@see |
246 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
247 |
0 |
public static Period createMonthPeriod(String date)... |
248 |
|
{ |
249 |
0 |
return createMonthPeriod(formatter.parseMillis(date)); |
250 |
|
} |
251 |
|
|
252 |
|
|
253 |
|
@return |
254 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
255 |
0 |
public static Period getCurrentMonth()... |
256 |
|
{ |
257 |
0 |
return createMonthPeriod(new DateTime().getMillis()); |
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
@param |
264 |
|
@return |
265 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
266 |
0 |
public static Period createYearPeriod(long timestamp)... |
267 |
|
{ |
268 |
0 |
MutableDateTime mdt = new MutableDateTime(timestamp); |
269 |
0 |
return createPeriod(toYearStart(mdt).getMillis(), toYearEnd(mdt).getMillis()); |
270 |
|
} |
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
@param |
276 |
|
@return |
277 |
|
@see |
278 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
279 |
0 |
public static Period createYearPeriod(String date)... |
280 |
|
{ |
281 |
0 |
return createYearPeriod(formatter.parseMillis(date)); |
282 |
|
} |
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
@return |
289 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
290 |
14 |
public static Period createMaximumPeriod()... |
291 |
|
{ |
292 |
14 |
return createPeriod(Long.MIN_VALUE, Long.MAX_VALUE); |
293 |
|
} |
294 |
|
|
295 |
|
|
296 |
|
@return |
297 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
298 |
0 |
public static Period getCurrentYear()... |
299 |
|
{ |
300 |
0 |
return createYearPeriod(new DateTime().getMillis()); |
301 |
|
} |
302 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
303 |
0 |
private static MutableDateTime toHourStart(MutableDateTime mdt)... |
304 |
|
{ |
305 |
0 |
mdt.setMinuteOfHour(mdt.minuteOfHour().getMinimumValue()); |
306 |
0 |
mdt.setSecondOfMinute(mdt.secondOfMinute().getMinimumValue()); |
307 |
0 |
mdt.setMillisOfSecond(mdt.millisOfSecond().getMinimumValue()); |
308 |
0 |
return mdt; |
309 |
|
} |
310 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
311 |
0 |
private static MutableDateTime toHourEnd(MutableDateTime mdt)... |
312 |
|
{ |
313 |
0 |
mdt.addHours(1); |
314 |
0 |
return toHourStart(mdt); |
315 |
|
} |
316 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
317 |
4 |
private static MutableDateTime toDayStart(MutableDateTime mdt)... |
318 |
|
{ |
319 |
4 |
mdt.setMillisOfDay(mdt.millisOfDay().getMinimumValue()); |
320 |
4 |
return mdt; |
321 |
|
} |
322 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
323 |
2 |
private static MutableDateTime toDayEnd(MutableDateTime mdt)... |
324 |
|
{ |
325 |
2 |
mdt.addDays(1); |
326 |
2 |
return toDayStart(mdt); |
327 |
|
} |
328 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
329 |
0 |
private static MutableDateTime toWeekStart(MutableDateTime mdt)... |
330 |
|
{ |
331 |
0 |
mdt.setDayOfWeek(mdt.dayOfWeek().getMinimumValue()); |
332 |
0 |
return toDayStart(mdt); |
333 |
|
} |
334 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
335 |
0 |
private static MutableDateTime toWeekEnd(MutableDateTime mdt)... |
336 |
|
{ |
337 |
0 |
mdt.setDayOfWeek(mdt.dayOfWeek().getMaximumValue()); |
338 |
0 |
return toDayEnd(mdt); |
339 |
|
} |
340 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
341 |
1 |
private static MutableDateTime toMonthStart(MutableDateTime mdt)... |
342 |
|
{ |
343 |
1 |
mdt.setDayOfMonth(mdt.dayOfMonth().getMinimumValue()); |
344 |
1 |
return toDayStart(mdt); |
345 |
|
} |
346 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
347 |
1 |
private static MutableDateTime toMonthEnd(MutableDateTime mdt)... |
348 |
|
{ |
349 |
1 |
mdt.setDayOfMonth(mdt.dayOfMonth().getMaximumValue()); |
350 |
1 |
return toDayEnd(mdt); |
351 |
|
} |
352 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
353 |
0 |
private static MutableDateTime toYearStart(MutableDateTime mdt)... |
354 |
|
{ |
355 |
0 |
mdt.setDayOfYear(mdt.dayOfYear().getMinimumValue()); |
356 |
0 |
return toDayStart(mdt); |
357 |
|
} |
358 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
359 |
0 |
private static MutableDateTime toYearEnd(MutableDateTime mdt)... |
360 |
|
{ |
361 |
0 |
mdt.setDayOfYear(mdt.dayOfYear().getMaximumValue()); |
362 |
0 |
return toDayEnd(mdt); |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
|
@link |
367 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
368 |
0 |
public static Period getALL_TIME()... |
369 |
|
{ |
370 |
0 |
return ALL_TIME; |
371 |
|
} |
372 |
|
} |