Revision 2160 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/coercion/CoerceToTime.java

View differences:

CoerceToTime.java
27 27
import java.text.SimpleDateFormat;
28 28
import java.util.Date;
29 29
import java.util.Locale;
30
import org.gvsig.tools.dataTypes.CoercionException;
31
import org.gvsig.tools.dataTypes.CoercionContext;
32 30

  
33 31
/**
34 32
 * Coerces a value to a {@link Date}. If the value is not a {@link Date}, it
......
55 53
  }
56 54

  
57 55
  @Override
58
  protected Date now() {
59
    Date d = new Date();
60
    d.setYear(0);
61
    d.setMonth(0);
62
    d.setDate(0);
63
    return d;
56
  protected Date valueOf(Date value) {
57
    java.sql.Time dd = new java.sql.Time(value.getTime());
58
    return dd;
64 59
  }
65 60

  
66 61
  @Override
......
68 63
    return "Time";
69 64
  }
70 65

  
71
  @Override
72
  public Object coerce(Object value, CoercionContext context) throws CoercionException {
73
    if( value == null ) {
74
      return null;
75
    }
76
    if (value instanceof Date) {
77
      Date d = (Date) value;
78
      Date n = new Date(0, 0, 0, d.getHours(), d.getMinutes(), d.getSeconds());
79
      return n;
80
    }
81
    return super.coerce(value, context);
82
  }
83

  
84 66
}

Also available in: Unified diff