gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / dataTypes / impl / coercion / CoerceToTimestamp.java @ 2080
History | View | Annotate | Download (2.42 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.tools.dataTypes.impl.coercion; |
25 |
|
26 |
import java.sql.Timestamp; |
27 |
import java.util.Date; |
28 |
import org.gvsig.tools.dataTypes.CoercionException; |
29 |
import org.gvsig.tools.dataTypes.CoercionContext; |
30 |
|
31 |
public class CoerceToTimestamp extends CoerceToDateTime { |
32 |
|
33 |
@Override
|
34 |
protected String getDateType() { |
35 |
return "Timestamp"; |
36 |
} |
37 |
|
38 |
@Override
|
39 |
protected Date now() { |
40 |
Timestamp n = new Timestamp(System.currentTimeMillis()); |
41 |
return n;
|
42 |
} |
43 |
|
44 |
@Override
|
45 |
protected Date valueOf(String value) { |
46 |
Timestamp n = Timestamp.valueOf(value); |
47 |
return n;
|
48 |
} |
49 |
|
50 |
@Override
|
51 |
public Object coerce(Object value, CoercionContext context) throws CoercionException { |
52 |
if (value == null) { |
53 |
return null; |
54 |
} |
55 |
if (value instanceof Date) { |
56 |
Timestamp n = new Timestamp(((Date) value).getTime()); |
57 |
return n;
|
58 |
} |
59 |
return super.coerce(value, context); |
60 |
} |
61 |
|
62 |
//
|
63 |
// @Override
|
64 |
// protected DateFormat[] getFormatters(Locale locale) {
|
65 |
// return new DateFormat[] {
|
66 |
// DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.MEDIUM, locale),
|
67 |
// DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT, locale),
|
68 |
// DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.LONG, locale),
|
69 |
// new SimpleDateFormat("yyyyMMddHHmmss"), // DBF format
|
70 |
// new SimpleDateFormat("yyyyMMddHHmmss") ?nanoseg?? // DBF format
|
71 |
// };
|
72 |
// }
|
73 |
//
|
74 |
} |