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