/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* <P>A thin wrapper around <code>java.util.Date</code> that allows
* the JDBC API to identify this as an SQL <code>TIMESTAMP</code> value.
* It adds the ability
* to hold the SQL <code>TIMESTAMP</code> fractional seconds value, by allowing
* the specification of fractional seconds to a precision of nanoseconds.
* A Timestamp also provides formatting and
* parsing operations to support the JDBC escape syntax for timestamp values.
*
* <p>The precision of a Timestamp object is calculated to be either:
* <ul>
* <li><code>19 </code>, which is the number of characters in yyyy-mm-dd hh:mm:ss
* <li> <code> 20 + s </code>, which is the number
* of characters in the yyyy-mm-dd hh:mm:ss.[fff...] and <code>s</code> represents the scale of the given Timestamp,
* its fractional seconds precision.
*</ul>
*
* <P><B>Note:</B> This type is a composite of a <code>java.util.Date</code> and a
* separate nanoseconds value. Only integral seconds are stored in the
* <code>java.util.Date</code> component. The fractional seconds - the nanos - are
* separate. The <code>Timestamp.equals(Object)</code> method never returns
* <code>true</code> when passed an object
* that isn't an instance of <code>java.sql.Timestamp</code>,
* because the nanos component of a date is unknown.
* As a result, the <code>Timestamp.equals(Object)</code>
* method is not symmetric with respect to the
* <code>java.util.Date.equals(Object)</code>
* method. Also, the <code>hashCode</code> method uses the underlying
* <code>java.util.Date</code>
* implementation and therefore does not include nanos in its computation.
* <P>
* Due to the differences between the <code>Timestamp</code> class
* and the <code>java.util.Date</code>
* class mentioned above, it is recommended that code not view
* <code>Timestamp</code> values generically as an instance of
* <code>java.util.Date</code>. The
* inheritance relationship between <code>Timestamp</code>
* and <code>java.util.Date</code> really
* denotes implementation inheritance, and not type inheritance.
*/
/**
* Constructs a <code>Timestamp</code> object initialized
* with the given values.
*
* @param year the year minus 1900
* @param month 0 to 11
* @param date 1 to 31
* @param hour 0 to 23
* @param minute 0 to 59
* @param second 0 to 59
* @param nano 0 to 999,999,999
* @deprecated instead use the constructor <code>Timestamp(long millis)</code>
* @exception IllegalArgumentException if the nano argument is out of bounds
*/
throw new IllegalArgumentException("nanos > 999999999 or < 0");
}
}
/**
* Constructs a <code>Timestamp</code> object
* using a milliseconds time value. The
* integral seconds are stored in the underlying date value; the
* fractional seconds are stored in the <code>nanos</code> field of
* the <code>Timestamp</code> object.
*
* @param time milliseconds since January 1, 1970, 00:00:00 GMT.
* A negative number is the number of milliseconds before
* January 1, 1970, 00:00:00 GMT.
* @see java.util.Calendar
*/
if (nanos < 0) {
}
}
/**
* Sets this <code>Timestamp</code> object to represent a point in time that is
* <tt>time</tt> milliseconds after January 1, 1970 00:00:00 GMT.
*
* @param time the number of milliseconds.
* @see #getTime
* @see #Timestamp(long time)
* @see java.util.Calendar
*/
if (nanos < 0) {
}
}
/**
* Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
* represented by this <code>Timestamp</code> object.
*
* @return the number of milliseconds since January 1, 1970, 00:00:00 GMT
* represented by this date.
* @see #setTime
*/
public long getTime() {
}
/**
* @serial
*/
private int nanos;
/**
* Converts a <code>String</code> object in JDBC timestamp escape format to a
* <code>Timestamp</code> value.
*
* @param s timestamp in format <code>yyyy-[m]m-[d]d hh:mm:ss[.f...]</code>. The
* fractional seconds may be omitted. The leading zero for <code>mm</code>
* and <code>dd</code> may also be omitted.
*
* @return corresponding <code>Timestamp</code> value
* @exception java.lang.IllegalArgumentException if the given argument
* does not have the format <code>yyyy-[m]m-[d]d hh:mm:ss[.f...]</code>
*/
final int YEAR_LENGTH = 4;
final int MONTH_LENGTH = 2;
final int DAY_LENGTH = 2;
final int MAX_MONTH = 12;
final int MAX_DAY = 31;
int year = 0;
int month = 0;
int day = 0;
int hour;
int minute;
int second;
int a_nanos = 0;
int firstDash;
int secondDash;
int dividingSpace;
int firstColon = 0;
int secondColon = 0;
int period = 0;
// Split the string into date and time components
s = s.trim();
if (dividingSpace > 0) {
} else {
}
// Parse the date
// Parse the time
// Convert the date
boolean parsedDate = false;
parsedDate = true;
}
}
}
if (! parsedDate) {
}
// Convert the time; default missing nanos
minute =
second =
} else if (period > 0) {
} else {
}
} else {
}
}
/**
* Formats a timestamp in JDBC timestamp escape format.
* <code>yyyy-mm-dd hh:mm:ss.fffffffff</code>,
* where <code>ffffffffff</code> indicates nanoseconds.
* <P>
* @return a <code>String</code> object in
* <code>yyyy-mm-dd hh:mm:ss.fffffffff</code> format
*/
int minute = super.getMinutes();
int second = super.getSeconds();
if (year < 1000) {
// Add leading zeros
} else {
}
if (month < 10) {
} else {
}
if (day < 10) {
} else {
}
if (hour < 10) {
} else {
}
if (minute < 10) {
} else {
}
if (second < 10) {
} else {
}
if (nanos == 0) {
nanosString = "0";
} else {
// Add leading zeros
// Truncate trailing zeros
int truncIndex = 8;
truncIndex--;
}
}
// do a string buffer here instead.
return (timestampBuf.toString());
}
/**
* Gets this <code>Timestamp</code> object's <code>nanos</code> value.
*
* @return this <code>Timestamp</code> object's fractional seconds component
* @see #setNanos
*/
public int getNanos() {
return nanos;
}
/**
* Sets this <code>Timestamp</code> object's <code>nanos</code> field
* to the given value.
*
* @param n the new fractional seconds component
* @exception java.lang.IllegalArgumentException if the given argument
* is greater than 999999999 or less than 0
* @see #getNanos
*/
public void setNanos(int n) {
if (n > 999999999 || n < 0) {
throw new IllegalArgumentException("nanos > 999999999 or < 0");
}
nanos = n;
}
/**
* Tests to see if this <code>Timestamp</code> object is
* equal to the given <code>Timestamp</code> object.
*
* @param ts the <code>Timestamp</code> value to compare with
* @return <code>true</code> if the given <code>Timestamp</code>
* object is equal to this <code>Timestamp</code> object;
* <code>false</code> otherwise
*/
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* Tests to see if this <code>Timestamp</code> object is
* equal to the given object.
*
* This version of the method <code>equals</code> has been added
* to fix the incorrect
* signature of <code>Timestamp.equals(Timestamp)</code> and to preserve backward
* compatibility with existing class files.
*
* Note: This method is not symmetric with respect to the
* <code>equals(Object)</code> method in the base class.
*
* @param ts the <code>Object</code> value to compare with
* @return <code>true</code> if the given <code>Object</code> is an instance
* of a <code>Timestamp</code> that
* is equal to this <code>Timestamp</code> object;
* <code>false</code> otherwise
*/
} else {
return false;
}
}
/**
* Indicates whether this <code>Timestamp</code> object is
* earlier than the given <code>Timestamp</code> object.
*
* @param ts the <code>Timestamp</code> value to compare with
* @return <code>true</code> if this <code>Timestamp</code> object is earlier;
* <code>false</code> otherwise
*/
}
/**
* Indicates whether this <code>Timestamp</code> object is
* later than the given <code>Timestamp</code> object.
*
* @param ts the <code>Timestamp</code> value to compare with
* @return <code>true</code> if this <code>Timestamp</code> object is later;
* <code>false</code> otherwise
*/
}
/**
* Compares this <code>Timestamp</code> object to the given
* <code>Timestamp</code> object.
*
* @param ts the <code>Timestamp</code> object to be compared to
* this <code>Timestamp</code> object
* @return the value <code>0</code> if the two <code>Timestamp</code>
* objects are equal; a value less than <code>0</code> if this
* <code>Timestamp</code> object is before the given argument;
* and a value greater than <code>0</code> if this
* <code>Timestamp</code> object is after the given argument.
* @since 1.4
*/
if (i == 0) {
return 1;
return -1;
}
}
return i;
}
/**
* Compares this <code>Timestamp</code> object to the given
* <code>Date</code> object.
*
* @param o the <code>Date</code> to be compared to
* this <code>Timestamp</code> object
* @return the value <code>0</code> if this <code>Timestamp</code> object
* and the given object are equal; a value less than <code>0</code>
* if this <code>Timestamp</code> object is before the given argument;
* and a value greater than <code>0</code> if this
* <code>Timestamp</code> object is after the given argument.
*
* @since 1.5
*/
if(o instanceof Timestamp) {
// When Timestamp instance compare it with a Timestamp
// Hence it is basically calling this.compareTo((Timestamp))o);
// Note typecasting is safe because o is instance of Timestamp
} else {
// When Date doing a o.compareTo(this)
// will give wrong results.
}
}
/**
* {@inheritDoc}
*
* The {@code hashCode} method uses the underlying {@code java.util.Date}
* implementation and therefore does not include nanos in its computation.
*
*/
public int hashCode() {
return super.hashCode();
}
}