#178 datetime decoding in TdsData.java

v1.2
closed
5
2012-08-16
2004-07-21
No

Per the sqlserver2000 docs dates in sqlserver are
stored with a percision of 1/300th of a millisecond.
With the following rounding applied:

01/01/98 23:59:59.999 = 1998-01-02 00:00:00.000

01/01/98 23:59:59.995,
01/01/98 23:59:59.996,
01/01/98 23:59:59.997,
01/01/98 23:59:59.998 = 1998-01-01 23:59:59.997

01/01/98 23:59:59.992,
01/01/98 23:59:59.993,
01/01/98 23:59:59.994 = 1998-01-01 23:59:59.993

01/01/98 23:59:59.990
01/01/98 23:59:59.991 = 1998-01-01 23:59:59.990

This rounding is what is implemented in the decoding of
the stream in TdsData.java. It is using just javas
math.round.

                daysSince1900 = in.readInt();
                sybaseToCalendar(daysSince1900, cal);
                time = in.readInt();
                hours = time / 1080000;
                cal.set(Calendar.HOUR_OF_DAY, hours);
                time = time - hours * 1080000;
                minutes = time / 18000;
                cal.set(Calendar.MINUTE, minutes);
                time = time - (minutes * 18000);
                seconds = time / 300;
                cal.set(Calendar.SECOND, seconds);
                time = time - seconds * 300;
                time = (int) Math.round(time * 1000

/ 300f);
cal.set(Calendar.MILLISECOND, time);

Discussion

  • James Nelson

    James Nelson - 2004-07-21

    Logged In: YES
    user_id=135226

    Sorry for the english, I ment to imply that what exists in
    TdsData.java is incorrect. The currentl Alg. doesn't seem
    to match the spec.

     
  • Brian Heineman

    Brian Heineman - 2004-07-21

    Logged In: YES
    user_id=716174

    James,

    Thank you for the bug report. This has been fixed for the 0.9
    release. 10 tests (for the cases you provided) have been
    added to ensure this functionality continues to work in the
    future.

    -Brian

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks