1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.base.utility; |
17 |
|
|
18 |
|
import java.util.Calendar; |
19 |
|
import java.util.Date; |
20 |
|
import java.util.GregorianCalendar; |
21 |
|
import java.util.TimeZone; |
22 |
|
|
23 |
|
import org.apache.commons.lang.time.FastDateFormat; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
@author |
29 |
|
|
|
|
| 82.5% |
Uncovered Elements: 11 (63) |
Complexity: 12 |
Complexity Density: 0.24 |
|
30 |
|
public final class DateUtility { |
31 |
|
|
32 |
|
|
33 |
|
public static final FastDateFormat ISO_8601_TIMESTAMP_FORMATTER = FastDateFormat.getInstance( |
34 |
|
"yyyy-MM-dd'T'HH:mm:ss.SSS"); |
35 |
|
|
36 |
|
|
37 |
|
public static final FastDateFormat ISO_8601_TIME_FORMATTER = FastDateFormat.getInstance( |
38 |
|
"HH:mm:ss.SSS"); |
39 |
|
|
40 |
|
|
41 |
|
public static final FastDateFormat NICE_TIMESTAMP_FORMATTER = FastDateFormat.getInstance( |
42 |
|
"yyyy-MM-dd' 'HH:mm:ss.SSS"); |
43 |
|
|
44 |
|
|
45 |
|
private static final TimeZone GMT = TimeZone.getTimeZone("GMT"); |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
50 |
0
|
private DateUtility() {... |
51 |
|
|
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@return |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
1
|
public static final String getIsoTimestamp() {... |
60 |
1
|
return ISO_8601_TIMESTAMP_FORMATTER.format(new Date()); |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
@param |
67 |
|
@return |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
0
|
public static final String getIsoTimestamp(final Date date) {... |
70 |
0
|
return ISO_8601_TIMESTAMP_FORMATTER.format(date); |
71 |
|
} |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
@param |
77 |
|
@return |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0
|
public static final String getIsoTimestamp(final long millis) {... |
80 |
0
|
return ISO_8601_TIMESTAMP_FORMATTER.format(getDate(millis)); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
@param |
87 |
|
@return |
88 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
89 |
0
|
public static final String getIsoTime(final long millis) {... |
90 |
0
|
return ISO_8601_TIME_FORMATTER.format(getDate(millis)); |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
@return |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
1
|
public static final String getTimestamp() {... |
99 |
1
|
return NICE_TIMESTAMP_FORMATTER.format(new Date()); |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
@return |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
1
|
public static final String getGmtTimestamp() {... |
108 |
1
|
return NICE_TIMESTAMP_FORMATTER.format(getCurrentGmtDate()); |
109 |
|
} |
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
@return |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
116 |
1
|
public static final Date getCurrentGmtDate() {... |
117 |
1
|
final Calendar cal = Calendar.getInstance(GMT); |
118 |
1
|
final Calendar gmtDate = new GregorianCalendar(); |
119 |
1
|
gmtDate.set(Calendar.MONTH, cal.get(Calendar.MONTH)); |
120 |
1
|
gmtDate.set(Calendar.YEAR, cal.get(Calendar.YEAR)); |
121 |
1
|
gmtDate.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH)); |
122 |
1
|
gmtDate.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY)); |
123 |
1
|
gmtDate.set(Calendar.MINUTE, cal.get(Calendar.MINUTE)); |
124 |
1
|
gmtDate.set(Calendar.SECOND, cal.get(Calendar.SECOND)); |
125 |
1
|
return gmtDate.getTime(); |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
@param |
132 |
|
@return |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (35) |
Complexity: 3 |
Complexity Density: 0.1 |
|
134 |
9
|
public static final String getDuration(final long milliseconds) {... |
135 |
9
|
final StringBuffer buffer = new StringBuffer(); |
136 |
9
|
long factor = 1000 * 60 * 60 * 24; |
137 |
9
|
long rest = milliseconds; |
138 |
9
|
long mod = 0; |
139 |
|
|
140 |
|
|
141 |
9
|
mod = rest / factor; |
142 |
9
|
rest = rest % factor; |
143 |
9
|
if (mod > 0) { |
144 |
4
|
buffer.append(mod); |
145 |
4
|
buffer.append(" day"); |
146 |
4
|
if (mod > 1) { |
147 |
2
|
buffer.append("s"); |
148 |
|
} |
149 |
4
|
buffer.append(" "); |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
9
|
factor = factor / 24; |
154 |
9
|
mod = rest / factor; |
155 |
9
|
rest = rest % factor; |
156 |
9
|
buffer.append(StringUtility.format(mod, 2)); |
157 |
|
|
158 |
9
|
buffer.append(":"); |
159 |
|
|
160 |
|
|
161 |
9
|
factor = factor / 60; |
162 |
9
|
mod = rest / factor; |
163 |
9
|
rest = rest % factor; |
164 |
9
|
buffer.append(StringUtility.format(mod, 2)); |
165 |
|
|
166 |
9
|
buffer.append(":"); |
167 |
|
|
168 |
|
|
169 |
9
|
factor = factor / 60; |
170 |
9
|
mod = rest / factor; |
171 |
9
|
rest = rest % factor; |
172 |
9
|
buffer.append(StringUtility.format(mod, 2)); |
173 |
|
|
174 |
9
|
buffer.append("."); |
175 |
|
|
176 |
|
|
177 |
9
|
factor = factor / 1000; |
178 |
9
|
mod = rest / factor; |
179 |
|
|
180 |
9
|
buffer.append(StringUtility.format(mod, 3)); |
181 |
|
|
182 |
9
|
return buffer.toString(); |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
@param |
189 |
|
@return |
190 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
191 |
0
|
public static final Date getDate(final long millis) {... |
192 |
0
|
final Calendar calendar = Calendar.getInstance(); |
193 |
0
|
calendar.setTimeInMillis(millis); |
194 |
0
|
return calendar.getTime(); |
195 |
|
} |
196 |
|
|
197 |
|
} |