Commit 47b0fa8
committed
fix: keep naive datetimes naive when building an Interval
`DateTime.diff()` constructs an `Interval`, whose `__init__` normalised
the start and end values via `pendulum.instance()`. That call used the
default `tz=UTC`, so a naive stdlib `datetime` was turned into a
UTC-aware `DateTime`. When the receiver was itself naive, the subsequent
comparison mixed an offset-naive value with an offset-aware one and
raised:
TypeError: can't compare offset-naive and offset-aware datetimes
`Interval.__new__` already validates that both endpoints share the same
awareness, so forcing a timezone here was both unnecessary and the
source of the bug. Pass each value's own `tzinfo` to `instance()`
instead: naive inputs stay naive and aware inputs keep their timezone
(`DateTime.instance` resolves `tz` as `dt.tzinfo or tz`), so behaviour
for aware datetimes is unchanged.
Fixes #8801 parent b99bd14 commit 47b0fa8
2 files changed
Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
201 | 213 | | |
202 | 214 | | |
203 | 215 | | |
| |||
0 commit comments