Skip to content

Commit 96e704e

Browse files
authored
fix: fix roundtrip conversion for LocalDateTime type (#624)
1 parent ca2fd58 commit 96e704e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

python/cocoindex/tests/test_convert.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,19 @@ def test_encode_engine_value_none() -> None:
198198
assert encode_engine_value(None) is None
199199

200200

201-
def test_make_engine_value_decoder_basic_types() -> None:
201+
def test_roundtrip_basic_types() -> None:
202202
validate_full_roundtrip(42, int)
203203
validate_full_roundtrip(3.25, float, (3.25, Float64))
204204
validate_full_roundtrip(3.25, Float64, (3.25, float))
205205
validate_full_roundtrip(3.25, Float32)
206206
validate_full_roundtrip("hello", str)
207207
validate_full_roundtrip(True, bool)
208208
validate_full_roundtrip(False, bool)
209+
validate_full_roundtrip(datetime.date(2025, 1, 1), datetime.date)
210+
validate_full_roundtrip(datetime.datetime.now(), cocoindex.LocalDateTime)
211+
validate_full_roundtrip(
212+
datetime.datetime.now(datetime.UTC), cocoindex.OffsetDateTime
213+
)
209214

210215

211216
@pytest.mark.parametrize(

src/base/value.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,9 @@ impl serde::Serialize for BasicValue {
883883
BasicValue::Uuid(v) => serializer.serialize_str(&v.to_string()),
884884
BasicValue::Date(v) => serializer.serialize_str(&v.to_string()),
885885
BasicValue::Time(v) => serializer.serialize_str(&v.to_string()),
886-
BasicValue::LocalDateTime(v) => serializer.serialize_str(&v.to_string()),
886+
BasicValue::LocalDateTime(v) => {
887+
serializer.serialize_str(&v.format("%Y-%m-%dT%H:%M:%S%.6f").to_string())
888+
}
887889
BasicValue::OffsetDateTime(v) => {
888890
serializer.serialize_str(&v.to_rfc3339_opts(chrono::SecondsFormat::AutoSi, true))
889891
}

0 commit comments

Comments
 (0)