1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core;
17
18 import java.sql.Time;
19
20 import org.joda.time.LocalTime;
21 import org.joda.time.format.DateTimeFormat;
22 import org.joda.time.format.DateTimeFormatter;
23 import org.kuali.rice.core.web.format.FormatException;
24 import org.kuali.rice.core.web.format.Formatter;
25
26 public class SqlTimeFormatter extends Formatter {
27
28 private static final long serialVersionUID = -6187456990309386413L;
29
30 private static final DateTimeFormatter sdFormat = DateTimeFormat.forPattern("hh:mm aa");
31
32 static {
33 registerFormatter(Time.class, SqlTimeFormatter.class);
34
35
36 }
37
38
39
40 @Override
41 protected Object convertToObject(String source) {
42 Object o = null;
43
44 try {
45 o = new Time(LocalTime.parse(source, sdFormat).toDateTimeToday().getMillis());
46 } catch (Exception e) {
47 throw new FormatException("parsing", "error.invalidTime", source, e);
48 }
49
50 return o;
51 }
52
53 @Override
54 public Object format(Object source) {
55 if (source != null && source instanceof Time) {
56 Time time = (Time) source;
57 return sdFormat.print(new LocalTime(time));
58 }
59
60 return null;
61 }
62 }