Revision 1388 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/coercion/CoerceToDate.java
CoerceToDate.java | ||
---|---|---|
24 | 24 |
package org.gvsig.tools.dataTypes.impl.coercion; |
25 | 25 |
|
26 | 26 |
import java.text.DateFormat; |
27 |
import java.text.ParseException; |
|
28 |
import java.text.SimpleDateFormat; |
|
27 | 29 |
import java.util.Date; |
28 | 30 |
import java.util.Locale; |
29 | 31 |
|
32 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
33 |
|
|
30 | 34 |
/** |
31 | 35 |
* Coerces a value to a {@link Date}. If the value is not a {@link Date}, it |
32 | 36 |
* will use the {@link Object#toString()} method to convert the |
33 | 37 |
* resulting {@link String} to a Date object using the current locale default |
34 | 38 |
* formatter for Date through the {@link DateFormat#getDateInstance(int)} method |
35 | 39 |
* and the {@link DateFormat#SHORT} style. |
36 |
*
|
|
40 |
* |
|
37 | 41 |
* @author gvSIG Team |
38 | 42 |
* @version $Id$ |
39 | 43 |
*/ |
... | ... | |
43 | 47 |
return DateFormat.getDateInstance(DateFormat.SHORT, locale); |
44 | 48 |
} |
45 | 49 |
|
50 |
/* (non-Javadoc) |
|
51 |
* @see org.gvsig.tools.dataTypes.impl.coercion.AbstractCoerceToDate#coerce(java.lang.Object) |
|
52 |
*/ |
|
53 |
@Override |
|
54 |
public Object coerce(Object value) throws CoercionException { |
|
55 |
try { |
|
56 |
return super.coerce(value); |
|
57 |
} catch (Throwable e) { |
|
58 |
//Do nothing |
|
59 |
} |
|
60 |
//PostgreSQL usa este formato de fecha para los valores por defecto |
|
61 |
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd"); |
|
62 |
return super.coerce(value, dateFormatter); |
|
63 |
|
|
64 |
} |
|
65 |
|
|
46 | 66 |
protected String getDateType() { |
47 | 67 |
return "Date"; |
48 | 68 |
} |
Also available in: Unified diff