freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: "Mark O'Donohue" <mark.odonohue AT ludwig.edu.au>
- To: freetds AT franklin.oit.unc.edu
- Subject: Error in dates > 2040 (and Fix)
- Date: Thu, 9 Nov 2000 23:03:12 -0500
The calculation intermediate in this line
long seconds = (long)((days - 25567)*(24*60*60))
+ (long)(time/300);
defaults to int arithmatic rather than long before the cast. So dates >
2040 are wrong.
The patch below defines days as a long so that the calculation then
defaults to long arithmateic and it doesn't overflow.
Cheers
Mark
*** tmp/freetds_jdbc/Tds.java Wed Sep 29 00:56:24 1999
--- freetds_jdbc/Tds.java Fri Nov 10 14:55:11 2000
***************
*** 1535,1546 ****
result = null;
break;
}
case 8:
{
// It appears that a datetime is made of of 2 32bit ints
// The first one is the number of days since 1900
// The second integer is the number of seconds*300
! int days = comm.getTdsInt();
int time = comm.getTdsInt();
long seconds = (long)((days - 25567)*(24*60*60))
+ (long)(time/300);
--- 1535,1547 ----
result = null;
break;
}
+
case 8:
{
// It appears that a datetime is made of of 2 32bit ints
// The first one is the number of days since 1900
// The second integer is the number of seconds*300
! long days = (long) comm.getTdsInt();
int time = comm.getTdsInt();
long seconds = (long)((days - 25567)*(24*60*60))
+ (long)(time/300);
***************
*** 1559,1565 ****
// the second smallint is the number of minutes past
// midnight.
! int days = comm.getTdsShort();
int minutes = comm.getTdsShort();
long seconds = (long)((days - 25567)*(24*60*60))
+ (long)(minutes * 60);
--- 1562,1568 ----
// the second smallint is the number of minutes past
// midnight.
! long days = (long) comm.getTdsShort();
int minutes = comm.getTdsShort();
long seconds = (long)((days - 25567)*(24*60*60))
+ (long)(minutes * 60);
-
Error in dates > 2040 (and Fix),
Mark O'Donohue, 11/09/2000
- <Possible follow-up(s)>
- Re: Error in dates > 2040 (and Fix), Bob Kline, 11/10/2000
Archive powered by MHonArc 2.6.24.