0N/A/*
2362N/A * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.sql;
0N/A
0N/A/**
0N/A * <P>A thin wrapper around the <code>java.util.Date</code> class that allows the JDBC
0N/A * API to identify this as an SQL <code>TIME</code> value. The <code>Time</code>
0N/A * class adds formatting and
0N/A * parsing operations to support the JDBC escape syntax for time
0N/A * values.
0N/A * <p>The date components should be set to the "zero epoch"
0N/A * value of January 1, 1970 and should not be accessed.
0N/A */
0N/Apublic class Time extends java.util.Date {
0N/A
0N/A /**
0N/A * Constructs a <code>Time</code> object initialized with the
0N/A * given values for the hour, minute, and second.
0N/A * The driver sets the date components to January 1, 1970.
0N/A * Any method that attempts to access the date components of a
0N/A * <code>Time</code> object will throw a
0N/A * <code>java.lang.IllegalArgumentException</code>.
0N/A * <P>
0N/A * The result is undefined if a given argument is out of bounds.
0N/A *
0N/A * @param hour 0 to 23
0N/A * @param minute 0 to 59
0N/A * @param second 0 to 59
0N/A *
0N/A * @deprecated Use the constructor that takes a milliseconds value
0N/A * in place of this constructor
0N/A */
0N/A @Deprecated
0N/A public Time(int hour, int minute, int second) {
0N/A super(70, 0, 1, hour, minute, second);
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>Time</code> object using a milliseconds time value.
0N/A *
0N/A * @param time milliseconds since January 1, 1970, 00:00:00 GMT;
0N/A * a negative number is milliseconds before
0N/A * January 1, 1970, 00:00:00 GMT
0N/A */
0N/A public Time(long time) {
0N/A super(time);
0N/A }
0N/A
0N/A /**
0N/A * Sets a <code>Time</code> object using a milliseconds time value.
0N/A *
0N/A * @param time milliseconds since January 1, 1970, 00:00:00 GMT;
0N/A * a negative number is milliseconds before
0N/A * January 1, 1970, 00:00:00 GMT
0N/A */
0N/A public void setTime(long time) {
0N/A super.setTime(time);
0N/A }
0N/A
0N/A /**
0N/A * Converts a string in JDBC time escape format to a <code>Time</code> value.
0N/A *
0N/A * @param s time in format "hh:mm:ss"
0N/A * @return a corresponding <code>Time</code> object
0N/A */
0N/A public static Time valueOf(String s) {
0N/A int hour;
0N/A int minute;
0N/A int second;
0N/A int firstColon;
0N/A int secondColon;
0N/A
0N/A if (s == null) throw new java.lang.IllegalArgumentException();
0N/A
0N/A firstColon = s.indexOf(':');
0N/A secondColon = s.indexOf(':', firstColon+1);
0N/A if ((firstColon > 0) & (secondColon > 0) &
0N/A (secondColon < s.length()-1)) {
0N/A hour = Integer.parseInt(s.substring(0, firstColon));
0N/A minute =
0N/A Integer.parseInt(s.substring(firstColon+1, secondColon));
0N/A second = Integer.parseInt(s.substring(secondColon+1));
0N/A } else {
0N/A throw new java.lang.IllegalArgumentException();
0N/A }
0N/A
0N/A return new Time(hour, minute, second);
0N/A }
0N/A
0N/A /**
0N/A * Formats a time in JDBC time escape format.
0N/A *
0N/A * @return a <code>String</code> in hh:mm:ss format
0N/A */
0N/A public String toString () {
0N/A int hour = super.getHours();
0N/A int minute = super.getMinutes();
0N/A int second = super.getSeconds();
0N/A String hourString;
0N/A String minuteString;
0N/A String secondString;
0N/A
0N/A if (hour < 10) {
0N/A hourString = "0" + hour;
0N/A } else {
0N/A hourString = Integer.toString(hour);
0N/A }
0N/A if (minute < 10) {
0N/A minuteString = "0" + minute;
0N/A } else {
0N/A minuteString = Integer.toString(minute);
0N/A }
0N/A if (second < 10) {
0N/A secondString = "0" + second;
0N/A } else {
0N/A secondString = Integer.toString(second);
0N/A }
0N/A return (hourString + ":" + minuteString + ":" + secondString);
0N/A }
0N/A
0N/A // Override all the date operations inherited from java.util.Date;
0N/A
0N/A /**
0N/A * This method is deprecated and should not be used because SQL <code>TIME</code>
0N/A * values do not have a year component.
0N/A *
0N/A * @deprecated
0N/A * @exception java.lang.IllegalArgumentException if this
0N/A * method is invoked
0N/A * @see #setYear
0N/A */
0N/A @Deprecated
0N/A public int getYear() {
0N/A throw new java.lang.IllegalArgumentException();
0N/A }
0N/A
0N/A /**
0N/A * This method is deprecated and should not be used because SQL <code>TIME</code>
0N/A * values do not have a month component.
0N/A *
0N/A * @deprecated
0N/A * @exception java.lang.IllegalArgumentException if this
0N/A * method is invoked
0N/A * @see #setMonth
0N/A */
0N/A @Deprecated
0N/A public int getMonth() {
0N/A throw new java.lang.IllegalArgumentException();
0N/A }
0N/A
0N/A /**
0N/A * This method is deprecated and should not be used because SQL <code>TIME</code>
0N/A * values do not have a day component.
0N/A *
0N/A * @deprecated
0N/A * @exception java.lang.IllegalArgumentException if this
0N/A * method is invoked
0N/A */
0N/A @Deprecated
0N/A public int getDay() {
0N/A throw new java.lang.IllegalArgumentException();
0N/A }
0N/A
0N/A /**
0N/A * This method is deprecated and should not be used because SQL <code>TIME</code>
0N/A * values do not have a date component.
0N/A *
0N/A * @deprecated
0N/A * @exception java.lang.IllegalArgumentException if this
0N/A * method is invoked
0N/A * @see #setDate
0N/A */
0N/A @Deprecated
0N/A public int getDate() {
0N/A throw new java.lang.IllegalArgumentException();
0N/A }
0N/A
0N/A /**
0N/A * This method is deprecated and should not be used because SQL <code>TIME</code>
0N/A * values do not have a year component.
0N/A *
0N/A * @deprecated
0N/A * @exception java.lang.IllegalArgumentException if this
0N/A * method is invoked
0N/A * @see #getYear
0N/A */
0N/A @Deprecated
0N/A public void setYear(int i) {
0N/A throw new java.lang.IllegalArgumentException();
0N/A }
0N/A
0N/A /**
0N/A * This method is deprecated and should not be used because SQL <code>TIME</code>
0N/A * values do not have a month component.
0N/A *
0N/A * @deprecated
0N/A * @exception java.lang.IllegalArgumentException if this
0N/A * method is invoked
0N/A * @see #getMonth
0N/A */
0N/A @Deprecated
0N/A public void setMonth(int i) {
0N/A throw new java.lang.IllegalArgumentException();
0N/A }
0N/A
0N/A /**
0N/A * This method is deprecated and should not be used because SQL <code>TIME</code>
0N/A * values do not have a date component.
0N/A *
0N/A * @deprecated
0N/A * @exception java.lang.IllegalArgumentException if this
0N/A * method is invoked
0N/A * @see #getDate
0N/A */
0N/A @Deprecated
0N/A public void setDate(int i) {
0N/A throw new java.lang.IllegalArgumentException();
0N/A }
0N/A
0N/A /**
0N/A * Private serial version unique ID to ensure serialization
0N/A * compatibility.
0N/A */
0N/A static final long serialVersionUID = 8397324403548013681L;
0N/A}