Commit a39d8ec
Fix instance() behaviour with pytz offsets (#158)
`pytz` has a class of timezone called a `FixedOffset`. This class only
stores an offset, not a zone name.
When calling `instance()` on a datetime that was using one of these
`FixedOffset` objects as a timezone, Pendulum would totally ignore the
offset and use the local timezone instead. This would happen even if a
`tz` argument was directly supplied to the `instance()` call.
Additionally, the fallback to a fixed offset would always use the
datetime's timezone, even it if was `None` and a `tz` argument was
supplied to the `instance()` call.
This commit makes 2 small changes:
- The `zone` property of the "effective timezone" (the datetime's
`tzinfo` with a fallback to the passed in `tz`) is only used if it is
non-null. This fixes using `FixedOffset` objects as timezones.
- The fallback to a fixed offset now uses the offset of the "effective
timezone" instead of the datetime's offset. This correctly handles
cases where the timezone on the datetime is `None` and a fallback is
provided.1 parent c30ac41 commit a39d8ec
2 files changed
+21
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | | - | |
| 208 | + | |
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
| 214 | + | |
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
138 | 157 | | |
139 | 158 | | |
140 | 159 | | |
| |||
0 commit comments