Revision 1881 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/coercion/CoerceToDate.java

View differences:

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 27
import java.text.SimpleDateFormat;
29 28
import java.util.Date;
30 29
import java.util.Locale;
31 30

  
32
import org.gvsig.tools.dataTypes.CoercionException;
33 31

  
34 32
/**
35 33
 * Coerces a value to a {@link Date}. If the value is not a {@link Date}, it
......
41 39
 * @author gvSIG Team
42 40
 * @version $Id$
43 41
 */
42
@SuppressWarnings("UseSpecificCatch")
44 43
public class CoerceToDate extends AbstractCoerceToDate {
45 44

  
46
    protected DateFormat createFormatter(Locale locale) {
47
        return DateFormat.getDateInstance(DateFormat.SHORT, locale);
48
    }
49

  
50
    /* (non-Javadoc)
51
     * @see org.gvsig.tools.dataTypes.impl.coercion.AbstractCoerceToDate#coerce(java.lang.Object)
52
     */
53 45
    @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

  
46
    protected DateFormat[] getFormatters(Locale locale) {
47
        return new DateFormat[] {
48
            DateFormat.getDateInstance(DateFormat.SHORT, locale),
49
            DateFormat.getDateInstance(DateFormat.MEDIUM, locale),
50
            DateFormat.getDateInstance(DateFormat.LONG, locale),
51
            new SimpleDateFormat("yyyy-MM-dd") // PostgreSQL format
52
        };
64 53
    }
65 54

  
55
    @Override
66 56
    protected String getDateType() {
67 57
        return "Date";
68 58
    }

Also available in: Unified diff