1 /*
2 * Copyright 2001-2005 Stephen Colebourne
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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 org.joda.time.Chronology;
19 import org.joda.time.DateTimeZone;
20
21 /**
22 * InstantConverter defines how an object is converted to milliseconds/chronology.
23 * <p>
24 * The two methods in this interface must be called in order, as the
25 * <code>getInstantMillis</code> method relies on the result of the
26 * <code>getChronology</code> method being passed in.
27 *
28 * @author Stephen Colebourne
29 * @since 1.0
30 */
31 public interface InstantConverter extends Converter {
32
33 /**
34 * Extracts the chronology from an object of this converter's type
35 * where the time zone is specified.
36 *
37 * @param object the object to convert
38 * @param zone the specified zone to use, null means default zone
39 * @return the chronology, never null
40 * @throws ClassCastException if the object is invalid
41 */
42 Chronology getChronology(Object object, DateTimeZone zone);
43
44 /**
45 * Extracts the chronology from an object of this converter's type
46 * where the chronology may be specified.
47 * <p>
48 * If the chronology is non-null it should be used. If it is null, then the
49 * object should be queried, and if it has no chronology then ISO default is used.
50 *
51 * @param object the object to convert
52 * @param chrono the chronology to use, null means use object
53 * @return the chronology, never null
54 * @throws ClassCastException if the object is invalid
55 */
56 Chronology getChronology(Object object, Chronology chrono);
57
58 //-----------------------------------------------------------------------
59 /**
60 * Extracts the millis from an object of this converter's type.
61 * <p>
62 * The chronology passed in is the result of the call to <code>getChronology</code>.
63 *
64 * @param object the object to convert
65 * @param chrono the chronology to use, which is the non-null result of getChronology()
66 * @return the millisecond instant
67 * @throws ClassCastException if the object is invalid
68 * @throws IllegalArgumentException if object conversion fails
69 */
70 long getInstantMillis(Object object, Chronology chrono);
71
72 }