Commit 2b9ca0c
Fix incorrect time-zone in results after localization
Consider the following example using the canonical way to add zones to
datetime objects:
>>> import pytz
>>> import datetime
>>> import zoneinfo
>>> datetime.datetime(2023, 1, 1, tzinfo=pytz.timezone("America/Los_Angeles")).isoformat()
'2023-01-01T00:00:00-07:53'
>>> datetime.datetime(2023, 1, 1, tzinfo=zoneinfo.ZoneInfo("America/Los_Angeles")).isoformat()
'2023-01-01T00:00:00-08:00'
pytz does eager timezone evaluation and uses the local-mean-time since
the instant in time is not known. It requires an additional `localize`
call to get the correct zone like so:
>>> pytz.timezone("America/Los_Angeles").localize(datetime.datetime(2023, 1, 1)).isoformat()
'2023-01-01T00:00:00-08:00'
This increases chances of introducing bugs when writing idiomatic
Python.
The only reason to use pytz was because it allowed to control what
happens with ambiguous datetimes but the standard library also allows
provides control over that since 3.9 (and is available as
backports.zoneinfo for older versions).1 parent a031cc2 commit 2b9ca0c
File tree
5 files changed
+43
-40
lines changed- tests/integration
- trino
5 files changed
+43
-40
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | | - | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| |||
234 | 238 | | |
235 | 239 | | |
236 | 240 | | |
237 | | - | |
| 241 | + | |
238 | 242 | | |
239 | 243 | | |
240 | 244 | | |
| |||
338 | 342 | | |
339 | 343 | | |
340 | 344 | | |
341 | | - | |
| 345 | + | |
342 | 346 | | |
343 | 347 | | |
344 | 348 | | |
| |||
364 | 368 | | |
365 | 369 | | |
366 | 370 | | |
367 | | - | |
| 371 | + | |
368 | 372 | | |
369 | 373 | | |
370 | 374 | | |
| |||
407 | 411 | | |
408 | 412 | | |
409 | 413 | | |
410 | | - | |
| 414 | + | |
411 | 415 | | |
412 | 416 | | |
413 | 417 | | |
414 | 418 | | |
415 | 419 | | |
416 | | - | |
417 | | - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
418 | 423 | | |
419 | 424 | | |
420 | 425 | | |
421 | | - | |
| 426 | + | |
422 | 427 | | |
423 | 428 | | |
424 | 429 | | |
425 | 430 | | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
| 431 | + | |
436 | 432 | | |
437 | 433 | | |
438 | 434 | | |
| |||
529 | 525 | | |
530 | 526 | | |
531 | 527 | | |
532 | | - | |
| 528 | + | |
533 | 529 | | |
534 | 530 | | |
535 | 531 | | |
| |||
693 | 689 | | |
694 | 690 | | |
695 | 691 | | |
696 | | - | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
697 | 696 | | |
698 | 697 | | |
699 | 698 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
7 | 12 | | |
8 | | - | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
| |||
729 | 733 | | |
730 | 734 | | |
731 | 735 | | |
732 | | - | |
| 736 | + | |
733 | 737 | | |
734 | 738 | | |
735 | 739 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
55 | 59 | | |
56 | | - | |
| 60 | + | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | 66 | | |
70 | 67 | | |
71 | 68 | | |
| |||
946 | 943 | | |
947 | 944 | | |
948 | 945 | | |
949 | | - | |
| 946 | + | |
950 | 947 | | |
951 | 948 | | |
952 | 949 | | |
| |||
996 | 993 | | |
997 | 994 | | |
998 | 995 | | |
999 | | - | |
1000 | | - | |
| 996 | + | |
1001 | 997 | | |
1002 | 998 | | |
1003 | 999 | | |
| |||
1041 | 1037 | | |
1042 | 1038 | | |
1043 | 1039 | | |
1044 | | - | |
| 1040 | + | |
1045 | 1041 | | |
1046 | 1042 | | |
1047 | 1043 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| |||
425 | 428 | | |
426 | 429 | | |
427 | 430 | | |
428 | | - | |
429 | | - | |
| 431 | + | |
| 432 | + | |
430 | 433 | | |
431 | 434 | | |
432 | 435 | | |
| |||
438 | 441 | | |
439 | 442 | | |
440 | 443 | | |
441 | | - | |
442 | | - | |
| 444 | + | |
| 445 | + | |
443 | 446 | | |
444 | 447 | | |
445 | 448 | | |
| |||
0 commit comments