Package net.sourceforge.jtds.jdbc
Class DateTime
java.lang.Object
net.sourceforge.jtds.jdbc.DateTime
Encapsulates 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
FieldsModifier and TypeFieldDescriptionprivate int
The date component of the server datetime value.(package private) static final int
Indicates date value not used.private Date
Cached value of the datetime as ajava.sql.Date
.private short
Unpacked day value.private short
Unpacked hour value.private short
Unpacked millisecond value.private short
Unpacked minute value.private short
Unpacked month value.private short
Unpacked second value.private String
Cached value of the datetime as aString
.private int
The time component of the server datetime value.(package private) static final int
Indicates time value not used.private Time
Cached value of the datetime as ajava.sql.Time
.private Timestamp
Cached value of the datetime as ajava.sql.Timestamp
.private boolean
Indicates server datetime values have been unpacked.private short
Unpacked year value. -
Constructor Summary
ConstructorsConstructorDescriptionDateTime
(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.Constructs a DateTime object from ajava.sql.Date
.Constructs a DateTime object from ajava.sql.Time
.Constructs a DateTime object from ajava.sql.Timestamp
. -
Method Summary
Modifier and TypeMethodDescription(package private) int
getDate()
Retrieves the date component of a datetime value.(package private) int
getTime()
Retrieves the time component of a datetime value.void
packDate()
Converts a calendar date into days since 1900 (Sybase epoch).void
packTime()
Converts separate time components into a datetime time value.toDate()
Retrieves the current datetime value as a Date.toObject()
Retrieves the current datetime value as a Time, Date or Timestamp.toString()
Retrieves the current datetime value as a String.toTime()
Retrieves the current datetime value as a Time.Retrieves the current datetime value as a Timestamp.private void
Converts a Julian datetime from the Sybase epoch of 1900-01-01 to the equivalent unpacked year/month/day etc.
-
Field Details
-
DATE_NOT_USED
static final int DATE_NOT_USEDIndicates date value not used.- See Also:
-
TIME_NOT_USED
static final int TIME_NOT_USEDIndicates time value not used.- See Also:
-
date
private int dateThe date component of the server datetime value. -
time
private int timeThe time component of the server datetime value. -
year
private short yearUnpacked year value. -
month
private short monthUnpacked month value. -
day
private short dayUnpacked day value. -
hour
private short hourUnpacked hour value. -
minute
private short minuteUnpacked minute value. -
second
private short secondUnpacked second value. -
millis
private short millisUnpacked millisecond value. -
unpacked
private boolean unpackedIndicates server datetime values have been unpacked. -
stringValue
Cached value of the datetime as aString
. -
tsValue
Cached value of the datetime as ajava.sql.Timestamp
. -
dateValue
Cached value of the datetime as ajava.sql.Date
. -
timeValue
Cached value of the datetime as ajava.sql.Time
.
-
-
Constructor Details
-
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(Timestamp ts) throws SQLException Constructs a DateTime object from ajava.sql.Timestamp
.- Parameters:
ts
-Timestamp
object representing the datetime- Throws:
SQLException
- if the date is out of range
-
DateTime
DateTime(Time t) throws SQLException Constructs a DateTime object from ajava.sql.Time
.- Parameters:
t
-Time
object representing the datetime- Throws:
SQLException
- if the time (date) is out of range
-
DateTime
DateTime(Date d) throws SQLException Constructs a DateTime object from ajava.sql.Date
.- Parameters:
d
-Date
object representing the datetime- Throws:
SQLException
- if the Date is out of range
-
-
Method Details
-
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
Converts 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:
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
Retrieves the current datetime value as a Timestamp.- Returns:
- the current datetime value as a
java.sql.Timestamp
-
toDate
Retrieves the current datetime value as a Date.- Returns:
- the current datetime value as a
java.sql.Date
-
toTime
Retrieves the current datetime value as a Time.- Returns:
- the current datetime value as a
java.sql.Time
-
toObject
Retrieves the current datetime value as a Time, Date or Timestamp.- Returns:
- the current datetime value as an
java.lang.Object
-
toString
Retrieves the current datetime value as a String.
-