Skip to Content.
Sympa Menu

freetds - jTDS: Timestamp Problem

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Oliver, Guy L" <OliverG AT BATTELLE.ORG>
  • To: "'freetds AT franklin.oit.unc.edu'" <freetds AT franklin.oit.unc.edu>
  • Subject: jTDS: Timestamp Problem
  • Date: Thu, 30 Aug 2001 15:20:32 -0400


While working with the code for the old freetds_jdbc project, I found a
small bug with how timestamps are handled. After reading the posts to the
mailing list and finding out that the jTDS project was effectively the
replacement for the old jdbc code, I got my hands on a copy of it and found
that the bug still exists in this code base.

Its a very simple problem that has to do with daylight savings time and
converting to and from the format used in the tds stream.

Basically, when you convert from tds to java, it seems to work ok. What is
done in this case is that the zoneOffset is subtracted from the final time,
as is the Daylight savings time offset.

In order to convert from java to tds, the exact opposite should be done, and
you add these values back on.

But when converting from Java to tds, the daylight savings offset is
subtracted, not added to the final time. The end result is that all the
timestamp values that you try to put into a database (in an area with
daylight saving time and during a time when its in effect) are about 2 hours
behind. By simply changing the subtraction of the dstOffset to an addition,
the problem goes away.

Below I attached the diff showing the two changes. The Tds.org file is the
original file from anon cvs. Tds.java shows my changes. (minor though they
were)


*** Tds.org Thu Aug 30 15:08:35 2001
--- Tds.java Thu Aug 30 15:06:35 2001
***************
*** 836,842 ****

long ms = ((value.getTime() + (nanoseconds /
nsPerMs))
+ zoneOffset);
! ms -= getDstOffset(ms);
long msIntoCurrentDay = ms % msPerDay;

long daysIntoUnixEpoch = (ms -
msIntoCurrentDay) / msPerDay;
--- 836,842 ----

long ms = ((value.getTime() + (nanoseconds /
nsPerMs))
+ zoneOffset);
! ms += getDstOffset(ms);
long msIntoCurrentDay = ms % msPerDay;

long daysIntoUnixEpoch = (ms -
msIntoCurrentDay) / msPerDay;





Archive powered by MHonArc 2.6.24.

Top of Page