svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.timesupport / org.gvsig.timesupport.lib / org.gvsig.timesupport.lib.impl / src / main / java / org / gvsig / timesupport / impl / coercion / CoerceToDate.java @ 44136
History | View | Annotate | Download (997 Bytes)
1 | 44078 | jjdelcerro | package org.gvsig.timesupport.impl.coercion; |
---|---|---|---|
2 | |||
3 | import java.util.Locale; |
||
4 | import org.gvsig.timesupport.RelativeInstant; |
||
5 | import org.gvsig.timesupport.RelativeInterval; |
||
6 | import org.gvsig.tools.dataTypes.CoercionException; |
||
7 | import org.gvsig.tools.dataTypes.DataTypesManager.Coercion; |
||
8 | import org.gvsig.tools.dataTypes.DataTypesManager.CoercionWithLocale; |
||
9 | |||
10 | /**
|
||
11 | *
|
||
12 | * @author jjdelcerro
|
||
13 | */
|
||
14 | public class CoerceToDate implements CoercionWithLocale{ |
||
15 | |||
16 | 44136 | omartinez | |
17 | public CoerceToDate() {
|
||
18 | 44078 | jjdelcerro | } |
19 | |||
20 | @Override
|
||
21 | public Object coerce(Object o) throws CoercionException { |
||
22 | return this.coerce(o, null); |
||
23 | } |
||
24 | |||
25 | @Override
|
||
26 | public Object coerce(Object o, Locale locale) throws CoercionException { |
||
27 | if( o instanceof RelativeInstant ) { |
||
28 | return ((RelativeInstant) o).toDate();
|
||
29 | } |
||
30 | if( o instanceof RelativeInterval ) { |
||
31 | return ((RelativeInterval) o).getStart().toDate();
|
||
32 | } |
||
33 | 44136 | omartinez | throw new CoercionException("Can't convert object to date"); |
34 | 44078 | jjdelcerro | } |
35 | |||
36 | } |