Package net.sourceforge.jtds.jdbc
Class DateTime
- java.lang.Object
-
- net.sourceforge.jtds.jdbc.DateTime
-
public class DateTime extends java.lang.ObjectEncapsulates Sybase date/time values and provides conversions to and from Java classes.- Version:
- $Id: DateTime.java,v 1.4.2.2 2009-08-20 19:44:04 ickzon Exp $
- Author:
- Mike Hutchinson
-
-
Field Summary
Fields Modifier and Type Field Description private intdateThe date component of the server datetime value.(package private) static intDATE_NOT_USEDIndicates date value not used.private java.sql.DatedateValueCached value of the datetime as ajava.sql.Date.private shortdayUnpacked day value.private shorthourUnpacked hour value.private shortmillisUnpacked millisecond value.private shortminuteUnpacked minute value.private shortmonthUnpacked month value.private shortsecondUnpacked second value.private java.lang.StringstringValueCached value of the datetime as aString.private inttimeThe time component of the server datetime value.(package private) static intTIME_NOT_USEDIndicates time value not used.private java.sql.TimetimeValueCached value of the datetime as ajava.sql.Time.private java.sql.TimestamptsValueCached value of the datetime as ajava.sql.Timestamp.private booleanunpackedIndicates server datetime values have been unpacked.private shortyearUnpacked year value.
-
Constructor Summary
Constructors Constructor Description DateTime(int date, int time)Constructs a DateTime object from the two integer components of a datetime.DateTime(short date, short time)Constructs a DateTime object from the two short components of a smalldatetime.DateTime(java.sql.Date d)Constructs a DateTime object from ajava.sql.Date.DateTime(java.sql.Time t)Constructs a DateTime object from ajava.sql.Time.DateTime(java.sql.Timestamp ts)Constructs a DateTime object from ajava.sql.Timestamp.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) intgetDate()Retrieves the date component of a datetime value.(package private) intgetTime()Retrieves the time component of a datetime value.voidpackDate()Converts a calendar date into days since 1900 (Sybase epoch).voidpackTime()Converts separate time components into a datetime time value.java.sql.DatetoDate()Retrieves the current datetime value as a Date.java.lang.ObjecttoObject()Retrieves the current datetime value as a Time, Date or Timestamp.java.lang.StringtoString()Retrieves the current datetime value as a String.java.sql.TimetoTime()Retrieves the current datetime value as a Time.java.sql.TimestamptoTimestamp()Retrieves the current datetime value as a Timestamp.private voidunpackDateTime()Converts a Julian datetime from the Sybase epoch of 1900-01-01 to the equivalent unpacked year/month/day etc.
-
-
-
Field Detail
-
DATE_NOT_USED
static final int DATE_NOT_USED
Indicates date value not used.- See Also:
- Constant Field Values
-
TIME_NOT_USED
static final int TIME_NOT_USED
Indicates time value not used.- See Also:
- Constant Field Values
-
date
private int date
The date component of the server datetime value.
-
time
private int time
The time component of the server datetime value.
-
year
private short year
Unpacked year value.
-
month
private short month
Unpacked month value.
-
day
private short day
Unpacked day value.
-
hour
private short hour
Unpacked hour value.
-
minute
private short minute
Unpacked minute value.
-
second
private short second
Unpacked second value.
-
millis
private short millis
Unpacked millisecond value.
-
unpacked
private boolean unpacked
Indicates server datetime values have been unpacked.
-
stringValue
private java.lang.String stringValue
Cached value of the datetime as aString.
-
tsValue
private java.sql.Timestamp tsValue
Cached value of the datetime as ajava.sql.Timestamp.
-
dateValue
private java.sql.Date dateValue
Cached value of the datetime as ajava.sql.Date.
-
timeValue
private java.sql.Time timeValue
Cached value of the datetime as ajava.sql.Time.
-
-
Constructor Detail
-
DateTime
DateTime(int date, int time)Constructs a DateTime object from the two integer components of a datetime.- Parameters:
date- server date fieldtime- server time field
-
DateTime
DateTime(short date, short time)Constructs a DateTime object from the two short components of a smalldatetime.- Parameters:
date- server date fieldtime- server time field
-
DateTime
DateTime(java.sql.Timestamp ts) throws java.sql.SQLException
Constructs a DateTime object from ajava.sql.Timestamp.- Parameters:
ts-Timestampobject representing the datetime- Throws:
java.sql.SQLException- if the date is out of range
-
DateTime
DateTime(java.sql.Time t) throws java.sql.SQLException
Constructs a DateTime object from ajava.sql.Time.- Parameters:
t-Timeobject representing the datetime- Throws:
java.sql.SQLException- if the time (date) is out of range
-
DateTime
DateTime(java.sql.Date d) throws java.sql.SQLException
Constructs a DateTime object from ajava.sql.Date.- Parameters:
d-Dateobject representing the datetime- Throws:
java.sql.SQLException- if the Date is out of range
-
-
Method Detail
-
getDate
int getDate()
Retrieves the date component of a datetime value.- Returns:
- the datetime date component as an
int
-
getTime
int getTime()
Retrieves the time component of a datetime value.- Returns:
- the datetime time component as an
int
-
unpackDateTime
private void unpackDateTime()
Converts a Julian datetime from the Sybase epoch of 1900-01-01 to the equivalent unpacked year/month/day etc. Algorithm from Fliegel, H F and van Flandern, T C (1968). Communications of the ACM, Vol 11, No 10 (October, 1968).SUBROUTINE GDATE (JD, YEAR,MONTH,DAY) C C---COMPUTES THE GREGORIAN CALENDAR DATE (YEAR,MONTH,DAY) C GIVEN THE JULIAN DATE (JD). C INTEGER JD,YEAR,MONTH,DAY,I,J,K C L= JD+68569 N= 4*L/146097 L= L-(146097*N+3)/4 I= 4000*(L+1)/1461001 L= L-1461*I/4+31 J= 80*L/2447 K= L-2447*J/80 L= J/11 J= J+2-12*L I= 100*(N-49)+I+L C YEAR= I MONTH= J DAY= K C RETURN END
-
packDate
public void packDate() throws java.sql.SQLExceptionConverts a calendar date into days since 1900 (Sybase epoch).Algorithm from Fliegel, H F and van Flandern, T C (1968). Communications of the ACM, Vol 11, No 10 (October, 1968).
INTEGER FUNCTION JD (YEAR,MONTH,DAY) C C---COMPUTES THE JULIAN DATE (JD) GIVEN A GREGORIAN CALENDAR C DATE (YEAR,MONTH,DAY). C INTEGER YEAR,MONTH,DAY,I,J,K C I= YEAR J= MONTH K= DAY C JD= K-32075+1461*(I+4800+(J-14)/12)/4+367*(J-2-(J-14)/12*12) 2 /12-3*((I+4900+(J-14)/12)/100)/4 C RETURN END- Throws:
java.sql.SQLException- if the date is outside the accepted range, 1753-9999
-
packTime
public void packTime()
Converts separate time components into a datetime time value.
-
toTimestamp
public java.sql.Timestamp toTimestamp()
Retrieves the current datetime value as a Timestamp.- Returns:
- the current datetime value as a
java.sql.Timestamp
-
toDate
public java.sql.Date toDate()
Retrieves the current datetime value as a Date.- Returns:
- the current datetime value as a
java.sql.Date
-
toTime
public java.sql.Time toTime()
Retrieves the current datetime value as a Time.- Returns:
- the current datetime value as a
java.sql.Time
-
toObject
public java.lang.Object toObject()
Retrieves the current datetime value as a Time, Date or Timestamp.- Returns:
- the current datetime value as an
java.lang.Object
-
toString
public java.lang.String toString()
Retrieves the current datetime value as a String.- Overrides:
toStringin classjava.lang.Object- Returns:
- the current datetime value as a
String
-
-