1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
/* * @(#)Time.java 1.33 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package java.sql; /** * <P>A thin wrapper around the <code>java.util.Date</code> class that allows the JDBC * API to identify this as an SQL <code>TIME</code> value. The <code>Time</code> * class adds formatting and * parsing operations to support the JDBC escape syntax for time * values. * <p>The date components should be set to the "zero epoch" * value of January 1, 1970 and should not be accessed. */ public class Time extends java.util.Date { /** * Constructs a <code>Time</code> object initialized with the * given values for the hour, minute, and second. * The driver sets the date components to January 1, 1970. * Any method that attempts to access the date components of a * <code>Time</code> object will throw a * <code>java.lang.IllegalArgumentException</code>. * <P> * The result is undefined if a given argument is out of bounds. * * @param hour 0 to 23 * @param minute 0 to 59 * @param second 0 to 59 * * @deprecated Use the constructor that takes a milliseconds value * in place of this constructor */ @Deprecated public Time(int hour, int minute, int second) { super(70, 0, 1, hour, minute, second); } /** * Constructs a <code>Time</code> object using a milliseconds time value. * * @param time milliseconds since January 1, 1970, 00:00:00 GMT; * a negative number is milliseconds before * January 1, 1970, 00:00:00 GMT */ public Time(long time) { super(time); } /** * Sets a <code>Time</code> object using a milliseconds time value. * * @param time milliseconds since January 1, 1970, 00:00:00 GMT; * a negative number is milliseconds before * January 1, 1970, 00:00:00 GMT */ public void setTime(long time) { super.setTime(time); } /** * Converts a string in JDBC time escape format to a <code>Time</code> value. * * @param s time in format "hh:mm:ss" * @return a corresponding <code>Time</code> object */ public static Time valueOf(String s) { int hour; int minute; int second; int firstColon; int secondColon; if (s == null) throw new java.lang.IllegalArgumentException(); firstColon = s.indexOf(':'); secondColon = s.indexOf(':', firstColon+1); if ((firstColon > 0) & (secondColon > 0) & (secondColon < s.length()-1)) { hour = Integer.parseInt(s.substring(0, firstColon)); minute = Integer.parseInt(s.substring(firstColon+1, secondColon)); second = Integer.parseInt(s.substring(secondColon+1)); } else { throw new java.lang.IllegalArgumentException(); } return new Time(hour, minute, second); } /** * Formats a time in JDBC time escape format. * * @return a <code>String</code> in hh:mm:ss format */ public String toString () { int hour = super.getHours(); int minute = super.getMinutes(); int second = super.getSeconds(); String hourString; String minuteString; String secondString; if (hour < 10) { hourString = "0" + hour; } else { hourString = Integer.toString(hour); } if (minute < 10) { minuteString = "0" + minute; } else { minuteString = Integer.toString(minute); } if (second < 10) { secondString = "0" + second; } else { secondString = Integer.toString(second); } return (hourString + ":" + minuteString + ":" + secondString); } // Override all the date operations inherited from java.util.Date; /** * This method is deprecated and should not be used because SQL <code>TIME</code> * values do not have a year component. * * @deprecated * @exception java.lang.IllegalArgumentException if this * method is invoked * @see #setYear */ @Deprecated public int getYear() { throw new java.lang.IllegalArgumentException(); } /** * This method is deprecated and should not be used because SQL <code>TIME</code> * values do not have a month component. * * @deprecated * @exception java.lang.IllegalArgumentException if this * method is invoked * @see #setMonth */ @Deprecated public int getMonth() { throw new java.lang.IllegalArgumentException(); } /** * This method is deprecated and should not be used because SQL <code>TIME</code> * values do not have a day component. * * @deprecated * @exception java.lang.IllegalArgumentException if this * method is invoked */ @Deprecated public int getDay() { throw new java.lang.IllegalArgumentException(); } /** * This method is deprecated and should not be used because SQL <code>TIME</code> * values do not have a date component. * * @deprecated * @exception java.lang.IllegalArgumentException if this * method is invoked * @see #setDate */ @Deprecated public int getDate() { throw new java.lang.IllegalArgumentException(); } /** * This method is deprecated and should not be used because SQL <code>TIME</code> * values do not have a year component. * * @deprecated * @exception java.lang.IllegalArgumentException if this * method is invoked * @see #getYear */ @Deprecated public void setYear(int i) { throw new java.lang.IllegalArgumentException(); } /** * This method is deprecated and should not be used because SQL <code>TIME</code> * values do not have a month component. * * @deprecated * @exception java.lang.IllegalArgumentException if this * method is invoked * @see #getMonth */ @Deprecated public void setMonth(int i) { throw new java.lang.IllegalArgumentException(); } /** * This method is deprecated and should not be used because SQL <code>TIME</code> * values do not have a date component. * * @deprecated * @exception java.lang.IllegalArgumentException if this * method is invoked * @see #getDate */ @Deprecated public void setDate(int i) { throw new java.lang.IllegalArgumentException(); } /** * Private serial version unique ID to ensure serialization * compatibility. */ static final long serialVersionUID = 8397324403548013681L; }