Skip to content

Commit 23a7291

Browse files
committed
Fix for #38
1 parent ce730e9 commit 23a7291

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99
### Fixed
1010

1111
- #34 - Pre-1970 dates causes OverflowError
12+
- #38 - 'datetime.date' object has no attribute 'date'
1213

1314
## [1.10.1] - 2023-12-21
1415

src/firebird/driver/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def _encode_timestamp(v: Union[datetime.datetime, datetime.date]) -> bytes:
176176
if isinstance(v, datetime.datetime):
177177
return _util.encode_date(v.date()).to_bytes(4, 'little') + _util.encode_time(v.time()).to_bytes(4, 'little')
178178
if isinstance(v, datetime.date):
179-
return _util.encode_date(v.date()).to_bytes(4, 'little') + _util.encode_time(datetime.time()).to_bytes(4, 'little')
179+
return _util.encode_date(v).to_bytes(4, 'little') + _util.encode_time(datetime.time()).to_bytes(4, 'little')
180180
raise ValueError("datetime.datetime or datetime.date expected")
181181

182182
def _is_fixed_point(dialect: int, datatype: SQLDataType, subtype: int,

tests/test_driver.py

+10
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,16 @@ def test_insert_datetime(self):
14851485
self.assertListEqual(rows,
14861486
[(5, datetime.date(1859, 11, 16), datetime.time(15, 0, 1, 200000),
14871487
datetime.datetime(1859, 11, 16, 15, 0, 1, 200000))])
1488+
# Pass date instead datetime for timestamp field (fix for #38)
1489+
now = datetime.datetime(2011, 11, 13, 15, 00, 1, 200000)
1490+
cur.execute('insert into T2 (C1,C6,C7,C8) values (?,?,?,?)', [6, now.date(), now.time(), now.date()])
1491+
self.con.commit()
1492+
cur.execute('select C1,C6,C7,C8 from T2 where C1 = 6')
1493+
rows = cur.fetchall()
1494+
self.assertListEqual(rows,
1495+
[(6, datetime.date(2011, 11, 13), datetime.time(15, 0, 1, 200000),
1496+
datetime.datetime(2011, 11, 13, 0, 0, 0, 0))])
1497+
14881498
def test_insert_blob(self):
14891499
with self.con.cursor() as cur, self.con2.cursor() as cur2:
14901500
cur.execute('insert into T2 (C1,C9) values (?,?)', [4, 'This is a BLOB!'])

0 commit comments

Comments
 (0)