01: /*
02: * Copyright 2001-2005 Stephen Colebourne
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.joda.time.convert;
17:
18: import java.util.Date;
19:
20: import org.joda.time.Chronology;
21:
22: /**
23: * DateConverter converts a java util Date to an instant or partial.
24: * The Date is converted to milliseconds in the ISO chronology.
25: *
26: * @author Stephen Colebourne
27: * @since 1.0
28: */
29: final class DateConverter extends AbstractConverter implements
30: InstantConverter, PartialConverter {
31:
32: /**
33: * Singleton instance.
34: */
35: static final DateConverter INSTANCE = new DateConverter();
36:
37: /**
38: * Restricted constructor.
39: */
40: protected DateConverter() {
41: super ();
42: }
43:
44: //-----------------------------------------------------------------------
45: /**
46: * Gets the millis, which is the Date millis value.
47: *
48: * @param object the Date to convert, must not be null
49: * @param chrono the non-null result of getChronology
50: * @return the millisecond value
51: * @throws NullPointerException if the object is null
52: * @throws ClassCastException if the object is an invalid type
53: */
54: public long getInstantMillis(Object object, Chronology chrono) {
55: Date date = (Date) object;
56: return date.getTime();
57: }
58:
59: //-----------------------------------------------------------------------
60: /**
61: * Returns Date.class.
62: *
63: * @return Date.class
64: */
65: public Class getSupportedType() {
66: return Date.class;
67: }
68:
69: }
|