1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
package net.smartlab.web.bean; |
25 |
|
|
26 |
|
import java.text.DateFormat; |
27 |
|
import java.text.ParseException; |
28 |
|
import java.util.Locale; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
@author |
34 |
|
|
|
|
| 21,1% |
Uncovered Elements: 15 (19) |
Complexity: 7 |
Complexity Density: 0,7 |
|
35 |
|
public class DateConverter extends Converter { |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
protected int format; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
2
|
public DateConverter() {... |
46 |
2
|
this(DateFormat.SHORT); |
47 |
|
} |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@param |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
2
|
public DateConverter(int format) {... |
55 |
2
|
this.format = format; |
56 |
|
} |
57 |
|
|
58 |
|
|
59 |
|
@see |
60 |
|
|
61 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0,62 |
|
62 |
0
|
public Object convert(Class type, Object value, Locale locale) throws ConversionException {... |
63 |
0
|
try { |
64 |
0
|
if (value.toString().trim().length() > 0) { |
65 |
0
|
if (type.equals(java.sql.Date.class)) { |
66 |
0
|
return new java.sql.Date(DateFormat.getDateInstance(format, locale).parse(value.toString()).getTime()); |
67 |
0
|
} else if (type.equals(java.util.Date.class)) { |
68 |
0
|
return DateFormat.getDateInstance(format, locale).parse(value.toString()); |
69 |
|
} else { |
70 |
0
|
return DateFormat.getDateInstance(format, locale).format(((java.util.Date)value)); |
71 |
|
} |
72 |
|
} else { |
73 |
0
|
return null; |
74 |
|
} |
75 |
|
} catch (ParseException pe) { |
76 |
|
throw new ConversionException("Invalid date " + value.toString(), pe); |
77 |
|
} |
78 |
|
} |
79 |
|
} |