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