|
69 | 69 |
|
70 | 70 | def _assert_timestamp(value, nano_value): |
71 | 71 | assert isinstance(value, datetime.datetime) |
72 | | - # Treat naive datetimes as UTC |
73 | | - if value.tzinfo is None: |
74 | | - value_utc = value.replace(tzinfo=UTC) |
| 72 | + assert value.tzinfo is None |
| 73 | + assert nano_value.tzinfo is UTC |
| 74 | + |
| 75 | + assert value.year == nano_value.year |
| 76 | + assert value.month == nano_value.month |
| 77 | + assert value.day == nano_value.day |
| 78 | + assert value.hour == nano_value.hour |
| 79 | + assert value.minute == nano_value.minute |
| 80 | + assert value.second == nano_value.second |
| 81 | + assert value.microsecond == nano_value.microsecond |
| 82 | + |
| 83 | + if isinstance(value, datetime_helpers.DatetimeWithNanoseconds): |
| 84 | + assert value.nanosecond == nano_value.nanosecond |
75 | 85 | else: |
76 | | - value_utc = value.astimezone(UTC) |
77 | | - if nano_value.tzinfo is None: |
78 | | - nano_value_utc = nano_value.replace(tzinfo=UTC) |
79 | | - else: |
80 | | - nano_value_utc = nano_value.astimezone(UTC) |
81 | | - |
82 | | - # Compare timestamps with tolerance for timezone differences |
83 | | - # Allow up to 24 hours difference to handle timezone conversions and date boundaries |
84 | | - time_diff = abs((value_utc - nano_value_utc).total_seconds()) |
85 | | - assert time_diff <= 86400, f"Time difference {time_diff} seconds exceeds 24 hours" |
86 | | - |
87 | | - # Only compare nanoseconds if the timestamps are within 1 second |
88 | | - if time_diff < 1: |
89 | | - if isinstance(value, datetime_helpers.DatetimeWithNanoseconds): |
90 | | - expected_ns = value.nanosecond |
91 | | - found_ns = ( |
92 | | - nano_value.nanosecond |
93 | | - if hasattr(nano_value, "nanosecond") |
94 | | - else nano_value.microsecond * 1000 |
95 | | - ) |
96 | | - # Allow up to 1 second difference for timestamp precision issues |
97 | | - # This accounts for potential precision loss during database round-trip |
98 | | - ns_diff = abs(expected_ns - found_ns) |
99 | | - assert ns_diff <= 1_000_000_000, f"Nanosecond diff {ns_diff} > 1s" |
100 | | - else: |
101 | | - # Allow up to 1 microsecond difference for timestamp precision issues |
102 | | - us_diff = abs(value.microsecond - nano_value.microsecond) |
103 | | - if us_diff > 1: |
104 | | - print(f" Expected: {value} (microsecond: {value.microsecond})") |
105 | | - print(f" Found: {nano_value} (microsecond: {nano_value.microsecond})") |
106 | | - print(f" Difference: {us_diff} microseconds") |
107 | | - assert us_diff <= 1, f"Microsecond diff {us_diff} > 1" |
| 86 | + assert value.microsecond * 1000 == nano_value.nanosecond |
108 | 87 |
|
109 | 88 |
|
110 | 89 | def _check_rows_data(rows_data, expected=ROW_DATA, recurse_into_lists=True): |
|
0 commit comments