Skip to content

Commit a74eb07

Browse files
authored
Merge pull request #681 from ydb-platform/fix_datetime_to_date_cast
Ability to create Date type from datetime
2 parents 2582597 + afa366d commit a74eb07

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ sqlalchemy==1.4.26
4646
pylint-protobuf
4747
cython
4848
freezegun==1.2.2
49-
pytest-cov
49+
# pytest-cov
5050
yandexcloud
5151
-e .

ydb/types.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ def _from_date(x: ydb_value_pb2.Value, table_client_settings: table.TableClientS
3333
return x.uint32_value
3434

3535

36-
def _to_date(pb: ydb_value_pb2.Value, value: typing.Union[date, int]) -> None:
37-
if isinstance(value, date):
36+
def _to_date(pb: ydb_value_pb2.Value, value: typing.Union[date, datetime, int]) -> None:
37+
if isinstance(value, datetime):
38+
pb.uint32_value = (value.date() - _EPOCH.date()).days
39+
elif isinstance(value, date):
3840
pb.uint32_value = (value - _EPOCH.date()).days
3941
else:
4042
pb.uint32_value = value

0 commit comments

Comments
 (0)