Skip to content

Commit b26df98

Browse files
committed
Fetch and insert dates with negative years correctly in Thin mode
1 parent 9296ddc commit b26df98

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Thin Mode Changes
2626
increase instead of NUM_HITS in v$cpool_stats view by default. This fix
2727
optimizes the use of DRCP connections.
2828

29+
#) Fixed the issue where dates with negative years are not inserted and
30+
fetched correctly in Thin mode.
31+
2932
node-oracledb `v6.0.2 <https://github.com/oracle/node-oracledb/compare/v6.0.1...v6.0.2>`__ (27 Jun 2023)
3033
--------------------------------------------------------------------------------------------------------
3134

@@ -71,7 +74,6 @@ Thick Mode Changes
7174
#) Fixed bug with getting the value of a LOB stored in a DbObject
7275
`Issue #1571 <https://github.com/oracle/node-oracledb/issues/1571>`__.
7376

74-
7577
node-oracledb `v6.0.1 <https://github.com/oracle/node-oracledb/compare/v6.0.0...v6.0.1>`__ (07 Jun 2023)
7678
--------------------------------------------------------------------------------------------------------
7779

lib/thin/protocol/buffer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ class BaseBuffer {
748748
const ptr = this.reserveBytes(length);
749749
if (type === types.DB_TYPE_DATE || type == types.DB_TYPE_TIMESTAMP) {
750750
const year = date.getFullYear();
751-
ptr[0] = Math.floor(year / 100) + 100;
751+
ptr[0] = Math.trunc(year / 100) + 100;
752752
ptr[1] = year % 100 + 100;
753753
ptr[2] = date.getMonth() + 1;
754754
ptr[3] = date.getDate();
@@ -757,7 +757,7 @@ class BaseBuffer {
757757
ptr[6] = date.getSeconds() + 1;
758758
} else {
759759
const year = date.getUTCFullYear();
760-
ptr[0] = Math.floor(year / 100) + 100;
760+
ptr[0] = Math.trunc(year / 100) + 100;
761761
ptr[1] = year % 100 + 100;
762762
ptr[2] = date.getUTCMonth() + 1;
763763
ptr[3] = date.getUTCDate();

test/dataTypeAssist.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,14 @@ assist.data = {
213213
new Date(10000000000),
214214
new Date(100000000000),
215215
new Date(1995, 11, 17),
216+
new Date(-1995, 11, 17), // Year in BC
216217
new Date('1995-12-17T03:24:00'),
217218
new Date('2015-07-23 21:00:00'),
218219
new Date('2015-07-23 22:00:00'),
219220
new Date('2015-07-23 23:00:00'),
220221
new Date('2015-07-24 00:00:00'),
222+
new Date('100-07-24 00:00:00'),
223+
new Date(-100, 11, 17), // Year in BC
221224
new Date(2003, 9, 23, 11, 50, 30, 123)
222225
]
223226
};

0 commit comments

Comments
 (0)