001 /* Time.java -- Wrapper around java.util.Date 002 Copyright (C) 1999, 2000, 2002, 2003, 2005, 2006 003 Free Software Foundation, Inc. 004 005 This file is part of GNU Classpath. 006 007 GNU Classpath is free software; you can redistribute it and/or modify 008 it under the terms of the GNU General Public License as published by 009 the Free Software Foundation; either version 2, or (at your option) 010 any later version. 011 012 GNU Classpath is distributed in the hope that it will be useful, but 013 WITHOUT ANY WARRANTY; without even the implied warranty of 014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 General Public License for more details. 016 017 You should have received a copy of the GNU General Public License 018 along with GNU Classpath; see the file COPYING. If not, write to the 019 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 020 02110-1301 USA. 021 022 Linking this library statically or dynamically with other modules is 023 making a combined work based on this library. Thus, the terms and 024 conditions of the GNU General Public License cover the whole 025 combination. 026 027 As a special exception, the copyright holders of this library give you 028 permission to link this library with independent modules to produce an 029 executable, regardless of the license terms of these independent 030 modules, and to copy and distribute the resulting executable under 031 terms of your choice, provided that you also meet, for each linked 032 independent module, the terms and conditions of the license of that 033 module. An independent module is a module which is not derived from 034 or based on this library. If you modify this library, you may extend 035 this exception to your version of the library, but you are not 036 obligated to do so. If you do not wish to do so, delete this 037 exception statement from your version. */ 038 039 040 package java.sql; 041 042 import java.text.ParseException; 043 import java.text.SimpleDateFormat; 044 045 /** 046 * This class is a wrapper around java.util.Date to allow the JDBC 047 * driver to identify the value as a SQL Time. 048 * 049 * @author Aaron M. Renn (arenn@urbanophile.com) 050 */ 051 public class Time extends java.util.Date 052 { 053 static final long serialVersionUID = 8397324403548013681L; 054 055 /** 056 * Used for parsing and formatting this date. 057 */ 058 private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); 059 060 /** 061 * This method always throws an IllegalArgumentException. 062 * 063 * @throws IllegalArgumentException when it's called. 064 * @deprecated 065 */ 066 public int getDate() throws IllegalArgumentException 067 { 068 throw new IllegalArgumentException(); 069 } 070 071 /** 072 * This method always throws an IllegalArgumentException. 073 * 074 * @throws IllegalArgumentException when it's called. 075 * @deprecated 076 */ 077 public int getDay() throws IllegalArgumentException 078 { 079 throw new IllegalArgumentException(); 080 } 081 082 /** 083 * This method always throws an IllegalArgumentException. 084 * 085 * @throws IllegalArgumentException when it's called. 086 * @deprecated 087 */ 088 public int getMonth() throws IllegalArgumentException 089 { 090 throw new IllegalArgumentException(); 091 } 092 093 /** 094 * This method always throws an IllegalArgumentException. 095 * 096 * @throws IllegalArgumentException when it's called. 097 * @deprecated 098 */ 099 public int getYear() throws IllegalArgumentException 100 { 101 throw new IllegalArgumentException(); 102 } 103 104 /** 105 * This method always throws an IllegalArgumentException. 106 * 107 * @throws IllegalArgumentException when it's called. 108 * @deprecated 109 */ 110 public void setDate(int newValue) throws IllegalArgumentException 111 { 112 throw new IllegalArgumentException(); 113 } 114 115 /** 116 * This method always throws an IllegalArgumentException. 117 * 118 * @throws IllegalArgumentException when it's called. 119 * @deprecated 120 */ 121 public void setMonth(int newValue) throws IllegalArgumentException 122 { 123 throw new IllegalArgumentException(); 124 } 125 126 /** 127 * This method always throws an IllegalArgumentException. 128 * 129 * @throws IllegalArgumentException when it's called. 130 * @deprecated 131 */ 132 public void setYear(int newValue) throws IllegalArgumentException 133 { 134 throw new IllegalArgumentException(); 135 } 136 137 /** 138 * This method returns a new instance of this class by parsing a 139 * date in JDBC format into a Java date. 140 * 141 * @param str The string to parse. 142 * @return The resulting <code>java.sql.Time</code> value. 143 */ 144 public static Time valueOf (String str) 145 { 146 try 147 { 148 java.util.Date d = (java.util.Date) sdf.parseObject(str); 149 150 if (d == null) 151 throw new IllegalArgumentException(str); 152 else 153 return new Time(d.getTime()); 154 } 155 catch (ParseException e) 156 { 157 throw new IllegalArgumentException(str); 158 } 159 } 160 161 /** 162 * This method initializes a new instance of this class with the 163 * specified year, month, and day. 164 * 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 169 */ 170 public Time(int hour, int minute, int second) 171 { 172 super(System.currentTimeMillis()); 173 174 setHours(hour); 175 setMinutes(minute); 176 setSeconds(second); 177 } 178 179 /** 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. 183 * 184 * @param date The time value to intialize this <code>Time</code> to. 185 */ 186 public Time(long date) 187 { 188 super(date); 189 } 190 191 /** 192 * This method returns this date in JDBC format. 193 * 194 * @return This date as a string. 195 */ 196 public String toString () 197 { 198 return sdf.format (this); 199 } 200 201 } 202