Skip to content

Commit b4c24e4

Browse files
committed
fix loss of time component in Value(datetime)
1 parent 0309b8a commit b4c24e4

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

django_mongodb/expressions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ def value(self, compiler, connection): # noqa: ARG001
209209
return {"$literal": value}
210210
if isinstance(value, Decimal):
211211
return Decimal128(value)
212+
if isinstance(value, datetime.datetime):
213+
return value
212214
if isinstance(value, datetime.date):
213215
# Turn dates into datetimes since BSON doesn't support dates.
214216
return datetime.datetime.combine(value, datetime.datetime.min.time())

tests/expressions_/test_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_date(self):
1717
def test_datetime(self):
1818
self.assertEqual(
1919
Value(datetime.datetime(2025, 1, 1, 9, 8, 7)).as_mql(None, None),
20-
datetime.datetime(2025, 1, 1),
20+
datetime.datetime(2025, 1, 1, 9, 8, 7),
2121
)
2222

2323
def test_decimal(self):

0 commit comments

Comments
 (0)