r2dbc / r2dbc-mssql

R2DBC Driver for Microsoft SQL Server using TDS (Tabular Data Stream) Protocol
Apache License 2.0
183 stars 32 forks source link

`OffsetDateTimeCodec` does not properly decode negative timezone offsets #208

Closed italiviocorrea closed 3 years ago

italiviocorrea commented 3 years ago

Bug Report

I'm using the latest driver 0.8.6.

I have a field in an MSSQLServer table that is of the DateTimeOffSet type, and I realized that when the timezone is negative it ignores the signal and treats it as a positive timezone. Analyzing the code of the OffsetDateTimeCodec Class, in line 87 we have a call to the uShort method of the Decode class, which converts the buffer to an unsigned integer.

     int localMinutesOffset = Decode.uShort (buffer);

This removes the TimeZone signal when it is negative. The correct thing would be to do this:

     int localMinutesOffset = Decode.Short (buffer);

As the Short method does not exist in the Decode class, it would be necessary to add it to this class, as in the example below:

 public static int Short (ByteBuf buffer) {
     return buffer.readShortLE ();
 }

With this simple change, the negative and positive timezones will be decoded correctly.

mp911de commented 3 years ago

Are you interested in providing a pull request that contains the fix and a way to reproduce the issue?

italiviocorrea commented 3 years ago

Hey! I can make the correction yes, it's up to you. Even because I made a fork and I'm using it with the fix, so far this solution is ok. I'm not practice pull request, but I'm a fast learner and I have a lot of experience in java programming, suddenly I can help fix other bugs. And I'm already using the lib in one project, which I'm currently working on, and I plan to use it in other projects.