|
24 | 24 | from cassandra.cqltypes import ( |
25 | 25 | CassandraType, DateRangeType, DateType, DecimalType, |
26 | 26 | EmptyValue, LongType, SetType, UTF8Type, |
27 | | - cql_typename, int8_pack, int64_pack, lookup_casstype, |
| 27 | + cql_typename, int8_pack, int64_pack, int64_unpack, lookup_casstype, |
28 | 28 | lookup_casstype_simple, parse_casstype_args, |
29 | 29 | int32_pack, Int32Type, ListType, MapType, VectorType, |
30 | 30 | FloatType |
@@ -241,6 +241,21 @@ def test_datetype(self): |
241 | 241 | expected = 2177403010.123 |
242 | 242 | assert DateType.deserialize(int64_pack(int(1000 * expected)), 0) == datetime.datetime(2038, 12, 31, 10, 10, 10, 123000, tzinfo=datetime.timezone.utc).replace(tzinfo=None) |
243 | 243 |
|
| 244 | + # Large timestamp precision (GH-532) - timestamps far from epoch must |
| 245 | + # not lose precision due to floating-point conversions. |
| 246 | + # 2300-01-01 00:00:00.001 UTC |
| 247 | + ts_ms = 10413792000001 |
| 248 | + deserialized = DateType.deserialize(int64_pack(ts_ms), 0) |
| 249 | + assert deserialized == datetime.datetime(2300, 1, 1, 0, 0, 0, 1000) |
| 250 | + # Round-trip: serialize the deserialized datetime back to milliseconds |
| 251 | + assert int64_unpack(DateType.serialize(deserialized, 0)) == ts_ms |
| 252 | + |
| 253 | + # Negative large timestamp: 1600-01-01 00:00:00.001 UTC |
| 254 | + ts_ms_neg = -11676096000000 + 1 # -11676095999999 |
| 255 | + deserialized_neg = DateType.deserialize(int64_pack(ts_ms_neg), 0) |
| 256 | + assert deserialized_neg == datetime.datetime(1600, 1, 1, 0, 0, 0, 1000) |
| 257 | + assert int64_unpack(DateType.serialize(deserialized_neg, 0)) == ts_ms_neg |
| 258 | + |
244 | 259 | def test_collection_null_support(self): |
245 | 260 | """ |
246 | 261 | Test that null values in collection are decoded properly. |
|
0 commit comments