01: /* $Id: TimeFormat.java 722 2006-10-30 10:15:22Z hengels $ */
02: package org.conform.format;
03:
04: import java.text.*;
05: import java.util.*;
06:
07: /**
08: * java.sql.Date
09: * @version $Revision: 722 $
10: */
11: public class TimeFormat extends AbstractFormat {
12: public TimeFormat() {
13: message = "validation.unparsableTime";
14: }
15:
16: public TimeFormat(String pattern) {
17: message = "validation.unparsableTime";
18: this .pattern = pattern;
19: }
20:
21: public java.text.DateFormat getFormat() {
22: if (pattern != null)
23: return new SimpleDateFormat(pattern, FormatFactory
24: .getInstance().getLocale());
25: else
26: return java.text.DateFormat.getTimeInstance(
27: java.text.DateFormat.SHORT, FormatFactory
28: .getInstance().getLocale());
29:
30: }
31:
32: public String getHelp() {
33: return ((SimpleDateFormat) getFormat()).toPattern();
34: }
35:
36: public String format(Object value) {
37: return getFormat().format(value);
38: }
39:
40: public Object parse(String string) throws ParseException {
41: Date date = (Date) getFormat().parseObject(string);
42: return new java.sql.Time(date.getTime());
43: }
44: }
|