1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.core.web.format; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.core.api.CoreConstants; |
21 | |
import org.kuali.rice.core.api.datetime.DateTimeService; |
22 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
23 | |
import org.kuali.rice.core.api.util.RiceKeyConstants; |
24 | |
|
25 | |
import java.text.ParseException; |
26 | |
import java.util.Date; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public class TimestampAMPMFormatter extends Formatter { |
33 | |
private static final long serialVersionUID = 7612442662886603084L; |
34 | |
|
35 | |
private transient DateTimeService dateTimeService; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public Object convertToObject(String target) { |
43 | |
try { |
44 | 0 | return getDateTimeService().convertToSqlTimestamp(target); |
45 | |
} |
46 | 0 | catch (ParseException e) { |
47 | 0 | throw new FormatException("parsing", RiceKeyConstants.ERROR_DATE_TIME, target, e); |
48 | |
} |
49 | |
} |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
public Object format(Object value) { |
58 | 0 | if (value == null) { |
59 | 0 | return null; |
60 | |
} |
61 | 0 | if (value instanceof String && StringUtils.isEmpty((String) value)) { |
62 | 0 | return null; |
63 | |
} |
64 | 0 | return getDateTimeService().toDateTimeString((Date)value); |
65 | |
} |
66 | |
|
67 | |
protected DateTimeService getDateTimeService() { |
68 | 0 | if (this.dateTimeService == null) { |
69 | 0 | this.dateTimeService = GlobalResourceLoader.getService(CoreConstants.Services.DATETIME_SERVICE); |
70 | |
} |
71 | 0 | return this.dateTimeService; |
72 | |
} |
73 | |
} |