Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / java / sql / Time.java
blob2d1a433fa41927437c975b1f9c71ee3f5f6c01cc
1 /* Time.java -- Wrapper around java.util.Date
2 Copyright (C) 1999, 2000, 2002, 2003, 2005, 2006
3 Free Software Foundation, Inc.
5 This file is part of GNU Classpath.
7 GNU Classpath is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Classpath is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Classpath; see the file COPYING. If not, write to the
19 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA.
22 Linking this library statically or dynamically with other modules is
23 making a combined work based on this library. Thus, the terms and
24 conditions of the GNU General Public License cover the whole
25 combination.
27 As a special exception, the copyright holders of this library give you
28 permission to link this library with independent modules to produce an
29 executable, regardless of the license terms of these independent
30 modules, and to copy and distribute the resulting executable under
31 terms of your choice, provided that you also meet, for each linked
32 independent module, the terms and conditions of the license of that
33 module. An independent module is a module which is not derived from
34 or based on this library. If you modify this library, you may extend
35 this exception to your version of the library, but you are not
36 obligated to do so. If you do not wish to do so, delete this
37 exception statement from your version. */
40 package java.sql;
42 import java.text.ParseException;
43 import java.text.SimpleDateFormat;
45 /**
46 * This class is a wrapper around java.util.Date to allow the JDBC
47 * driver to identify the value as a SQL Time.
49 * @author Aaron M. Renn (arenn@urbanophile.com)
51 public class Time extends java.util.Date
53 static final long serialVersionUID = 8397324403548013681L;
55 /**
56 * Used for parsing and formatting this date.
58 private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
60 /**
61 * This method always throws an IllegalArgumentException.
63 * @throws IllegalArgumentException when it's called.
64 * @deprecated
66 public int getDate() throws IllegalArgumentException
68 throw new IllegalArgumentException();
71 /**
72 * This method always throws an IllegalArgumentException.
74 * @throws IllegalArgumentException when it's called.
75 * @deprecated
77 public int getDay() throws IllegalArgumentException
79 throw new IllegalArgumentException();
82 /**
83 * This method always throws an IllegalArgumentException.
85 * @throws IllegalArgumentException when it's called.
86 * @deprecated
88 public int getMonth() throws IllegalArgumentException
90 throw new IllegalArgumentException();
93 /**
94 * This method always throws an IllegalArgumentException.
96 * @throws IllegalArgumentException when it's called.
97 * @deprecated
99 public int getYear() throws IllegalArgumentException
101 throw new IllegalArgumentException();
105 * This method always throws an IllegalArgumentException.
107 * @throws IllegalArgumentException when it's called.
108 * @deprecated
110 public void setDate(int newValue) throws IllegalArgumentException
112 throw new IllegalArgumentException();
116 * This method always throws an IllegalArgumentException.
118 * @throws IllegalArgumentException when it's called.
119 * @deprecated
121 public void setMonth(int newValue) throws IllegalArgumentException
123 throw new IllegalArgumentException();
127 * This method always throws an IllegalArgumentException.
129 * @throws IllegalArgumentException when it's called.
130 * @deprecated
132 public void setYear(int newValue) throws IllegalArgumentException
134 throw new IllegalArgumentException();
138 * This method returns a new instance of this class by parsing a
139 * date in JDBC format into a Java date.
141 * @param str The string to parse.
142 * @return The resulting <code>java.sql.Time</code> value.
144 public static Time valueOf (String str)
148 java.util.Date d = (java.util.Date) sdf.parseObject(str);
150 if (d == null)
151 throw new IllegalArgumentException(str);
152 else
153 return new Time(d.getTime());
155 catch (ParseException e)
157 throw new IllegalArgumentException(str);
162 * This method initializes a new instance of this class with the
163 * specified year, month, and day.
165 * @param hour The hour for this Time (0-23)
166 * @param minute The minute for this time (0-59)
167 * @param second The second for this time (0-59)
168 * @deprecated
170 public Time(int hour, int minute, int second)
172 super(System.currentTimeMillis());
174 setHours(hour);
175 setMinutes(minute);
176 setSeconds(second);
180 * This method initializes a new instance of this class with the
181 * specified time value representing the number of milliseconds since
182 * Jan 1, 1970 at 12:00 midnight GMT.
184 * @param date The time value to intialize this <code>Time</code> to.
186 public Time(long date)
188 super(date);
192 * This method returns this date in JDBC format.
194 * @return This date as a string.
196 public String toString ()
198 return sdf.format (this);