Skip to content

Commit

Permalink
[CONJS-236] binary TIME wrong decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jan 10, 2023
1 parent 58f4f2e commit be84cc4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/io/packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ class Packet {
const min = this.readUInt8();
const sec = this.readUInt8();
let microSec = 0;
if (len > 7) {
if (len > 8) {
microSec = this.readUInt32();
}
let val = appendZero(hour, 2) + ':' + appendZero(min, 2) + ':' + appendZero(sec, 2);
Expand Down
26 changes: 26 additions & 0 deletions test/integration/datatype/test-time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const base = require('../../base.js');
const { assert } = require('chai');
const { isXpand } = require('../../base');

describe('time', () => {
it('time data', async function () {
if (!base.utf8Collation()) this.skip();

await shareConn.query('DROP TABLE IF EXISTS time_data');
await shareConn.query('CREATE TABLE time_data(t1 time(6), t2 time(6))');
await shareConn.query('INSERT INTO time_data VALUES (?, ?)', ['-838:59:58', '-838:59:59.999999']);
await shareConn.query('INSERT INTO time_data VALUES (?, ?)', ['-1:00:00', '25:00:00']);
let results = await shareConn.query('SELECT * FROM time_data');
assert.equal(results[0].t1, '-838:59:58.000000');
assert.equal(results[0].t2, '-838:59:59.999999');
assert.equal(results[1].t1, '-01:00:00.000000');
assert.equal(results[1].t2, '25:00:00.000000');
results = await shareConn.execute('SELECT * FROM time_data');
assert.equal(results[0].t1, '-838:59:58');
assert.equal(results[0].t2, '-838:59:59.999999');
assert.equal(results[1].t1, '-01:00:00');
assert.equal(results[1].t2, '25:00:00');
});
});

0 comments on commit be84cc4

Please sign in to comment.