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101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index eaee837f10e..bf04ac541e6 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -546,6 +546,7 @@ def get_config_vars(*args):
 
         if os.name == 'nt':
             _init_non_posix(_CONFIG_VARS)
+            _CONFIG_VARS['TZPATH'] = ''
         if os.name == 'posix':
             _init_posix(_CONFIG_VARS)
         # For backward compatibility, see issue19555
diff --git a/Lib/zoneinfo/__init__.py b/Lib/zoneinfo/__init__.py
new file mode 100644
index 00000000000..81a2d5ea97b
--- /dev/null
+++ b/Lib/zoneinfo/__init__.py
@@ -0,0 +1,29 @@
+__all__ = [
+    "ZoneInfo",
+    "reset_tzpath",
+    "TZPATH",
+    "ZoneInfoNotFoundError",
+    "InvalidTZPathWarning",
+]
+
+from . import _tzpath
+from ._common import ZoneInfoNotFoundError
+
+try:
+    from _zoneinfo import ZoneInfo
+except ImportError:  # pragma: nocover
+    from ._zoneinfo import ZoneInfo
+
+reset_tzpath = _tzpath.reset_tzpath
+InvalidTZPathWarning = _tzpath.InvalidTZPathWarning
+
+
+def __getattr__(name):
+    if name == "TZPATH":
+        return _tzpath.TZPATH
+    else:
+        raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
+
+
+def __dir__():
+    return sorted(list(globals()) + ["TZPATH"])
diff --git a/Lib/zoneinfo/_common.py b/Lib/zoneinfo/_common.py
new file mode 100644
index 00000000000..3d35d4f4b46
--- /dev/null
+++ b/Lib/zoneinfo/_common.py
@@ -0,0 +1,166 @@
+import struct
+
+
+def load_tzdata(key):
+    import importlib.resources
+
+    components = key.split("/")
+    package_name = ".".join(["tzdata.zoneinfo"] + components[:-1])
+    resource_name = components[-1]
+
+    try:
+        return importlib.resources.open_binary(package_name, resource_name)
+    except (ImportError, FileNotFoundError, UnicodeEncodeError):
+        # There are three types of exception that can be raised that all amount
+        # to "we cannot find this key":
+        #
+        # ImportError: If package_name doesn't exist (e.g. if tzdata is not
+        #   installed, or if there's an error in the folder name like
+        #   Amrica/New_York)
+        # FileNotFoundError: If resource_name doesn't exist in the package
+        #   (e.g. Europe/Krasnoy)
+        # UnicodeEncodeError: If package_name or resource_name are not UTF-8,
+        #   such as keys containing a surrogate character.
+        raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
+
+
+def load_data(fobj):
+    header = _TZifHeader.from_file(fobj)
+
+    if header.version == 1:
+        time_size = 4
+        time_type = "l"
+    else:
+        # Version 2+ has 64-bit integer transition times
+        time_size = 8
+        time_type = "q"
+
+        # Version 2+ also starts with a Version 1 header and data, which
+        # we need to skip now
+        skip_bytes = (
+            header.timecnt * 5  # Transition times and types
+            + header.typecnt * 6  # Local time type records
+            + header.charcnt  # Time zone designations
+            + header.leapcnt * 8  # Leap second records
+            + header.isstdcnt  # Standard/wall indicators
+            + header.isutcnt  # UT/local indicators
+        )
+
+        fobj.seek(skip_bytes, 1)
+
+        # Now we need to read the second header, which is not the same
+        # as the first
+        header = _TZifHeader.from_file(fobj)
+
+    typecnt = header.typecnt
+    timecnt = header.timecnt
+    charcnt = header.charcnt
+
+    # The data portion starts with timecnt transitions and indices
+    if timecnt:
+        trans_list_utc = struct.unpack(
+            f">{timecnt}{time_type}", fobj.read(timecnt * time_size)
+        )
+        trans_idx = struct.unpack(f">{timecnt}B", fobj.read(timecnt))
+    else:
+        trans_list_utc = ()
+        trans_idx = ()
+
+    # Read the ttinfo struct, (utoff, isdst, abbrind)
+    if typecnt:
+        utcoff, isdst, abbrind = zip(
+            *(struct.unpack(">lbb", fobj.read(6)) for i in range(typecnt))
+        )
+    else:
+        utcoff = ()
+        isdst = ()
+        abbrind = ()
+
+    # Now read the abbreviations. They are null-terminated strings, indexed
+    # not by position in the array but by position in the unsplit
+    # abbreviation string. I suppose this makes more sense in C, which uses
+    # null to terminate the strings, but it's inconvenient here...
+    char_total = 0
+    abbr_vals = {}
+    abbr_chars = fobj.read(charcnt)
+
+    def get_abbr(idx):
+        # Gets a string starting at idx and running until the next \x00
+        #
+        # We cannot pre-populate abbr_vals by splitting on \x00 because there
+        # are some zones that use subsets of longer abbreviations, like so:
+        #
+        #  LMT\x00AHST\x00HDT\x00
+        #
+        # Where the idx to abbr mapping should be:
+        #
+        # {0: "LMT", 4: "AHST", 5: "HST", 9: "HDT"}
+        if idx not in abbr_vals:
+            span_end = abbr_chars.find(b"\x00", idx)
+            abbr_vals[idx] = abbr_chars[idx:span_end].decode()
+
+        return abbr_vals[idx]
+
+    abbr = tuple(get_abbr(idx) for idx in abbrind)
+
+    # The remainder of the file consists of leap seconds (currently unused) and
+    # the standard/wall and ut/local indicators, which are metadata we don't need.
+    # In version 2 files, we need to skip the unnecessary data to get at the TZ string:
+    if header.version >= 2:
+        # Each leap second record has size (time_size + 4)
+        skip_bytes = header.isutcnt + header.isstdcnt + header.leapcnt * 12
+        fobj.seek(skip_bytes, 1)
+
+        c = fobj.read(1)  # Should be \n
+        assert c == b"\n", c
+
+        tz_bytes = b""
+        while (c := fobj.read(1)) != b"\n":
+            tz_bytes += c
+
+        tz_str = tz_bytes
+    else:
+        tz_str = None
+
+    return trans_idx, trans_list_utc, utcoff, isdst, abbr, tz_str
+
+
+class _TZifHeader:
+    __slots__ = [
+        "version",
+        "isutcnt",
+        "isstdcnt",
+        "leapcnt",
+        "timecnt",
+        "typecnt",
+        "charcnt",
+    ]
+
+    def __init__(self, *args):
+        assert len(self.__slots__) == len(args)
+        for attr, val in zip(self.__slots__, args):
+            setattr(self, attr, val)
+
+    @classmethod
+    def from_file(cls, stream):
+        # The header starts with a 4-byte "magic" value
+        if stream.read(4) != b"TZif":
+            raise ValueError("Invalid TZif file: magic not found")
+
+        _version = stream.read(1)
+        if _version == b"\x00":
+            version = 1
+        else:
+            version = int(_version)
+        stream.read(15)
+
+        args = (version,)
+
+        # Slots are defined in the order that the bytes are arranged
+        args = args + struct.unpack(">6l", stream.read(24))
+
+        return cls(*args)
+
+
+class ZoneInfoNotFoundError(KeyError):
+    """Exception raised when a ZoneInfo key is not found."""
diff --git a/Lib/zoneinfo/_tzpath.py b/Lib/zoneinfo/_tzpath.py
new file mode 100644
index 00000000000..8cff0b171bf
--- /dev/null
+++ b/Lib/zoneinfo/_tzpath.py
@@ -0,0 +1,110 @@
+import os
+import sys
+import sysconfig
+
+
+def reset_tzpath(to=None):
+    global TZPATH
+
+    tzpaths = to
+    if tzpaths is not None:
+        if isinstance(tzpaths, (str, bytes)):
+            raise TypeError(
+                f"tzpaths must be a list or tuple, "
+                + f"not {type(tzpaths)}: {tzpaths!r}"
+            )
+        elif not all(map(os.path.isabs, tzpaths)):
+            raise ValueError(_get_invalid_paths_message(tzpaths))
+        base_tzpath = tzpaths
+    else:
+        env_var = os.environ.get("PYTHONTZPATH", None)
+        if env_var is not None:
+            base_tzpath = _parse_python_tzpath(env_var)
+        else:
+            base_tzpath = _parse_python_tzpath(
+                sysconfig.get_config_var("TZPATH")
+            )
+
+    TZPATH = tuple(base_tzpath)
+
+
+def _parse_python_tzpath(env_var):
+    if not env_var:
+        return ()
+
+    raw_tzpath = env_var.split(os.pathsep)
+    new_tzpath = tuple(filter(os.path.isabs, raw_tzpath))
+
+    # If anything has been filtered out, we will warn about it
+    if len(new_tzpath) != len(raw_tzpath):
+        import warnings
+
+        msg = _get_invalid_paths_message(raw_tzpath)
+
+        warnings.warn(
+            "Invalid paths specified in PYTHONTZPATH environment variable."
+            + msg,
+            InvalidTZPathWarning,
+        )
+
+    return new_tzpath
+
+
+def _get_invalid_paths_message(tzpaths):
+    invalid_paths = (path for path in tzpaths if not os.path.isabs(path))
+
+    prefix = "\n    "
+    indented_str = prefix + prefix.join(invalid_paths)
+
+    return (
+        "Paths should be absolute but found the following relative paths:"
+        + indented_str
+    )
+
+
+def find_tzfile(key):
+    """Retrieve the path to a TZif file from a key."""
+    _validate_tzfile_path(key)
+    for search_path in TZPATH:
+        filepath = os.path.join(search_path, key)
+        if os.path.isfile(filepath):
+            return filepath
+
+    return None
+
+
+_TEST_PATH = os.path.normpath(os.path.join("_", "_"))[:-1]
+
+
+def _validate_tzfile_path(path, _base=_TEST_PATH):
+    if os.path.isabs(path):
+        raise ValueError(
+            f"ZoneInfo keys may not be absolute paths, got: {path}"
+        )
+
+    # We only care about the kinds of path normalizations that would change the
+    # length of the key - e.g. a/../b -> a/b, or a/b/ -> a/b. On Windows,
+    # normpath will also change from a/b to a\b, but that would still preserve
+    # the length.
+    new_path = os.path.normpath(path)
+    if len(new_path) != len(path):
+        raise ValueError(
+            f"ZoneInfo keys must be normalized relative paths, got: {path}"
+        )
+
+    resolved = os.path.normpath(os.path.join(_base, new_path))
+    if not resolved.startswith(_base):
+        raise ValueError(
+            f"ZoneInfo keys must refer to subdirectories of TZPATH, got: {path}"
+        )
+
+
+del _TEST_PATH
+
+
+class InvalidTZPathWarning(RuntimeWarning):
+    """Warning raised if an invalid path is specified in PYTHONTZPATH."""
+
+
+TZPATH = ()
+reset_tzpath()
diff --git a/Lib/zoneinfo/_zoneinfo.py b/Lib/zoneinfo/_zoneinfo.py
new file mode 100644
index 00000000000..69133ae80a4
--- /dev/null
+++ b/Lib/zoneinfo/_zoneinfo.py
@@ -0,0 +1,755 @@
+import bisect
+import calendar
+import collections
+import functools
+import os
+import re
+import struct
+import sys
+import weakref
+from datetime import datetime, timedelta, timezone, tzinfo
+
+from . import _common, _tzpath
+
+EPOCH = datetime(1970, 1, 1)
+EPOCHORDINAL = datetime(1970, 1, 1).toordinal()
+
+# It is relatively expensive to construct new timedelta objects, and in most
+# cases we're looking at the same deltas, like integer numbers of hours, etc.
+# To improve speed and memory use, we'll keep a dictionary with references
+# to the ones we've already used so far.
+#
+# Loading every time zone in the 2020a version of the time zone database
+# requires 447 timedeltas, which requires approximately the amount of space
+# that ZoneInfo("America/New_York") with 236 transitions takes up, so we will
+# set the cache size to 512 so that in the common case we always get cache
+# hits, but specifically crafted ZoneInfo objects don't leak arbitrary amounts
+# of memory.
+@functools.lru_cache(maxsize=512)
+def _load_timedelta(seconds):
+    return timedelta(seconds=seconds)
+
+
+class ZoneInfo(tzinfo):
+    _strong_cache_size = 8
+    _strong_cache = collections.OrderedDict()
+    _weak_cache = weakref.WeakValueDictionary()
+    __module__ = "zoneinfo"
+
+    def __init_subclass__(cls):
+        cls._strong_cache = collections.OrderedDict()
+        cls._weak_cache = weakref.WeakValueDictionary()
+
+    def __new__(cls, key):
+        instance = cls._weak_cache.get(key, None)
+        if instance is None:
+            instance = cls._weak_cache.setdefault(key, cls._new_instance(key))
+            instance._from_cache = True
+
+        # Update the "strong" cache
+        cls._strong_cache[key] = cls._strong_cache.pop(key, instance)
+
+        if len(cls._strong_cache) > cls._strong_cache_size:
+            cls._strong_cache.popitem(last=False)
+
+        return instance
+
+    @classmethod
+    def no_cache(cls, key):
+        obj = cls._new_instance(key)
+        obj._from_cache = False
+
+        return obj
+
+    @classmethod
+    def _new_instance(cls, key):
+        obj = super().__new__(cls)
+        obj._key = key
+        obj._file_path = obj._find_tzfile(key)
+
+        if obj._file_path is not None:
+            file_obj = open(obj._file_path, "rb")
+        else:
+            file_obj = _common.load_tzdata(key)
+
+        with file_obj as f:
+            obj._load_file(f)
+
+        return obj
+
+    @classmethod
+    def from_file(cls, fobj, /, key=None):
+        obj = super().__new__(cls)
+        obj._key = key
+        obj._file_path = None
+        obj._load_file(fobj)
+        obj._file_repr = repr(fobj)
+
+        # Disable pickling for objects created from files
+        obj.__reduce__ = obj._file_reduce
+
+        return obj
+
+    @classmethod
+    def clear_cache(cls, *, only_keys=None):
+        if only_keys is not None:
+            for key in only_keys:
+                cls._weak_cache.pop(key, None)
+                cls._strong_cache.pop(key, None)
+
+        else:
+            cls._weak_cache.clear()
+            cls._strong_cache.clear()
+
+    @property
+    def key(self):
+        return self._key
+
+    def utcoffset(self, dt):
+        return self._find_trans(dt).utcoff
+
+    def dst(self, dt):
+        return self._find_trans(dt).dstoff
+
+    def tzname(self, dt):
+        return self._find_trans(dt).tzname
+
+    def fromutc(self, dt):
+        """Convert from datetime in UTC to datetime in local time"""
+
+        if not isinstance(dt, datetime):
+            raise TypeError("fromutc() requires a datetime argument")
+        if dt.tzinfo is not self:
+            raise ValueError("dt.tzinfo is not self")
+
+        timestamp = self._get_local_timestamp(dt)
+        num_trans = len(self._trans_utc)
+
+        if num_trans >= 1 and timestamp < self._trans_utc[0]:
+            tti = self._tti_before
+            fold = 0
+        elif (
+            num_trans == 0 or timestamp > self._trans_utc[-1]
+        ) and not isinstance(self._tz_after, _ttinfo):
+            tti, fold = self._tz_after.get_trans_info_fromutc(
+                timestamp, dt.year
+            )
+        elif num_trans == 0:
+            tti = self._tz_after
+            fold = 0
+        else:
+            idx = bisect.bisect_right(self._trans_utc, timestamp)
+
+            if num_trans > 1 and timestamp >= self._trans_utc[1]:
+                tti_prev, tti = self._ttinfos[idx - 2 : idx]
+            elif timestamp > self._trans_utc[-1]:
+                tti_prev = self._ttinfos[-1]
+                tti = self._tz_after
+            else:
+                tti_prev = self._tti_before
+                tti = self._ttinfos[0]
+
+            # Detect fold
+            shift = tti_prev.utcoff - tti.utcoff
+            fold = shift.total_seconds() > timestamp - self._trans_utc[idx - 1]
+        dt += tti.utcoff
+        if fold:
+            return dt.replace(fold=1)
+        else:
+            return dt
+
+    def _find_trans(self, dt):
+        if dt is None:
+            if self._fixed_offset:
+                return self._tz_after
+            else:
+                return _NO_TTINFO
+
+        ts = self._get_local_timestamp(dt)
+
+        lt = self._trans_local[dt.fold]
+
+        num_trans = len(lt)
+
+        if num_trans and ts < lt[0]:
+            return self._tti_before
+        elif not num_trans or ts > lt[-1]:
+            if isinstance(self._tz_after, _TZStr):
+                return self._tz_after.get_trans_info(ts, dt.year, dt.fold)
+            else:
+                return self._tz_after
+        else:
+            # idx is the transition that occurs after this timestamp, so we
+            # subtract off 1 to get the current ttinfo
+            idx = bisect.bisect_right(lt, ts) - 1
+            assert idx >= 0
+            return self._ttinfos[idx]
+
+    def _get_local_timestamp(self, dt):
+        return (
+            (dt.toordinal() - EPOCHORDINAL) * 86400
+            + dt.hour * 3600
+            + dt.minute * 60
+            + dt.second
+        )
+
+    def __str__(self):
+        if self._key is not None:
+            return f"{self._key}"
+        else:
+            return repr(self)
+
+    def __repr__(self):
+        if self._key is not None:
+            return f"{self.__class__.__name__}(key={self._key!r})"
+        else:
+            return f"{self.__class__.__name__}.from_file({self._file_repr})"
+
+    def __reduce__(self):
+        return (self.__class__._unpickle, (self._key, self._from_cache))
+
+    def _file_reduce(self):
+        import pickle
+
+        raise pickle.PicklingError(
+            "Cannot pickle a ZoneInfo file created from a file stream."
+        )
+
+    @classmethod
+    def _unpickle(cls, key, from_cache, /):
+        if from_cache:
+            return cls(key)
+        else:
+            return cls.no_cache(key)
+
+    def _find_tzfile(self, key):
+        return _tzpath.find_tzfile(key)
+
+    def _load_file(self, fobj):
+        # Retrieve all the data as it exists in the zoneinfo file
+        trans_idx, trans_utc, utcoff, isdst, abbr, tz_str = _common.load_data(
+            fobj
+        )
+
+        # Infer the DST offsets (needed for .dst()) from the data
+        dstoff = self._utcoff_to_dstoff(trans_idx, utcoff, isdst)
+
+        # Convert all the transition times (UTC) into "seconds since 1970-01-01 local time"
+        trans_local = self._ts_to_local(trans_idx, trans_utc, utcoff)
+
+        # Construct `_ttinfo` objects for each transition in the file
+        _ttinfo_list = [
+            _ttinfo(
+                _load_timedelta(utcoffset), _load_timedelta(dstoffset), tzname
+            )
+            for utcoffset, dstoffset, tzname in zip(utcoff, dstoff, abbr)
+        ]
+
+        self._trans_utc = trans_utc
+        self._trans_local = trans_local
+        self._ttinfos = [_ttinfo_list[idx] for idx in trans_idx]
+
+        # Find the first non-DST transition
+        for i in range(len(isdst)):
+            if not isdst[i]:
+                self._tti_before = _ttinfo_list[i]
+                break
+        else:
+            if self._ttinfos:
+                self._tti_before = self._ttinfos[0]
+            else:
+                self._tti_before = None
+
+        # Set the "fallback" time zone
+        if tz_str is not None and tz_str != b"":
+            self._tz_after = _parse_tz_str(tz_str.decode())
+        else:
+            if not self._ttinfos and not _ttinfo_list:
+                raise ValueError("No time zone information found.")
+
+            if self._ttinfos:
+                self._tz_after = self._ttinfos[-1]
+            else:
+                self._tz_after = _ttinfo_list[-1]
+
+        # Determine if this is a "fixed offset" zone, meaning that the output
+        # of the utcoffset, dst and tzname functions does not depend on the
+        # specific datetime passed.
+        #
+        # We make three simplifying assumptions here:
+        #
+        # 1. If _tz_after is not a _ttinfo, it has transitions that might
+        #    actually occur (it is possible to construct TZ strings that
+        #    specify STD and DST but no transitions ever occur, such as
+        #    AAA0BBB,0/0,J365/25).
+        # 2. If _ttinfo_list contains more than one _ttinfo object, the objects
+        #    represent different offsets.
+        # 3. _ttinfo_list contains no unused _ttinfos (in which case an
+        #    otherwise fixed-offset zone with extra _ttinfos defined may
+        #    appear to *not* be a fixed offset zone).
+        #
+        # Violations to these assumptions would be fairly exotic, and exotic
+        # zones should almost certainly not be used with datetime.time (the
+        # only thing that would be affected by this).
+        if len(_ttinfo_list) > 1 or not isinstance(self._tz_after, _ttinfo):
+            self._fixed_offset = False
+        elif not _ttinfo_list:
+            self._fixed_offset = True
+        else:
+            self._fixed_offset = _ttinfo_list[0] == self._tz_after
+
+    @staticmethod
+    def _utcoff_to_dstoff(trans_idx, utcoffsets, isdsts):
+        # Now we must transform our ttis and abbrs into `_ttinfo` objects,
+        # but there is an issue: .dst() must return a timedelta with the
+        # difference between utcoffset() and the "standard" offset, but
+        # the "base offset" and "DST offset" are not encoded in the file;
+        # we can infer what they are from the isdst flag, but it is not
+        # sufficient to to just look at the last standard offset, because
+        # occasionally countries will shift both DST offset and base offset.
+
+        typecnt = len(isdsts)
+        dstoffs = [0] * typecnt  # Provisionally assign all to 0.
+        dst_cnt = sum(isdsts)
+        dst_found = 0
+
+        for i in range(1, len(trans_idx)):
+            if dst_cnt == dst_found:
+                break
+
+            idx = trans_idx[i]
+
+            dst = isdsts[idx]
+
+            # We're only going to look at daylight saving time
+            if not dst:
+                continue
+
+            # Skip any offsets that have already been assigned
+            if dstoffs[idx] != 0:
+                continue
+
+            dstoff = 0
+            utcoff = utcoffsets[idx]
+
+            comp_idx = trans_idx[i - 1]
+
+            if not isdsts[comp_idx]:
+                dstoff = utcoff - utcoffsets[comp_idx]
+
+            if not dstoff and idx < (typecnt - 1):
+                comp_idx = trans_idx[i + 1]
+
+                # If the following transition is also DST and we couldn't
+                # find the DST offset by this point, we're going ot have to
+                # skip it and hope this transition gets assigned later
+                if isdsts[comp_idx]:
+                    continue
+
+                dstoff = utcoff - utcoffsets[comp_idx]
+
+            if dstoff:
+                dst_found += 1
+                dstoffs[idx] = dstoff
+        else:
+            # If we didn't find a valid value for a given index, we'll end up
+            # with dstoff = 0 for something where `isdst=1`. This is obviously
+            # wrong - one hour will be a much better guess than 0
+            for idx in range(typecnt):
+                if not dstoffs[idx] and isdsts[idx]:
+                    dstoffs[idx] = 3600
+
+        return dstoffs
+
+    @staticmethod
+    def _ts_to_local(trans_idx, trans_list_utc, utcoffsets):
+        """Generate number of seconds since 1970 *in the local time*.
+
+        This is necessary to easily find the transition times in local time"""
+        if not trans_list_utc:
+            return [[], []]
+
+        # Start with the timestamps and modify in-place
+        trans_list_wall = [list(trans_list_utc), list(trans_list_utc)]
+
+        if len(utcoffsets) > 1:
+            offset_0 = utcoffsets[0]
+            offset_1 = utcoffsets[trans_idx[0]]
+            if offset_1 > offset_0:
+                offset_1, offset_0 = offset_0, offset_1
+        else:
+            offset_0 = offset_1 = utcoffsets[0]
+
+        trans_list_wall[0][0] += offset_0
+        trans_list_wall[1][0] += offset_1
+
+        for i in range(1, len(trans_idx)):
+            offset_0 = utcoffsets[trans_idx[i - 1]]
+            offset_1 = utcoffsets[trans_idx[i]]
+
+            if offset_1 > offset_0:
+                offset_1, offset_0 = offset_0, offset_1
+
+            trans_list_wall[0][i] += offset_0
+            trans_list_wall[1][i] += offset_1
+
+        return trans_list_wall
+
+
+class _ttinfo:
+    __slots__ = ["utcoff", "dstoff", "tzname"]
+
+    def __init__(self, utcoff, dstoff, tzname):
+        self.utcoff = utcoff
+        self.dstoff = dstoff
+        self.tzname = tzname
+
+    def __eq__(self, other):
+        return (
+            self.utcoff == other.utcoff
+            and self.dstoff == other.dstoff
+            and self.tzname == other.tzname
+        )
+
+    def __repr__(self):  # pragma: nocover
+        return (
+            f"{self.__class__.__name__}"
+            + f"({self.utcoff}, {self.dstoff}, {self.tzname})"
+        )
+
+
+_NO_TTINFO = _ttinfo(None, None, None)
+
+
+class _TZStr:
+    __slots__ = (
+        "std",
+        "dst",
+        "start",
+        "end",
+        "get_trans_info",
+        "get_trans_info_fromutc",
+        "dst_diff",
+    )
+
+    def __init__(
+        self, std_abbr, std_offset, dst_abbr, dst_offset, start=None, end=None
+    ):
+        self.dst_diff = dst_offset - std_offset
+        std_offset = _load_timedelta(std_offset)
+        self.std = _ttinfo(
+            utcoff=std_offset, dstoff=_load_timedelta(0), tzname=std_abbr
+        )
+
+        self.start = start
+        self.end = end
+
+        dst_offset = _load_timedelta(dst_offset)
+        delta = _load_timedelta(self.dst_diff)
+        self.dst = _ttinfo(utcoff=dst_offset, dstoff=delta, tzname=dst_abbr)
+
+        # These are assertions because the constructor should only be called
+        # by functions that would fail before passing start or end
+        assert start is not None, "No transition start specified"
+        assert end is not None, "No transition end specified"
+
+        self.get_trans_info = self._get_trans_info
+        self.get_trans_info_fromutc = self._get_trans_info_fromutc
+
+    def transitions(self, year):
+        start = self.start.year_to_epoch(year)
+        end = self.end.year_to_epoch(year)
+        return start, end
+
+    def _get_trans_info(self, ts, year, fold):
+        """Get the information about the current transition - tti"""
+        start, end = self.transitions(year)
+
+        # With fold = 0, the period (denominated in local time) with the
+        # smaller offset starts at the end of the gap and ends at the end of
+        # the fold; with fold = 1, it runs from the start of the gap to the
+        # beginning of the fold.
+        #
+        # So in order to determine the DST boundaries we need to know both
+        # the fold and whether DST is positive or negative (rare), and it
+        # turns out that this boils down to fold XOR is_positive.
+        if fold == (self.dst_diff >= 0):
+            end -= self.dst_diff
+        else:
+            start += self.dst_diff
+
+        if start < end:
+            isdst = start <= ts < end
+        else:
+            isdst = not (end <= ts < start)
+
+        return self.dst if isdst else self.std
+
+    def _get_trans_info_fromutc(self, ts, year):
+        start, end = self.transitions(year)
+        start -= self.std.utcoff.total_seconds()
+        end -= self.dst.utcoff.total_seconds()
+
+        if start < end:
+            isdst = start <= ts < end
+        else:
+            isdst = not (end <= ts < start)
+
+        # For positive DST, the ambiguous period is one dst_diff after the end
+        # of DST; for negative DST, the ambiguous period is one dst_diff before
+        # the start of DST.
+        if self.dst_diff > 0:
+            ambig_start = end
+            ambig_end = end + self.dst_diff
+        else:
+            ambig_start = start
+            ambig_end = start - self.dst_diff
+
+        fold = ambig_start <= ts < ambig_end
+
+        return (self.dst if isdst else self.std, fold)
+
+
+def _post_epoch_days_before_year(year):
+    """Get the number of days between 1970-01-01 and YEAR-01-01"""
+    y = year - 1
+    return y * 365 + y // 4 - y // 100 + y // 400 - EPOCHORDINAL
+
+
+class _DayOffset:
+    __slots__ = ["d", "julian", "hour", "minute", "second"]
+
+    def __init__(self, d, julian, hour=2, minute=0, second=0):
+        if not (0 + julian) <= d <= 365:
+            min_day = 0 + julian
+            raise ValueError(f"d must be in [{min_day}, 365], not: {d}")
+
+        self.d = d
+        self.julian = julian
+        self.hour = hour
+        self.minute = minute
+        self.second = second
+
+    def year_to_epoch(self, year):
+        days_before_year = _post_epoch_days_before_year(year)
+
+        d = self.d
+        if self.julian and d >= 59 and calendar.isleap(year):
+            d += 1
+
+        epoch = (days_before_year + d) * 86400
+        epoch += self.hour * 3600 + self.minute * 60 + self.second
+
+        return epoch
+
+
+class _CalendarOffset:
+    __slots__ = ["m", "w", "d", "hour", "minute", "second"]
+
+    _DAYS_BEFORE_MONTH = (
+        -1,
+        0,
+        31,
+        59,
+        90,
+        120,
+        151,
+        181,
+        212,
+        243,
+        273,
+        304,
+        334,
+    )
+
+    def __init__(self, m, w, d, hour=2, minute=0, second=0):
+        if not 0 < m <= 12:
+            raise ValueError("m must be in (0, 12]")
+
+        if not 0 < w <= 5:
+            raise ValueError("w must be in (0, 5]")
+
+        if not 0 <= d <= 6:
+            raise ValueError("d must be in [0, 6]")
+
+        self.m = m
+        self.w = w
+        self.d = d
+        self.hour = hour
+        self.minute = minute
+        self.second = second
+
+    @classmethod
+    def _ymd2ord(cls, year, month, day):
+        return (
+            _post_epoch_days_before_year(year)
+            + cls._DAYS_BEFORE_MONTH[month]
+            + (month > 2 and calendar.isleap(year))
+            + day
+        )
+
+    # TODO: These are not actually epoch dates as they are expressed in local time
+    def year_to_epoch(self, year):
+        """Calculates the datetime of the occurrence from the year"""
+        # We know year and month, we need to convert w, d into day of month
+        #
+        # Week 1 is the first week in which day `d` (where 0 = Sunday) appears.
+        # Week 5 represents the last occurrence of day `d`, so we need to know
+        # the range of the month.
+        first_day, days_in_month = calendar.monthrange(year, self.m)
+
+        # This equation seems magical, so I'll break it down:
+        # 1. calendar says 0 = Monday, POSIX says 0 = Sunday
+        #    so we need first_day + 1 to get 1 = Monday -> 7 = Sunday,
+        #    which is still equivalent because this math is mod 7
+        # 2. Get first day - desired day mod 7: -1 % 7 = 6, so we don't need
+        #    to do anything to adjust negative numbers.
+        # 3. Add 1 because month days are a 1-based index.
+        month_day = (self.d - (first_day + 1)) % 7 + 1
+
+        # Now use a 0-based index version of `w` to calculate the w-th
+        # occurrence of `d`
+        month_day += (self.w - 1) * 7
+
+        # month_day will only be > days_in_month if w was 5, and `w` means
+        # "last occurrence of `d`", so now we just check if we over-shot the
+        # end of the month and if so knock off 1 week.
+        if month_day > days_in_month:
+            month_day -= 7
+
+        ordinal = self._ymd2ord(year, self.m, month_day)
+        epoch = ordinal * 86400
+        epoch += self.hour * 3600 + self.minute * 60 + self.second
+        return epoch
+
+
+def _parse_tz_str(tz_str):
+    # The tz string has the format:
+    #
+    # std[offset[dst[offset],start[/time],end[/time]]]
+    #
+    # std and dst must be 3 or more characters long and must not contain
+    # a leading colon, embedded digits, commas, nor a plus or minus signs;
+    # The spaces between "std" and "offset" are only for display and are
+    # not actually present in the string.
+    #
+    # The format of the offset is ``[+|-]hh[:mm[:ss]]``
+
+    offset_str, *start_end_str = tz_str.split(",", 1)
+
+    # fmt: off
+    parser_re = re.compile(
+        r"(?P<std>[^<0-9:.+-]+|<[a-zA-Z0-9+\-]+>)" +
+        r"((?P<stdoff>[+-]?\d{1,2}(:\d{2}(:\d{2})?)?)" +
+            r"((?P<dst>[^0-9:.+-]+|<[a-zA-Z0-9+\-]+>)" +
+                r"((?P<dstoff>[+-]?\d{1,2}(:\d{2}(:\d{2})?)?))?" +
+            r")?" + # dst
+        r")?$" # stdoff
+    )
+    # fmt: on
+
+    m = parser_re.match(offset_str)
+
+    if m is None:
+        raise ValueError(f"{tz_str} is not a valid TZ string")
+
+    std_abbr = m.group("std")
+    dst_abbr = m.group("dst")
+    dst_offset = None
+
+    std_abbr = std_abbr.strip("<>")
+
+    if dst_abbr:
+        dst_abbr = dst_abbr.strip("<>")
+
+    if std_offset := m.group("stdoff"):
+        try:
+            std_offset = _parse_tz_delta(std_offset)
+        except ValueError as e:
+            raise ValueError(f"Invalid STD offset in {tz_str}") from e
+    else:
+        std_offset = 0
+
+    if dst_abbr is not None:
+        if dst_offset := m.group("dstoff"):
+            try:
+                dst_offset = _parse_tz_delta(dst_offset)
+            except ValueError as e:
+                raise ValueError(f"Invalid DST offset in {tz_str}") from e
+        else:
+            dst_offset = std_offset + 3600
+
+        if not start_end_str:
+            raise ValueError(f"Missing transition rules: {tz_str}")
+
+        start_end_strs = start_end_str[0].split(",", 1)
+        try:
+            start, end = (_parse_dst_start_end(x) for x in start_end_strs)
+        except ValueError as e:
+            raise ValueError(f"Invalid TZ string: {tz_str}") from e
+
+        return _TZStr(std_abbr, std_offset, dst_abbr, dst_offset, start, end)
+    elif start_end_str:
+        raise ValueError(f"Transition rule present without DST: {tz_str}")
+    else:
+        # This is a static ttinfo, don't return _TZStr
+        return _ttinfo(
+            _load_timedelta(std_offset), _load_timedelta(0), std_abbr
+        )
+
+
+def _parse_dst_start_end(dststr):
+    date, *time = dststr.split("/")
+    if date[0] == "M":
+        n_is_julian = False
+        m = re.match(r"M(\d{1,2})\.(\d).(\d)$", date)
+        if m is None:
+            raise ValueError(f"Invalid dst start/end date: {dststr}")
+        date_offset = tuple(map(int, m.groups()))
+        offset = _CalendarOffset(*date_offset)
+    else:
+        if date[0] == "J":
+            n_is_julian = True
+            date = date[1:]
+        else:
+            n_is_julian = False
+
+        doy = int(date)
+        offset = _DayOffset(doy, n_is_julian)
+
+    if time:
+        time_components = list(map(int, time[0].split(":")))
+        n_components = len(time_components)
+        if n_components < 3:
+            time_components.extend([0] * (3 - n_components))
+        offset.hour, offset.minute, offset.second = time_components
+
+    return offset
+
+
+def _parse_tz_delta(tz_delta):
+    match = re.match(
+        r"(?P<sign>[+-])?(?P<h>\d{1,2})(:(?P<m>\d{2})(:(?P<s>\d{2}))?)?",
+        tz_delta,
+    )
+    # Anything passed to this function should already have hit an equivalent
+    # regular expression to find the section to parse.
+    assert match is not None, tz_delta
+
+    h, m, s = (
+        int(v) if v is not None else 0
+        for v in map(match.group, ("h", "m", "s"))
+    )
+
+    total = h * 3600 + m * 60 + s
+
+    if not -86400 < total < 86400:
+        raise ValueError(
+            "Offset must be strictly between -24h and +24h:" + tz_delta
+        )
+
+    # Yes, +5 maps to an offset of -5h
+    if match.group("sign") != "-":
+        total *= -1
+
+    return total
diff --git a/Makefile.pre.in b/Makefile.pre.in
index d545a9efb3c..dbfd805f1a0 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -197,6 +197,9 @@ OPENSSL_INCLUDES=@OPENSSL_INCLUDES@
 OPENSSL_LIBS=@OPENSSL_LIBS@
 OPENSSL_LDFLAGS=@OPENSSL_LDFLAGS@
 
+# Default zoneinfo.TZPATH. Added here to expose it in sysconfig.get_config_var
+TZPATH=@TZPATH@
+
 # Modes for directories, executables and data files created by the
 # install process.  Default to user-only-writable for all file types.
 DIRMODE=	755
diff --git a/Modules/Setup b/Modules/Setup
index 87e73bac78f..02cfb67518d 100644
--- a/Modules/Setup
+++ b/Modules/Setup
@@ -181,6 +181,7 @@ _symtable symtablemodule.c
 #_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c	# elementtree accelerator
 #_pickle _pickle.c	# pickle accelerator
 #_datetime _datetimemodule.c	# datetime accelerator
+#_zoneinfo _zoneinfo.c	# zoneinfo accelerator
 #_bisect _bisectmodule.c	# Bisection algorithms
 #_heapq _heapqmodule.c	# Heap queue algorithm
 #_asyncio _asynciomodule.c  # Fast asyncio Future
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
new file mode 100644
index 00000000000..9f5e64d8486
--- /dev/null
+++ b/Modules/_zoneinfo.c
@@ -0,0 +1,2695 @@
+#include "Python.h"
+#include "structmember.h"
+
+#include <ctype.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include "datetime.h"
+
+// Imports
+static PyObject *io_open = NULL;
+static PyObject *_tzpath_find_tzfile = NULL;
+static PyObject *_common_mod = NULL;
+
+typedef struct TransitionRuleType TransitionRuleType;
+typedef struct StrongCacheNode StrongCacheNode;
+
+typedef struct {
+    PyObject *utcoff;
+    PyObject *dstoff;
+    PyObject *tzname;
+    long utcoff_seconds;
+} _ttinfo;
+
+typedef struct {
+    _ttinfo std;
+    _ttinfo dst;
+    int dst_diff;
+    TransitionRuleType *start;
+    TransitionRuleType *end;
+    unsigned char std_only;
+} _tzrule;
+
+typedef struct {
+    PyDateTime_TZInfo base;
+    PyObject *key;
+    PyObject *file_repr;
+    PyObject *weakreflist;
+    unsigned int num_transitions;
+    unsigned int num_ttinfos;
+    int64_t *trans_list_utc;
+    int64_t *trans_list_wall[2];
+    _ttinfo **trans_ttinfos;  // References to the ttinfo for each transition
+    _ttinfo *ttinfo_before;
+    _tzrule tzrule_after;
+    _ttinfo *_ttinfos;  // Unique array of ttinfos for ease of deallocation
+    unsigned char fixed_offset;
+    unsigned char source;
+} PyZoneInfo_ZoneInfo;
+
+struct TransitionRuleType {
+    int64_t (*year_to_timestamp)(TransitionRuleType *, int);
+};
+
+typedef struct {
+    TransitionRuleType base;
+    uint8_t month;
+    uint8_t week;
+    uint8_t day;
+    int8_t hour;
+    int8_t minute;
+    int8_t second;
+} CalendarRule;
+
+typedef struct {
+    TransitionRuleType base;
+    uint8_t julian;
+    unsigned int day;
+    int8_t hour;
+    int8_t minute;
+    int8_t second;
+} DayRule;
+
+struct StrongCacheNode {
+    StrongCacheNode *next;
+    StrongCacheNode *prev;
+    PyObject *key;
+    PyObject *zone;
+};
+
+static PyTypeObject PyZoneInfo_ZoneInfoType;
+
+// Globals
+static PyObject *TIMEDELTA_CACHE = NULL;
+static PyObject *ZONEINFO_WEAK_CACHE = NULL;
+static StrongCacheNode *ZONEINFO_STRONG_CACHE = NULL;
+static size_t ZONEINFO_STRONG_CACHE_MAX_SIZE = 8;
+
+static _ttinfo NO_TTINFO = {NULL, NULL, NULL, 0};
+
+// Constants
+static const int EPOCHORDINAL = 719163;
+static int DAYS_IN_MONTH[] = {
+    -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
+};
+
+static int DAYS_BEFORE_MONTH[] = {
+    -1, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
+};
+
+static const int SOURCE_NOCACHE = 0;
+static const int SOURCE_CACHE = 1;
+static const int SOURCE_FILE = 2;
+
+// Forward declarations
+static int
+load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj);
+static void
+utcoff_to_dstoff(size_t *trans_idx, long *utcoffs, long *dstoffs,
+                 unsigned char *isdsts, size_t num_transitions,
+                 size_t num_ttinfos);
+static int
+ts_to_local(size_t *trans_idx, int64_t *trans_utc, long *utcoff,
+            int64_t *trans_local[2], size_t num_ttinfos,
+            size_t num_transitions);
+
+static int
+parse_tz_str(PyObject *tz_str_obj, _tzrule *out);
+
+static ssize_t
+parse_abbr(const char *const p, PyObject **abbr);
+static ssize_t
+parse_tz_delta(const char *const p, long *total_seconds);
+static ssize_t
+parse_transition_time(const char *const p, int8_t *hour, int8_t *minute,
+                      int8_t *second);
+static ssize_t
+parse_transition_rule(const char *const p, TransitionRuleType **out);
+
+static _ttinfo *
+find_tzrule_ttinfo(_tzrule *rule, int64_t ts, unsigned char fold, int year);
+static _ttinfo *
+find_tzrule_ttinfo_fromutc(_tzrule *rule, int64_t ts, int year,
+                           unsigned char *fold);
+
+static int
+build_ttinfo(long utcoffset, long dstoffset, PyObject *tzname, _ttinfo *out);
+static void
+xdecref_ttinfo(_ttinfo *ttinfo);
+static int
+ttinfo_eq(const _ttinfo *const tti0, const _ttinfo *const tti1);
+
+static int
+build_tzrule(PyObject *std_abbr, PyObject *dst_abbr, long std_offset,
+             long dst_offset, TransitionRuleType *start,
+             TransitionRuleType *end, _tzrule *out);
+static void
+free_tzrule(_tzrule *tzrule);
+
+static PyObject *
+load_timedelta(long seconds);
+
+static int
+get_local_timestamp(PyObject *dt, int64_t *local_ts);
+static _ttinfo *
+find_ttinfo(PyZoneInfo_ZoneInfo *self, PyObject *dt);
+
+static int
+ymd_to_ord(int y, int m, int d);
+static int
+is_leap_year(int year);
+
+static size_t
+_bisect(const int64_t value, const int64_t *arr, size_t size);
+
+static void
+eject_from_strong_cache(const PyTypeObject *const type, PyObject *key);
+static void
+clear_strong_cache(const PyTypeObject *const type);
+static void
+update_strong_cache(const PyTypeObject *const type, PyObject *key,
+                    PyObject *zone);
+static PyObject *
+zone_from_strong_cache(const PyTypeObject *const type, PyObject *key);
+
+static PyObject *
+zoneinfo_new_instance(PyTypeObject *type, PyObject *key)
+{
+    PyObject *file_obj = NULL;
+    PyObject *file_path = NULL;
+
+    file_path = PyObject_CallFunctionObjArgs(_tzpath_find_tzfile, key, NULL);
+    if (file_path == NULL) {
+        return NULL;
+    }
+    else if (file_path == Py_None) {
+        file_obj = PyObject_CallMethod(_common_mod, "load_tzdata", "O", key);
+        if (file_obj == NULL) {
+            Py_DECREF(file_path);
+            return NULL;
+        }
+    }
+
+    PyObject *self = (PyObject *)(type->tp_alloc(type, 0));
+    if (self == NULL) {
+        goto error;
+    }
+
+    if (file_obj == NULL) {
+        file_obj = PyObject_CallFunction(io_open, "Os", file_path, "rb");
+        if (file_obj == NULL) {
+            goto error;
+        }
+    }
+
+    if (load_data((PyZoneInfo_ZoneInfo *)self, file_obj)) {
+        goto error;
+    }
+
+    PyObject *rv = PyObject_CallMethod(file_obj, "close", NULL);
+    Py_DECREF(file_obj);
+    file_obj = NULL;
+    if (rv == NULL) {
+        goto error;
+    }
+    Py_DECREF(rv);
+
+    ((PyZoneInfo_ZoneInfo *)self)->key = key;
+    Py_INCREF(key);
+
+    goto cleanup;
+error:
+    Py_XDECREF(self);
+    self = NULL;
+cleanup:
+    if (file_obj != NULL) {
+        PyObject *tmp = PyObject_CallMethod(file_obj, "close", NULL);
+        Py_DECREF(tmp);
+        Py_DECREF(file_obj);
+    }
+    Py_DECREF(file_path);
+    return self;
+}
+
+static PyObject *
+get_weak_cache(PyTypeObject *type)
+{
+    if (type == &PyZoneInfo_ZoneInfoType) {
+        return ZONEINFO_WEAK_CACHE;
+    }
+    else {
+        PyObject *cache =
+            PyObject_GetAttrString((PyObject *)type, "_weak_cache");
+        // We are assuming that the type lives at least as long as the function
+        // that calls get_weak_cache, and that it holds a reference to the
+        // cache, so we'll return a "borrowed reference".
+        Py_XDECREF(cache);
+        return cache;
+    }
+}
+
+static PyObject *
+zoneinfo_new(PyTypeObject *type, PyObject *args, PyObject *kw)
+{
+    PyObject *key = NULL;
+    static char *kwlist[] = {"key", NULL};
+    if (PyArg_ParseTupleAndKeywords(args, kw, "O", kwlist, &key) == 0) {
+        return NULL;
+    }
+
+    PyObject *instance = zone_from_strong_cache(type, key);
+    if (instance != NULL) {
+        return instance;
+    }
+
+    PyObject *weak_cache = get_weak_cache(type);
+    instance = PyObject_CallMethod(weak_cache, "get", "O", key, Py_None);
+    if (instance == NULL) {
+        return NULL;
+    }
+
+    if (instance == Py_None) {
+        Py_DECREF(instance);
+        PyObject *tmp = zoneinfo_new_instance(type, key);
+        if (tmp == NULL) {
+            return NULL;
+        }
+
+        instance =
+            PyObject_CallMethod(weak_cache, "setdefault", "OO", key, tmp);
+        ((PyZoneInfo_ZoneInfo *)instance)->source = SOURCE_CACHE;
+
+        Py_DECREF(tmp);
+
+        if (instance == NULL) {
+            return NULL;
+        }
+    }
+
+    update_strong_cache(type, key, instance);
+    return instance;
+}
+
+static void
+zoneinfo_dealloc(PyObject *obj_self)
+{
+    PyZoneInfo_ZoneInfo *self = (PyZoneInfo_ZoneInfo *)obj_self;
+
+    if (self->weakreflist != NULL) {
+        PyObject_ClearWeakRefs(obj_self);
+    }
+
+    if (self->trans_list_utc != NULL) {
+        PyMem_Free(self->trans_list_utc);
+    }
+
+    for (size_t i = 0; i < 2; i++) {
+        if (self->trans_list_wall[i] != NULL) {
+            PyMem_Free(self->trans_list_wall[i]);
+        }
+    }
+
+    if (self->_ttinfos != NULL) {
+        for (size_t i = 0; i < self->num_ttinfos; ++i) {
+            xdecref_ttinfo(&(self->_ttinfos[i]));
+        }
+        PyMem_Free(self->_ttinfos);
+    }
+
+    if (self->trans_ttinfos != NULL) {
+        PyMem_Free(self->trans_ttinfos);
+    }
+
+    free_tzrule(&(self->tzrule_after));
+
+    Py_XDECREF(self->key);
+    Py_XDECREF(self->file_repr);
+
+    Py_TYPE(self)->tp_free((PyObject *)self);
+}
+
+static PyObject *
+zoneinfo_from_file(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+    PyObject *file_obj = NULL;
+    PyObject *file_repr = NULL;
+    PyObject *key = Py_None;
+    PyZoneInfo_ZoneInfo *self = NULL;
+
+    static char *kwlist[] = {"", "key", NULL};
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", kwlist, &file_obj,
+                                     &key)) {
+        return NULL;
+    }
+
+    PyObject *obj_self = (PyObject *)(type->tp_alloc(type, 0));
+    self = (PyZoneInfo_ZoneInfo *)obj_self;
+    if (self == NULL) {
+        return NULL;
+    }
+
+    file_repr = PyUnicode_FromFormat("%R", file_obj);
+    if (file_repr == NULL) {
+        goto error;
+    }
+
+    if (load_data(self, file_obj)) {
+        goto error;
+    }
+
+    self->source = SOURCE_FILE;
+    self->file_repr = file_repr;
+    self->key = key;
+    Py_INCREF(key);
+
+    return obj_self;
+error:
+    Py_XDECREF(file_repr);
+    Py_XDECREF(self);
+    return NULL;
+}
+
+static PyObject *
+zoneinfo_no_cache(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
+{
+    static char *kwlist[] = {"key", NULL};
+    PyObject *key = NULL;
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &key)) {
+        return NULL;
+    }
+
+    PyObject *out = zoneinfo_new_instance(cls, key);
+    if (out != NULL) {
+        ((PyZoneInfo_ZoneInfo *)out)->source = SOURCE_NOCACHE;
+    }
+
+    return out;
+}
+
+static PyObject *
+zoneinfo_clear_cache(PyObject *cls, PyObject *args, PyObject *kwargs)
+{
+    PyObject *only_keys = NULL;
+    static char *kwlist[] = {"only_keys", NULL};
+
+    if (!(PyArg_ParseTupleAndKeywords(args, kwargs, "|$O", kwlist,
+                                      &only_keys))) {
+        return NULL;
+    }
+
+    PyTypeObject *type = (PyTypeObject *)cls;
+    PyObject *weak_cache = get_weak_cache(type);
+
+    if (only_keys == NULL || only_keys == Py_None) {
+        PyObject *rv = PyObject_CallMethod(weak_cache, "clear", NULL);
+        if (rv != NULL) {
+            Py_DECREF(rv);
+        }
+
+        clear_strong_cache(type);
+        ZONEINFO_STRONG_CACHE = NULL;
+    }
+    else {
+        PyObject *item = NULL;
+        PyObject *pop = PyUnicode_FromString("pop");
+        if (pop == NULL) {
+            return NULL;
+        }
+
+        PyObject *iter = PyObject_GetIter(only_keys);
+        if (iter == NULL) {
+            Py_DECREF(pop);
+            return NULL;
+        }
+
+        while ((item = PyIter_Next(iter))) {
+            // Remove from strong cache
+            eject_from_strong_cache(type, item);
+
+            // Remove from weak cache
+            PyObject *tmp = PyObject_CallMethodObjArgs(weak_cache, pop, item,
+                                                       Py_None, NULL);
+
+            Py_DECREF(item);
+            if (tmp == NULL) {
+                break;
+            }
+            Py_DECREF(tmp);
+        }
+        Py_DECREF(iter);
+        Py_DECREF(pop);
+    }
+
+    if (PyErr_Occurred()) {
+        return NULL;
+    }
+
+    Py_RETURN_NONE;
+}
+
+static PyObject *
+zoneinfo_utcoffset(PyObject *self, PyObject *dt)
+{
+    _ttinfo *tti = find_ttinfo((PyZoneInfo_ZoneInfo *)self, dt);
+    if (tti == NULL) {
+        return NULL;
+    }
+    Py_INCREF(tti->utcoff);
+    return tti->utcoff;
+}
+
+static PyObject *
+zoneinfo_dst(PyObject *self, PyObject *dt)
+{
+    _ttinfo *tti = find_ttinfo((PyZoneInfo_ZoneInfo *)self, dt);
+    if (tti == NULL) {
+        return NULL;
+    }
+    Py_INCREF(tti->dstoff);
+    return tti->dstoff;
+}
+
+static PyObject *
+zoneinfo_tzname(PyObject *self, PyObject *dt)
+{
+    _ttinfo *tti = find_ttinfo((PyZoneInfo_ZoneInfo *)self, dt);
+    if (tti == NULL) {
+        return NULL;
+    }
+    Py_INCREF(tti->tzname);
+    return tti->tzname;
+}
+
+#define HASTZINFO(p) (((_PyDateTime_BaseTZInfo *)(p))->hastzinfo)
+#define GET_DT_TZINFO(p) \
+    (HASTZINFO(p) ? ((PyDateTime_DateTime *)(p))->tzinfo : Py_None)
+
+static PyObject *
+zoneinfo_fromutc(PyObject *obj_self, PyObject *dt)
+{
+    if (!PyDateTime_Check(dt)) {
+        PyErr_SetString(PyExc_TypeError,
+                        "fromutc: argument must be a datetime");
+        return NULL;
+    }
+    if (GET_DT_TZINFO(dt) != obj_self) {
+        PyErr_SetString(PyExc_ValueError,
+                        "fromutc: dt.tzinfo "
+                        "is not self");
+        return NULL;
+    }
+
+    PyZoneInfo_ZoneInfo *self = (PyZoneInfo_ZoneInfo *)obj_self;
+
+    int64_t timestamp;
+    if (get_local_timestamp(dt, &timestamp)) {
+        return NULL;
+    }
+    size_t num_trans = self->num_transitions;
+
+    _ttinfo *tti = NULL;
+    unsigned char fold = 0;
+
+    if (num_trans >= 1 && timestamp < self->trans_list_utc[0]) {
+        tti = self->ttinfo_before;
+    }
+    else if (num_trans == 0 ||
+             timestamp > self->trans_list_utc[num_trans - 1]) {
+        tti = find_tzrule_ttinfo_fromutc(&(self->tzrule_after), timestamp,
+                                         PyDateTime_GET_YEAR(dt), &fold);
+
+        // Immediately after the last manual transition, the fold/gap is
+        // between self->trans_ttinfos[num_transitions - 1] and whatever
+        // ttinfo applies immediately after the last transition, not between
+        // the STD and DST rules in the tzrule_after, so we may need to
+        // adjust the fold value.
+        if (num_trans) {
+            _ttinfo *tti_prev = NULL;
+            if (num_trans == 1) {
+                tti_prev = self->ttinfo_before;
+            }
+            else {
+                tti_prev = self->trans_ttinfos[num_trans - 2];
+            }
+            int64_t diff = tti_prev->utcoff_seconds - tti->utcoff_seconds;
+            if (diff > 0 &&
+                timestamp < (self->trans_list_utc[num_trans - 1] + diff)) {
+                fold = 1;
+            }
+        }
+    }
+    else {
+        size_t idx = _bisect(timestamp, self->trans_list_utc, num_trans);
+        _ttinfo *tti_prev = NULL;
+
+        if (idx >= 2) {
+            tti_prev = self->trans_ttinfos[idx - 2];
+            tti = self->trans_ttinfos[idx - 1];
+        }
+        else {
+            tti_prev = self->ttinfo_before;
+            tti = self->trans_ttinfos[0];
+        }
+
+        // Detect fold
+        int64_t shift =
+            (int64_t)(tti_prev->utcoff_seconds - tti->utcoff_seconds);
+        if (shift > (timestamp - self->trans_list_utc[idx - 1])) {
+            fold = 1;
+        }
+    }
+
+    PyObject *tmp = PyNumber_Add(dt, tti->utcoff);
+    if (tmp == NULL) {
+        return NULL;
+    }
+
+    if (fold) {
+        if (PyDateTime_CheckExact(tmp)) {
+            ((PyDateTime_DateTime *)tmp)->fold = 1;
+            dt = tmp;
+        }
+        else {
+            PyObject *replace = PyObject_GetAttrString(tmp, "replace");
+            PyObject *args = PyTuple_New(0);
+            PyObject *kwargs = PyDict_New();
+
+            Py_DECREF(tmp);
+            if (args == NULL || kwargs == NULL || replace == NULL) {
+                Py_XDECREF(args);
+                Py_XDECREF(kwargs);
+                Py_XDECREF(replace);
+                return NULL;
+            }
+
+            dt = NULL;
+            if (!PyDict_SetItemString(kwargs, "fold", _PyLong_One)) {
+                dt = PyObject_Call(replace, args, kwargs);
+            }
+
+            Py_DECREF(args);
+            Py_DECREF(kwargs);
+            Py_DECREF(replace);
+
+            if (dt == NULL) {
+                return NULL;
+            }
+        }
+    }
+    else {
+        dt = tmp;
+    }
+    return dt;
+}
+
+static PyObject *
+zoneinfo_repr(PyZoneInfo_ZoneInfo *self)
+{
+    PyObject *rv = NULL;
+    const char *type_name = Py_TYPE((PyObject *)self)->tp_name;
+    if (!(self->key == Py_None)) {
+        rv = PyUnicode_FromFormat("%s(key=%R)", type_name, self->key);
+    }
+    else {
+        assert(PyUnicode_Check(self->file_repr));
+        rv = PyUnicode_FromFormat("%s.from_file(%U)", type_name,
+                                  self->file_repr);
+    }
+
+    return rv;
+}
+
+static PyObject *
+zoneinfo_str(PyZoneInfo_ZoneInfo *self)
+{
+    if (!(self->key == Py_None)) {
+        Py_INCREF(self->key);
+        return self->key;
+    }
+    else {
+        return zoneinfo_repr(self);
+    }
+}
+
+/* Pickles the ZoneInfo object by key and source.
+ *
+ * ZoneInfo objects are pickled by reference to the TZif file that they came
+ * from, which means that the exact transitions may be different or the file
+ * may not un-pickle if the data has changed on disk in the interim.
+ *
+ * It is necessary to include a bit indicating whether or not the object
+ * was constructed from the cache, because from-cache objects will hit the
+ * unpickling process's cache, whereas no-cache objects will bypass it.
+ *
+ * Objects constructed from ZoneInfo.from_file cannot be pickled.
+ */
+static PyObject *
+zoneinfo_reduce(PyObject *obj_self, PyObject *unused)
+{
+    PyZoneInfo_ZoneInfo *self = (PyZoneInfo_ZoneInfo *)obj_self;
+    if (self->source == SOURCE_FILE) {
+        // Objects constructed from files cannot be pickled.
+        PyObject *pickle = PyImport_ImportModule("pickle");
+        if (pickle == NULL) {
+            return NULL;
+        }
+
+        PyObject *pickle_error =
+            PyObject_GetAttrString(pickle, "PicklingError");
+        Py_DECREF(pickle);
+        if (pickle_error == NULL) {
+            return NULL;
+        }
+
+        PyErr_Format(pickle_error,
+                     "Cannot pickle a ZoneInfo file from a file stream.");
+        Py_DECREF(pickle_error);
+        return NULL;
+    }
+
+    unsigned char from_cache = self->source == SOURCE_CACHE ? 1 : 0;
+    PyObject *constructor = PyObject_GetAttrString(obj_self, "_unpickle");
+
+    if (constructor == NULL) {
+        return NULL;
+    }
+
+    PyObject *rv = Py_BuildValue("O(OB)", constructor, self->key, from_cache);
+    Py_DECREF(constructor);
+    return rv;
+}
+
+static PyObject *
+zoneinfo__unpickle(PyTypeObject *cls, PyObject *args)
+{
+    PyObject *key;
+    unsigned char from_cache;
+    if (!PyArg_ParseTuple(args, "OB", &key, &from_cache)) {
+        return NULL;
+    }
+
+    if (from_cache) {
+        PyObject *val_args = Py_BuildValue("(O)", key);
+        if (val_args == NULL) {
+            return NULL;
+        }
+
+        PyObject *rv = zoneinfo_new(cls, val_args, NULL);
+
+        Py_DECREF(val_args);
+        return rv;
+    }
+    else {
+        return zoneinfo_new_instance(cls, key);
+    }
+}
+
+/* It is relatively expensive to construct new timedelta objects, and in most
+ * cases we're looking at a relatively small number of timedeltas, such as
+ * integer number of hours, etc. We will keep a cache so that we construct
+ * a minimal number of these.
+ *
+ * Possibly this should be replaced with an LRU cache so that it's not possible
+ * for the memory usage to explode from this, but in order for this to be a
+ * serious problem, one would need to deliberately craft a malicious time zone
+ * file with many distinct offsets. As of tzdb 2019c, loading every single zone
+ * fills the cache with ~450 timedeltas for a total size of ~12kB.
+ *
+ * This returns a new reference to the timedelta.
+ */
+static PyObject *
+load_timedelta(long seconds)
+{
+    PyObject *rv = NULL;
+    PyObject *pyoffset = PyLong_FromLong(seconds);
+    if (pyoffset == NULL) {
+        return NULL;
+    }
+    int contains = PyDict_Contains(TIMEDELTA_CACHE, pyoffset);
+    if (contains == -1) {
+        goto error;
+    }
+
+    if (!contains) {
+        PyObject *tmp = PyDateTimeAPI->Delta_FromDelta(
+            0, seconds, 0, 1, PyDateTimeAPI->DeltaType);
+
+        if (tmp == NULL) {
+            goto error;
+        }
+
+        rv = PyDict_SetDefault(TIMEDELTA_CACHE, pyoffset, tmp);
+        Py_DECREF(tmp);
+    }
+    else {
+        rv = PyDict_GetItem(TIMEDELTA_CACHE, pyoffset);
+    }
+
+    Py_DECREF(pyoffset);
+    Py_INCREF(rv);
+    return rv;
+error:
+    Py_DECREF(pyoffset);
+    return NULL;
+}
+
+/* Constructor for _ttinfo object - this starts by initializing the _ttinfo
+ * to { NULL, NULL, NULL }, so that Py_XDECREF will work on partially
+ * initialized _ttinfo objects.
+ */
+static int
+build_ttinfo(long utcoffset, long dstoffset, PyObject *tzname, _ttinfo *out)
+{
+    out->utcoff = NULL;
+    out->dstoff = NULL;
+    out->tzname = NULL;
+
+    out->utcoff_seconds = utcoffset;
+    out->utcoff = load_timedelta(utcoffset);
+    if (out->utcoff == NULL) {
+        return -1;
+    }
+
+    out->dstoff = load_timedelta(dstoffset);
+    if (out->dstoff == NULL) {
+        return -1;
+    }
+
+    out->tzname = tzname;
+    Py_INCREF(tzname);
+
+    return 0;
+}
+
+/* Decrease reference count on any non-NULL members of a _ttinfo  */
+static void
+xdecref_ttinfo(_ttinfo *ttinfo)
+{
+    if (ttinfo != NULL) {
+        Py_XDECREF(ttinfo->utcoff);
+        Py_XDECREF(ttinfo->dstoff);
+        Py_XDECREF(ttinfo->tzname);
+    }
+}
+
+/* Equality function for _ttinfo. */
+static int
+ttinfo_eq(const _ttinfo *const tti0, const _ttinfo *const tti1)
+{
+    int rv;
+    if ((rv = PyObject_RichCompareBool(tti0->utcoff, tti1->utcoff, Py_EQ)) <
+        1) {
+        goto end;
+    }
+
+    if ((rv = PyObject_RichCompareBool(tti0->dstoff, tti1->dstoff, Py_EQ)) <
+        1) {
+        goto end;
+    }
+
+    if ((rv = PyObject_RichCompareBool(tti0->tzname, tti1->tzname, Py_EQ)) <
+        1) {
+        goto end;
+    }
+end:
+    return rv;
+}
+
+/* Given a file-like object, this populates a ZoneInfo object
+ *
+ * The current version calls into a Python function to read the data from
+ * file into Python objects, and this translates those Python objects into
+ * C values and calculates derived values (e.g. dstoff) in C.
+ *
+ * This returns 0 on success and -1 on failure.
+ *
+ * The function will never return while `self` is partially initialized —
+ * the object only needs to be freed / deallocated if this succeeds.
+ */
+static int
+load_data(PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
+{
+    PyObject *data_tuple = NULL;
+
+    long *utcoff = NULL;
+    long *dstoff = NULL;
+    size_t *trans_idx = NULL;
+    unsigned char *isdst = NULL;
+
+    self->trans_list_utc = NULL;
+    self->trans_list_wall[0] = NULL;
+    self->trans_list_wall[1] = NULL;
+    self->trans_ttinfos = NULL;
+    self->_ttinfos = NULL;
+    self->file_repr = NULL;
+
+    size_t ttinfos_allocated = 0;
+
+    data_tuple = PyObject_CallMethod(_common_mod, "load_data", "O", file_obj);
+
+    if (data_tuple == NULL) {
+        goto error;
+    }
+
+    if (!PyTuple_CheckExact(data_tuple)) {
+        PyErr_Format(PyExc_TypeError, "Invalid data result type: %r",
+                     data_tuple);
+        goto error;
+    }
+
+    // Unpack the data tuple
+    PyObject *trans_idx_list = PyTuple_GetItem(data_tuple, 0);
+    if (trans_idx_list == NULL) {
+        goto error;
+    }
+
+    PyObject *trans_utc = PyTuple_GetItem(data_tuple, 1);
+    if (trans_utc == NULL) {
+        goto error;
+    }
+
+    PyObject *utcoff_list = PyTuple_GetItem(data_tuple, 2);
+    if (utcoff_list == NULL) {
+        goto error;
+    }
+
+    PyObject *isdst_list = PyTuple_GetItem(data_tuple, 3);
+    if (isdst_list == NULL) {
+        goto error;
+    }
+
+    PyObject *abbr = PyTuple_GetItem(data_tuple, 4);
+    if (abbr == NULL) {
+        goto error;
+    }
+
+    PyObject *tz_str = PyTuple_GetItem(data_tuple, 5);
+    if (tz_str == NULL) {
+        goto error;
+    }
+
+    // Load the relevant sizes
+    Py_ssize_t num_transitions = PyTuple_Size(trans_utc);
+    if (num_transitions == -1) {
+        goto error;
+    }
+
+    Py_ssize_t num_ttinfos = PyTuple_Size(utcoff_list);
+    if (num_ttinfos == -1) {
+        goto error;
+    }
+
+    self->num_transitions = (size_t)num_transitions;
+    self->num_ttinfos = (size_t)num_ttinfos;
+
+    // Load the transition indices and list
+    self->trans_list_utc =
+        PyMem_Malloc(self->num_transitions * sizeof(int64_t));
+    trans_idx = PyMem_Malloc(self->num_transitions * sizeof(Py_ssize_t));
+
+    for (Py_ssize_t i = 0; i < self->num_transitions; ++i) {
+        PyObject *num = PyTuple_GetItem(trans_utc, i);
+        if (num == NULL) {
+            goto error;
+        }
+        self->trans_list_utc[i] = PyLong_AsLongLong(num);
+        if (self->trans_list_utc[i] == -1 && PyErr_Occurred()) {
+            goto error;
+        }
+
+        num = PyTuple_GetItem(trans_idx_list, i);
+        if (num == NULL) {
+            goto error;
+        }
+
+        Py_ssize_t cur_trans_idx = PyLong_AsSsize_t(num);
+        if (cur_trans_idx == -1) {
+            goto error;
+        }
+
+        trans_idx[i] = (size_t)cur_trans_idx;
+        if (trans_idx[i] > self->num_ttinfos) {
+            PyErr_Format(
+                PyExc_ValueError,
+                "Invalid transition index found while reading TZif: %zd",
+                cur_trans_idx);
+
+            goto error;
+        }
+    }
+
+    // Load UTC offsets and isdst (size num_ttinfos)
+    utcoff = PyMem_Malloc(self->num_ttinfos * sizeof(long));
+    isdst = PyMem_Malloc(self->num_ttinfos * sizeof(unsigned char));
+
+    if (utcoff == NULL || isdst == NULL) {
+        goto error;
+    }
+    for (Py_ssize_t i = 0; i < self->num_ttinfos; ++i) {
+        PyObject *num = PyTuple_GetItem(utcoff_list, i);
+        if (num == NULL) {
+            goto error;
+        }
+
+        utcoff[i] = PyLong_AsLong(num);
+        if (utcoff[i] == -1 && PyErr_Occurred()) {
+            goto error;
+        }
+
+        num = PyTuple_GetItem(isdst_list, i);
+        if (num == NULL) {
+            goto error;
+        }
+
+        int isdst_with_error = PyObject_IsTrue(num);
+        if (isdst_with_error == -1) {
+            goto error;
+        }
+        else {
+            isdst[i] = (unsigned char)isdst_with_error;
+        }
+    }
+
+    dstoff = PyMem_Calloc(self->num_ttinfos, sizeof(long));
+    if (dstoff == NULL) {
+        goto error;
+    }
+
+    // Derive dstoff and trans_list_wall from the information we've loaded
+    utcoff_to_dstoff(trans_idx, utcoff, dstoff, isdst, self->num_transitions,
+                     self->num_ttinfos);
+
+    if (ts_to_local(trans_idx, self->trans_list_utc, utcoff,
+                    self->trans_list_wall, self->num_ttinfos,
+                    self->num_transitions)) {
+        goto error;
+    }
+
+    // Build _ttinfo objects from utcoff, dstoff and abbr
+    self->_ttinfos = PyMem_Malloc(self->num_ttinfos * sizeof(_ttinfo));
+    for (size_t i = 0; i < self->num_ttinfos; ++i) {
+        PyObject *tzname = PyTuple_GetItem(abbr, i);
+        if (tzname == NULL) {
+            goto error;
+        }
+
+        ttinfos_allocated++;
+        if (build_ttinfo(utcoff[i], dstoff[i], tzname, &(self->_ttinfos[i]))) {
+            goto error;
+        }
+    }
+
+    // Build our mapping from transition to the ttinfo that applies
+    self->trans_ttinfos =
+        PyMem_Calloc(self->num_transitions, sizeof(_ttinfo *));
+    for (size_t i = 0; i < self->num_transitions; ++i) {
+        size_t ttinfo_idx = trans_idx[i];
+        assert(ttinfo_idx < self->num_ttinfos);
+        self->trans_ttinfos[i] = &(self->_ttinfos[ttinfo_idx]);
+    }
+
+    // Set ttinfo_before to the first non-DST transition
+    for (size_t i = 0; i < self->num_ttinfos; ++i) {
+        if (!isdst[i]) {
+            self->ttinfo_before = &(self->_ttinfos[i]);
+            break;
+        }
+    }
+
+    // If there are only DST ttinfos, pick the first one, if there are no
+    // ttinfos at all, set ttinfo_before to NULL
+    if (self->ttinfo_before == NULL && self->num_ttinfos > 0) {
+        self->ttinfo_before = &(self->_ttinfos[0]);
+    }
+
+    if (tz_str != Py_None && PyObject_IsTrue(tz_str)) {
+        if (parse_tz_str(tz_str, &(self->tzrule_after))) {
+            goto error;
+        }
+    }
+    else {
+        if (!self->num_ttinfos) {
+            PyErr_Format(PyExc_ValueError, "No time zone information found.");
+            goto error;
+        }
+
+        size_t idx;
+        if (!self->num_transitions) {
+            idx = self->num_ttinfos - 1;
+        }
+        else {
+            idx = trans_idx[self->num_transitions - 1];
+        }
+
+        _ttinfo *tti = &(self->_ttinfos[idx]);
+        build_tzrule(tti->tzname, NULL, tti->utcoff_seconds, 0, NULL, NULL,
+                     &(self->tzrule_after));
+
+        // We've abused the build_tzrule constructor to construct an STD-only
+        // rule mimicking whatever ttinfo we've picked up, but it's possible
+        // that the one we've picked up is a DST zone, so we need to make sure
+        // that the dstoff is set correctly in that case.
+        if (PyObject_IsTrue(tti->dstoff)) {
+            _ttinfo *tti_after = &(self->tzrule_after.std);
+            Py_DECREF(tti_after->dstoff);
+            tti_after->dstoff = tti->dstoff;
+            Py_INCREF(tti_after->dstoff);
+        }
+    }
+
+    // Determine if this is a "fixed offset" zone, meaning that the output of
+    // the utcoffset, dst and tzname functions does not depend on the specific
+    // datetime passed.
+    //
+    // We make three simplifying assumptions here:
+    //
+    // 1. If tzrule_after is not std_only, it has transitions that might occur
+    //    (it is possible to construct TZ strings that specify STD and DST but
+    //    no transitions ever occur, such as AAA0BBB,0/0,J365/25).
+    // 2. If self->_ttinfos contains more than one _ttinfo object, the objects
+    //    represent different offsets.
+    // 3. self->ttinfos contains no unused _ttinfos (in which case an otherwise
+    //    fixed-offset zone with extra _ttinfos defined may appear to *not* be
+    //    a fixed offset zone).
+    //
+    // Violations to these assumptions would be fairly exotic, and exotic
+    // zones should almost certainly not be used with datetime.time (the
+    // only thing that would be affected by this).
+    if (self->num_ttinfos > 1 || !self->tzrule_after.std_only) {
+        self->fixed_offset = 0;
+    }
+    else if (self->num_ttinfos == 0) {
+        self->fixed_offset = 1;
+    }
+    else {
+        int constant_offset =
+            ttinfo_eq(&(self->_ttinfos[0]), &self->tzrule_after.std);
+        if (constant_offset < 0) {
+            goto error;
+        }
+        else {
+            self->fixed_offset = constant_offset;
+        }
+    }
+
+    int rv = 0;
+    goto cleanup;
+error:
+    // These resources only need to be freed if we have failed, if we succeed
+    // in initializing a PyZoneInfo_ZoneInfo object, we can rely on its dealloc
+    // method to free the relevant resources.
+    if (self->trans_list_utc != NULL) {
+        PyMem_Free(self->trans_list_utc);
+        self->trans_list_utc = NULL;
+    }
+
+    for (size_t i = 0; i < 2; ++i) {
+        if (self->trans_list_wall[i] != NULL) {
+            PyMem_Free(self->trans_list_wall[i]);
+            self->trans_list_wall[i] = NULL;
+        }
+    }
+
+    if (self->_ttinfos != NULL) {
+        for (size_t i = 0; i < ttinfos_allocated; ++i) {
+            xdecref_ttinfo(&(self->_ttinfos[i]));
+        }
+        PyMem_Free(self->_ttinfos);
+        self->_ttinfos = NULL;
+    }
+
+    if (self->trans_ttinfos != NULL) {
+        PyMem_Free(self->trans_ttinfos);
+        self->trans_ttinfos = NULL;
+    }
+
+    rv = -1;
+cleanup:
+    Py_XDECREF(data_tuple);
+
+    if (utcoff != NULL) {
+        PyMem_Free(utcoff);
+    }
+
+    if (dstoff != NULL) {
+        PyMem_Free(dstoff);
+    }
+
+    if (isdst != NULL) {
+        PyMem_Free(isdst);
+    }
+
+    if (trans_idx != NULL) {
+        PyMem_Free(trans_idx);
+    }
+
+    return rv;
+}
+
+/* Function to calculate the local timestamp of a transition from the year. */
+int64_t
+calendarrule_year_to_timestamp(TransitionRuleType *base_self, int year)
+{
+    CalendarRule *self = (CalendarRule *)base_self;
+
+    // We want (year, month, day of month); we have year and month, but we
+    // need to turn (week, day-of-week) into day-of-month
+    //
+    // Week 1 is the first week in which day `day` (where 0 = Sunday) appears.
+    // Week 5 represents the last occurrence of day `day`, so we need to know
+    // the first weekday of the month and the number of days in the month.
+    int8_t first_day = (ymd_to_ord(year, self->month, 1) + 6) % 7;
+    uint8_t days_in_month = DAYS_IN_MONTH[self->month];
+    if (self->month == 2 && is_leap_year(year)) {
+        days_in_month += 1;
+    }
+
+    // This equation seems magical, so I'll break it down:
+    // 1. calendar says 0 = Monday, POSIX says 0 = Sunday so we need first_day
+    //    + 1 to get 1 = Monday -> 7 = Sunday, which is still equivalent
+    //    because this math is mod 7
+    // 2. Get first day - desired day mod 7 (adjusting by 7 for negative
+    //    numbers so that -1 % 7 = 6).
+    // 3. Add 1 because month days are a 1-based index.
+    int8_t month_day = ((int8_t)(self->day) - (first_day + 1)) % 7;
+    if (month_day < 0) {
+        month_day += 7;
+    }
+    month_day += 1;
+
+    // Now use a 0-based index version of `week` to calculate the w-th
+    // occurrence of `day`
+    month_day += ((int8_t)(self->week) - 1) * 7;
+
+    // month_day will only be > days_in_month if w was 5, and `w` means "last
+    // occurrence of `d`", so now we just check if we over-shot the end of the
+    // month and if so knock off 1 week.
+    if (month_day > days_in_month) {
+        month_day -= 7;
+    }
+
+    int64_t ordinal = ymd_to_ord(year, self->month, month_day) - EPOCHORDINAL;
+    return ((ordinal * 86400) + (int64_t)(self->hour * 3600) +
+            (int64_t)(self->minute * 60) + (int64_t)(self->second));
+}
+
+/* Constructor for CalendarRule. */
+int
+calendarrule_new(uint8_t month, uint8_t week, uint8_t day, int8_t hour,
+                 int8_t minute, int8_t second, CalendarRule *out)
+{
+    // These bounds come from the POSIX standard, which describes an Mm.n.d
+    // rule as:
+    //
+    //   The d'th day (0 <= d <= 6) of week n of month m of the year (1 <= n <=
+    //   5, 1 <= m <= 12, where week 5 means "the last d day in month m" which
+    //   may occur in either the fourth or the fifth week). Week 1 is the first
+    //   week in which the d'th day occurs. Day zero is Sunday.
+    if (month <= 0 || month > 12) {
+        PyErr_Format(PyExc_ValueError, "Month must be in (0, 12]");
+        return -1;
+    }
+
+    if (week <= 0 || week > 5) {
+        PyErr_Format(PyExc_ValueError, "Week must be in (0, 5]");
+        return -1;
+    }
+
+    // day is an unsigned integer, so day < 0 should always return false, but
+    // if day's type changes to a signed integer *without* changing this value,
+    // it may create a bug. Considering that the compiler should be able to
+    // optimize out the first comparison if day is an unsigned integer anyway,
+    // we will leave this comparison in place and disable the compiler warning.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wtype-limits"
+    if (day < 0 || day > 6) {
+#pragma GCC diagnostic pop
+        PyErr_Format(PyExc_ValueError, "Day must be in [0, 6]");
+        return -1;
+    }
+
+    TransitionRuleType base = {&calendarrule_year_to_timestamp};
+
+    CalendarRule new_offset = {
+        .base = base,
+        .month = month,
+        .week = week,
+        .day = day,
+        .hour = hour,
+        .minute = minute,
+        .second = second,
+    };
+
+    *out = new_offset;
+    return 0;
+}
+
+/* Function to calculate the local timestamp of a transition from the year.
+ *
+ * This translates the day of the year into a local timestamp — either a
+ * 1-based Julian day, not including leap days, or the 0-based year-day,
+ * including leap days.
+ * */
+int64_t
+dayrule_year_to_timestamp(TransitionRuleType *base_self, int year)
+{
+    // The function signature requires a TransitionRuleType pointer, but this
+    // function is only applicable to DayRule* objects.
+    DayRule *self = (DayRule *)base_self;
+
+    // ymd_to_ord calculates the number of days since 0001-01-01, but we want
+    // to know the number of days since 1970-01-01, so we must subtract off
+    // the equivalent of ymd_to_ord(1970, 1, 1).
+    //
+    // We subtract off an additional 1 day to account for January 1st (we want
+    // the number of full days *before* the date of the transition - partial
+    // days are accounted for in the hour, minute and second portions.
+    int64_t days_before_year = ymd_to_ord(year, 1, 1) - EPOCHORDINAL - 1;
+
+    // The Julian day specification skips over February 29th in leap years,
+    // from the POSIX standard:
+    //
+    //   Leap days shall not be counted. That is, in all years-including leap
+    //   years-February 28 is day 59 and March 1 is day 60. It is impossible to
+    //   refer explicitly to the occasional February 29.
+    //
+    // This is actually more useful than you'd think — if you want a rule that
+    // always transitions on a given calendar day (other than February 29th),
+    // you would use a Julian day, e.g. J91 always refers to April 1st and J365
+    // always refers to December 31st.
+    unsigned int day = self->day;
+    if (self->julian && day >= 59 && is_leap_year(year)) {
+        day += 1;
+    }
+
+    return ((days_before_year + day) * 86400) + (self->hour * 3600) +
+           (self->minute * 60) + self->second;
+}
+
+/* Constructor for DayRule. */
+static int
+dayrule_new(uint8_t julian, unsigned int day, int8_t hour, int8_t minute,
+            int8_t second, DayRule *out)
+{
+    // The POSIX standard specifies that Julian days must be in the range (1 <=
+    // n <= 365) and that non-Julian (they call it "0-based Julian") days must
+    // be in the range (0 <= n <= 365).
+    if (day < julian || day > 365) {
+        PyErr_Format(PyExc_ValueError, "day must be in [%u, 365], not: %u",
+                     julian, day);
+        return -1;
+    }
+
+    TransitionRuleType base = {
+        &dayrule_year_to_timestamp,
+    };
+
+    DayRule tmp = {
+        .base = base,
+        .julian = julian,
+        .day = day,
+        .hour = hour,
+        .minute = minute,
+        .second = second,
+    };
+
+    *out = tmp;
+
+    return 0;
+}
+
+/* Calculate the start and end rules for a _tzrule in the given year. */
+static void
+tzrule_transitions(_tzrule *rule, int year, int64_t *start, int64_t *end)
+{
+    assert(rule->start != NULL);
+    assert(rule->end != NULL);
+    *start = rule->start->year_to_timestamp(rule->start, year);
+    *end = rule->end->year_to_timestamp(rule->end, year);
+}
+
+/* Calculate the _ttinfo that applies at a given local time from a _tzrule.
+ *
+ * This takes a local timestamp and fold for disambiguation purposes; the year
+ * could technically be calculated from the timestamp, but given that the
+ * callers of this function already have the year information accessible from
+ * the datetime struct, it is taken as an additional parameter to reduce
+ * unncessary calculation.
+ * */
+static _ttinfo *
+find_tzrule_ttinfo(_tzrule *rule, int64_t ts, unsigned char fold, int year)
+{
+    if (rule->std_only) {
+        return &(rule->std);
+    }
+
+    int64_t start, end;
+    uint8_t isdst;
+
+    tzrule_transitions(rule, year, &start, &end);
+
+    // With fold = 0, the period (denominated in local time) with the smaller
+    // offset starts at the end of the gap and ends at the end of the fold;
+    // with fold = 1, it runs from the start of the gap to the beginning of the
+    // fold.
+    //
+    // So in order to determine the DST boundaries we need to know both the
+    // fold and whether DST is positive or negative (rare), and it turns out
+    // that this boils down to fold XOR is_positive.
+    if (fold == (rule->dst_diff >= 0)) {
+        end -= rule->dst_diff;
+    }
+    else {
+        start += rule->dst_diff;
+    }
+
+    if (start < end) {
+        isdst = (ts >= start) && (ts < end);
+    }
+    else {
+        isdst = (ts < end) || (ts >= start);
+    }
+
+    if (isdst) {
+        return &(rule->dst);
+    }
+    else {
+        return &(rule->std);
+    }
+}
+
+/* Calculate the ttinfo and fold that applies for a _tzrule at an epoch time.
+ *
+ * This function can determine the _ttinfo that applies at a given epoch time,
+ * (analogous to trans_list_utc), and whether or not the datetime is in a fold.
+ * This is to be used in the .fromutc() function.
+ *
+ * The year is technically a redundant parameter, because it can be calculated
+ * from the timestamp, but all callers of this function should have the year
+ * in the datetime struct anyway, so taking it as a parameter saves unnecessary
+ * calculation.
+ **/
+static _ttinfo *
+find_tzrule_ttinfo_fromutc(_tzrule *rule, int64_t ts, int year,
+                           unsigned char *fold)
+{
+    if (rule->std_only) {
+        *fold = 0;
+        return &(rule->std);
+    }
+
+    int64_t start, end;
+    uint8_t isdst;
+    tzrule_transitions(rule, year, &start, &end);
+    start -= rule->std.utcoff_seconds;
+    end -= rule->dst.utcoff_seconds;
+
+    if (start < end) {
+        isdst = (ts >= start) && (ts < end);
+    }
+    else {
+        isdst = (ts < end) || (ts >= start);
+    }
+
+    // For positive DST, the ambiguous period is one dst_diff after the end of
+    // DST; for negative DST, the ambiguous period is one dst_diff before the
+    // start of DST.
+    int64_t ambig_start, ambig_end;
+    if (rule->dst_diff > 0) {
+        ambig_start = end;
+        ambig_end = end + rule->dst_diff;
+    }
+    else {
+        ambig_start = start;
+        ambig_end = start - rule->dst_diff;
+    }
+
+    *fold = (ts >= ambig_start) && (ts < ambig_end);
+
+    if (isdst) {
+        return &(rule->dst);
+    }
+    else {
+        return &(rule->std);
+    }
+}
+
+/* Parse a TZ string in the format specified by the POSIX standard:
+ *
+ *  std offset[dst[offset],start[/time],end[/time]]
+ *
+ *  std and dst must be 3 or more characters long and must not contain a
+ *  leading colon, embedded digits, commas, nor a plus or minus signs; The
+ *  spaces between "std" and "offset" are only for display and are not actually
+ *  present in the string.
+ *
+ *  The format of the offset is ``[+|-]hh[:mm[:ss]]``
+ *
+ * See the POSIX.1 spec: IEE Std 1003.1-2018 §8.3:
+ *
+ * https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html
+ */
+static int
+parse_tz_str(PyObject *tz_str_obj, _tzrule *out)
+{
+    PyObject *std_abbr = NULL;
+    PyObject *dst_abbr = NULL;
+    TransitionRuleType *start = NULL;
+    TransitionRuleType *end = NULL;
+    long std_offset, dst_offset;
+
+    char *tz_str = PyBytes_AsString(tz_str_obj);
+    if (tz_str == NULL) {
+        return -1;
+    }
+    char *p = tz_str;
+
+    // Read the `std` abbreviation, which must be at least 3 characters long.
+    ssize_t num_chars = parse_abbr(p, &std_abbr);
+    if (num_chars < 1) {
+        PyErr_Format(PyExc_ValueError, "Invalid STD format in %R", tz_str_obj);
+        goto error;
+    }
+
+    p += num_chars;
+
+    // Now read the STD offset, which is required
+    num_chars = parse_tz_delta(p, &std_offset);
+    if (num_chars < 0) {
+        PyErr_Format(PyExc_ValueError, "Invalid STD offset in %R", tz_str_obj);
+        goto error;
+    }
+    p += num_chars;
+
+    // If the string ends here, there is no DST, otherwise we must parse the
+    // DST abbreviation and start and end dates and times.
+    if (*p == '\0') {
+        goto complete;
+    }
+
+    num_chars = parse_abbr(p, &dst_abbr);
+    if (num_chars < 1) {
+        PyErr_Format(PyExc_ValueError, "Invalid DST format in %R", tz_str_obj);
+        goto error;
+    }
+    p += num_chars;
+
+    if (*p == ',') {
+        // From the POSIX standard:
+        //
+        // If no offset follows dst, the alternative time is assumed to be one
+        // hour ahead of standard time.
+        dst_offset = std_offset + 3600;
+    }
+    else {
+        num_chars = parse_tz_delta(p, &dst_offset);
+        if (num_chars < 0) {
+            PyErr_Format(PyExc_ValueError, "Invalid DST offset in %R",
+                         tz_str_obj);
+            goto error;
+        }
+
+        p += num_chars;
+    }
+
+    TransitionRuleType **transitions[2] = {&start, &end};
+    for (size_t i = 0; i < 2; ++i) {
+        if (*p != ',') {
+            PyErr_Format(PyExc_ValueError,
+                         "Missing transition rules in TZ string: %R",
+                         tz_str_obj);
+            goto error;
+        }
+        p++;
+
+        num_chars = parse_transition_rule(p, transitions[i]);
+        if (num_chars < 0) {
+            PyErr_Format(PyExc_ValueError,
+                         "Malformed transition rule in TZ string: %R",
+                         tz_str_obj);
+            goto error;
+        }
+        p += num_chars;
+    }
+
+    if (*p != '\0') {
+        PyErr_Format(PyExc_ValueError,
+                     "Extraneous characters at end of TZ string: %R",
+                     tz_str_obj);
+        goto error;
+    }
+
+complete:
+    build_tzrule(std_abbr, dst_abbr, std_offset, dst_offset, start, end, out);
+    Py_DECREF(std_abbr);
+    Py_XDECREF(dst_abbr);
+
+    return 0;
+error:
+    Py_XDECREF(std_abbr);
+    if (dst_abbr != NULL && dst_abbr != Py_None) {
+        Py_DECREF(dst_abbr);
+    }
+
+    if (start != NULL) {
+        PyMem_Free(start);
+    }
+
+    if (end != NULL) {
+        PyMem_Free(end);
+    }
+
+    return -1;
+}
+
+static ssize_t
+parse_uint(const char *const p)
+{
+    if (!isdigit(*p)) {
+        return -1;
+    }
+
+    return (*p) - '0';
+}
+
+/* Parse the STD and DST abbreviations from a TZ string. */
+static ssize_t
+parse_abbr(const char *const p, PyObject **abbr)
+{
+    const char *ptr = p;
+    char buff = *ptr;
+    const char *str_start;
+    const char *str_end;
+
+    if (*ptr == '<') {
+        ptr++;
+        str_start = ptr;
+        while ((buff = *ptr) != '>') {
+            // From the POSIX standard:
+            //
+            //   In the quoted form, the first character shall be the less-than
+            //   ( '<' ) character and the last character shall be the
+            //   greater-than ( '>' ) character. All characters between these
+            //   quoting characters shall be alphanumeric characters from the
+            //   portable character set in the current locale, the plus-sign (
+            //   '+' ) character, or the minus-sign ( '-' ) character. The std
+            //   and dst fields in this case shall not include the quoting
+            //   characters.
+            if (!isalpha(buff) && !isdigit(buff) && buff != '+' &&
+                buff != '-') {
+                return -1;
+            }
+            ptr++;
+        }
+        str_end = ptr;
+        ptr++;
+    }
+    else {
+        str_start = p;
+        // From the POSIX standard:
+        //
+        //   In the unquoted form, all characters in these fields shall be
+        //   alphabetic characters from the portable character set in the
+        //   current locale.
+        while (isalpha(*ptr)) {
+            ptr++;
+        }
+        str_end = ptr;
+    }
+
+    *abbr = PyUnicode_FromStringAndSize(str_start, str_end - str_start);
+    if (abbr == NULL) {
+        return -1;
+    }
+
+    return ptr - p;
+}
+
+/* Parse a UTC offset from a TZ str. */
+static ssize_t
+parse_tz_delta(const char *const p, long *total_seconds)
+{
+    // From the POSIX spec:
+    //
+    //   Indicates the value added to the local time to arrive at Coordinated
+    //   Universal Time. The offset has the form:
+    //
+    //   hh[:mm[:ss]]
+    //
+    //   One or more digits may be used; the value is always interpreted as a
+    //   decimal number.
+    //
+    // The POSIX spec says that the values for `hour` must be between 0 and 24
+    // hours, but RFC 8536 §3.3.1 specifies that the hours part of the
+    // transition times may be signed and range from -167 to 167.
+    long sign = -1;
+    long hours = 0;
+    long minutes = 0;
+    long seconds = 0;
+
+    const char *ptr = p;
+    char buff = *ptr;
+    if (buff == '-' || buff == '+') {
+        // Negative numbers correspond to *positive* offsets, from the spec:
+        //
+        //   If preceded by a '-', the timezone shall be east of the Prime
+        //   Meridian; otherwise, it shall be west (which may be indicated by
+        //   an optional preceding '+' ).
+        if (buff == '-') {
+            sign = 1;
+        }
+
+        ptr++;
+    }
+
+    // The hour can be 1 or 2 numeric characters
+    for (size_t i = 0; i < 2; ++i) {
+        buff = *ptr;
+        if (!isdigit(buff)) {
+            if (i == 0) {
+                return -1;
+            }
+            else {
+                break;
+            }
+        }
+
+        hours *= 10;
+        hours += buff - '0';
+        ptr++;
+    }
+
+    if (hours > 24 || hours < 0) {
+        return -1;
+    }
+
+    // Minutes and seconds always of the format ":dd"
+    long *outputs[2] = {&minutes, &seconds};
+    for (size_t i = 0; i < 2; ++i) {
+        if (*ptr != ':') {
+            goto complete;
+        }
+        ptr++;
+
+        for (size_t j = 0; j < 2; ++j) {
+            buff = *ptr;
+            if (!isdigit(buff)) {
+                return -1;
+            }
+            *(outputs[i]) *= 10;
+            *(outputs[i]) += buff - '0';
+            ptr++;
+        }
+    }
+
+complete:
+    *total_seconds = sign * ((hours * 3600) + (minutes * 60) + seconds);
+
+    return ptr - p;
+}
+
+/* Parse the date portion of a transition rule. */
+static ssize_t
+parse_transition_rule(const char *const p, TransitionRuleType **out)
+{
+    // The full transition rule indicates when to change back and forth between
+    // STD and DST, and has the form:
+    //
+    //   date[/time],date[/time]
+    //
+    // This function parses an individual date[/time] section, and returns
+    // the number of characters that contributed to the transition rule. This
+    // does not include the ',' at the end of the first rule.
+    //
+    // The POSIX spec states that if *time* is not given, the default is 02:00.
+    const char *ptr = p;
+    int8_t hour = 2;
+    int8_t minute = 0;
+    int8_t second = 0;
+
+    // Rules come in one of three flavors:
+    //
+    //   1. Jn: Julian day n, with no leap days.
+    //   2. n: Day of year (0-based, with leap days)
+    //   3. Mm.n.d: Specifying by month, week and day-of-week.
+
+    if (*ptr == 'M') {
+        uint8_t month, week, day;
+        ptr++;
+        ssize_t tmp = parse_uint(ptr);
+        if (tmp < 0) {
+            return -1;
+        }
+        month = (uint8_t)tmp;
+        ptr++;
+        if (*ptr != '.') {
+            tmp = parse_uint(ptr);
+            if (tmp < 0) {
+                return -1;
+            }
+
+            month *= 10;
+            month += (uint8_t)tmp;
+            ptr++;
+        }
+
+        uint8_t *values[2] = {&week, &day};
+        for (size_t i = 0; i < 2; ++i) {
+            if (*ptr != '.') {
+                return -1;
+            }
+            ptr++;
+
+            tmp = parse_uint(ptr);
+            if (tmp < 0) {
+                return -1;
+            }
+            ptr++;
+
+            *(values[i]) = tmp;
+        }
+
+        if (*ptr == '/') {
+            ptr++;
+            ssize_t num_chars =
+                parse_transition_time(ptr, &hour, &minute, &second);
+            if (num_chars < 0) {
+                return -1;
+            }
+            ptr += num_chars;
+        }
+
+        CalendarRule *rv = PyMem_Calloc(1, sizeof(CalendarRule));
+        if (rv == NULL) {
+            return -1;
+        }
+
+        if (calendarrule_new(month, week, day, hour, minute, second, rv)) {
+            PyMem_Free(rv);
+            return -1;
+        }
+
+        *out = (TransitionRuleType *)rv;
+    }
+    else {
+        uint8_t julian = 0;
+        unsigned int day = 0;
+        if (*ptr == 'J') {
+            julian = 1;
+            ptr++;
+        }
+
+        for (size_t i = 0; i < 3; ++i) {
+            if (!isdigit(*ptr)) {
+                if (i == 0) {
+                    return -1;
+                }
+                break;
+            }
+            day *= 10;
+            day += (*ptr) - '0';
+            ptr++;
+        }
+
+        if (*ptr == '/') {
+            ptr++;
+            ssize_t num_chars =
+                parse_transition_time(ptr, &hour, &minute, &second);
+            if (num_chars < 0) {
+                return -1;
+            }
+            ptr += num_chars;
+        }
+
+        DayRule *rv = PyMem_Calloc(1, sizeof(DayRule));
+        if (rv == NULL) {
+            return -1;
+        }
+
+        if (dayrule_new(julian, day, hour, minute, second, rv)) {
+            PyMem_Free(rv);
+            return -1;
+        }
+        *out = (TransitionRuleType *)rv;
+    }
+
+    return ptr - p;
+}
+
+/* Parse the time portion of a transition rule (e.g. following an /) */
+static ssize_t
+parse_transition_time(const char *const p, int8_t *hour, int8_t *minute,
+                      int8_t *second)
+{
+    // From the spec:
+    //
+    //   The time has the same format as offset except that no leading sign
+    //   ( '-' or '+' ) is allowed.
+    //
+    // The format for the offset is:
+    //
+    //   h[h][:mm[:ss]]
+    //
+    // RFC 8536 also allows transition times to be signed and to range from
+    // -167 to +167, but the current version only supports [0, 99].
+    //
+    // TODO: Support the full range of transition hours.
+    int8_t *components[3] = {hour, minute, second};
+    const char *ptr = p;
+    int8_t sign = 1;
+
+    if (*ptr == '-' || *ptr == '+') {
+        if (*ptr == '-') {
+            sign = -1;
+        }
+        ptr++;
+    }
+
+    for (size_t i = 0; i < 3; ++i) {
+        if (i > 0) {
+            if (*ptr != ':') {
+                break;
+            }
+            ptr++;
+        }
+
+        uint8_t buff = 0;
+        for (size_t j = 0; j < 2; j++) {
+            if (!isdigit(*ptr)) {
+                if (i == 0 && j > 0) {
+                    break;
+                }
+                return -1;
+            }
+
+            buff *= 10;
+            buff += (*ptr) - '0';
+            ptr++;
+        }
+
+        *(components[i]) = sign * buff;
+    }
+
+    return ptr - p;
+}
+
+/* Constructor for a _tzrule.
+ *
+ * If `dst_abbr` is NULL, this will construct an "STD-only" _tzrule, in which
+ * case `dst_offset` will be ignored and `start` and `end` are expected to be
+ * NULL as well.
+ *
+ * Returns 0 on success.
+ */
+static int
+build_tzrule(PyObject *std_abbr, PyObject *dst_abbr, long std_offset,
+             long dst_offset, TransitionRuleType *start,
+             TransitionRuleType *end, _tzrule *out)
+{
+    _tzrule rv = {0};
+
+    rv.start = start;
+    rv.end = end;
+
+    if (build_ttinfo(std_offset, 0, std_abbr, &rv.std)) {
+        goto error;
+    }
+
+    if (dst_abbr != NULL) {
+        rv.dst_diff = dst_offset - std_offset;
+        if (build_ttinfo(dst_offset, rv.dst_diff, dst_abbr, &rv.dst)) {
+            goto error;
+        }
+    }
+    else {
+        rv.std_only = 1;
+    }
+
+    *out = rv;
+
+    return 0;
+error:
+    xdecref_ttinfo(&rv.std);
+    xdecref_ttinfo(&rv.dst);
+    return -1;
+}
+
+/* Destructor for _tzrule. */
+static void
+free_tzrule(_tzrule *tzrule)
+{
+    xdecref_ttinfo(&(tzrule->std));
+    if (!tzrule->std_only) {
+        xdecref_ttinfo(&(tzrule->dst));
+    }
+
+    if (tzrule->start != NULL) {
+        PyMem_Free(tzrule->start);
+    }
+
+    if (tzrule->end != NULL) {
+        PyMem_Free(tzrule->end);
+    }
+}
+
+/* Calculate DST offsets from transitions and UTC offsets
+ *
+ * This is necessary because each C `ttinfo` only contains the UTC offset,
+ * time zone abbreviation and an isdst boolean - it does not include the
+ * amount of the DST offset, but we need the amount for the dst() function.
+ *
+ * Thus function uses heuristics to infer what the offset should be, so it
+ * is not guaranteed that this will work for all zones. If we cannot assign
+ * a value for a given DST offset, we'll assume it's 1H rather than 0H, so
+ * bool(dt.dst()) will always match ttinfo.isdst.
+ */
+static void
+utcoff_to_dstoff(size_t *trans_idx, long *utcoffs, long *dstoffs,
+                 unsigned char *isdsts, size_t num_transitions,
+                 size_t num_ttinfos)
+{
+    size_t dst_count = 0;
+    size_t dst_found = 0;
+    for (size_t i = 0; i < num_ttinfos; ++i) {
+        dst_count++;
+    }
+
+    for (size_t i = 1; i < num_transitions; ++i) {
+        if (dst_count == dst_found) {
+            break;
+        }
+
+        size_t idx = trans_idx[i];
+        size_t comp_idx = trans_idx[i - 1];
+
+        // Only look at DST offsets that have nto been assigned already
+        if (!isdsts[idx] || dstoffs[idx] != 0) {
+            continue;
+        }
+
+        long dstoff = 0;
+        long utcoff = utcoffs[idx];
+
+        if (!isdsts[comp_idx]) {
+            dstoff = utcoff - utcoffs[comp_idx];
+        }
+
+        if (!dstoff && idx < (num_ttinfos - 1)) {
+            comp_idx = trans_idx[i + 1];
+
+            // If the following transition is also DST and we couldn't find
+            // the DST offset by this point, we're going to have to skip it
+            // and hope this transition gets assigned later
+            if (isdsts[comp_idx]) {
+                continue;
+            }
+
+            dstoff = utcoff - utcoffs[comp_idx];
+        }
+
+        if (dstoff) {
+            dst_found++;
+            dstoffs[idx] = dstoff;
+        }
+    }
+
+    if (dst_found < dst_count) {
+        // If there are time zones we didn't find a value for, we'll end up
+        // with dstoff = 0 for something where isdst=1. This is obviously
+        // wrong — one hour will be a much better guess than 0.
+        for (size_t idx = 0; idx < num_ttinfos; ++idx) {
+            if (isdsts[idx] && !dstoffs[idx]) {
+                dstoffs[idx] = 3600;
+            }
+        }
+    }
+}
+
+#define _swap(x, y, buffer) \
+    buffer = x;             \
+    x = y;                  \
+    y = buffer;
+
+/* Calculate transitions in local time from UTC time and offsets.
+ *
+ * We want to know when each transition occurs, denominated in the number of
+ * nominal wall-time seconds between 1970-01-01T00:00:00 and the transition in
+ * *local time* (note: this is *not* equivalent to the output of
+ * datetime.timestamp, which is the total number of seconds actual elapsed
+ * since 1970-01-01T00:00:00Z in UTC).
+ *
+ * This is an ambiguous question because "local time" can be ambiguous — but it
+ * is disambiguated by the `fold` parameter, so we allocate two arrays:
+ *
+ *  trans_local[0]: The wall-time transitions for fold=0
+ *  trans_local[1]: The wall-time transitions for fold=1
+ *
+ * This returns 0 on success and a negative number of failure. The trans_local
+ * arrays must be freed if they are not NULL.
+ */
+static int
+ts_to_local(size_t *trans_idx, int64_t *trans_utc, long *utcoff,
+            int64_t *trans_local[2], size_t num_ttinfos,
+            size_t num_transitions)
+{
+    if (num_transitions == 0) {
+        return 0;
+    }
+
+    // Copy the UTC transitions into each array to be modified in place later
+    for (size_t i = 0; i < 2; ++i) {
+        trans_local[i] = PyMem_Malloc(num_transitions * sizeof(int64_t));
+        if (trans_local[i] == NULL) {
+            return -1;
+        }
+
+        memcpy(trans_local[i], trans_utc, num_transitions * sizeof(int64_t));
+    }
+
+    int64_t offset_0, offset_1, buff;
+    if (num_ttinfos > 1) {
+        offset_0 = utcoff[0];
+        offset_1 = utcoff[trans_idx[0]];
+
+        if (offset_1 > offset_0) {
+            _swap(offset_0, offset_1, buff);
+        }
+    }
+    else {
+        offset_0 = utcoff[0];
+        offset_1 = utcoff[0];
+    }
+
+    trans_local[0][0] += offset_0;
+    trans_local[1][0] += offset_1;
+
+    for (size_t i = 1; i < num_transitions; ++i) {
+        offset_0 = utcoff[trans_idx[i - 1]];
+        offset_1 = utcoff[trans_idx[i]];
+
+        if (offset_1 > offset_0) {
+            _swap(offset_1, offset_0, buff);
+        }
+
+        trans_local[0][i] += offset_0;
+        trans_local[1][i] += offset_1;
+    }
+
+    return 0;
+}
+
+/* Simple bisect_right binary search implementation */
+static size_t
+_bisect(const int64_t value, const int64_t *arr, size_t size)
+{
+    size_t lo = 0;
+    size_t hi = size;
+    size_t m;
+
+    while (lo < hi) {
+        m = (lo + hi) / 2;
+        if (arr[m] > value) {
+            hi = m;
+        }
+        else {
+            lo = m + 1;
+        }
+    }
+
+    return hi;
+}
+
+/* Find the ttinfo rules that apply at a given local datetime. */
+static _ttinfo *
+find_ttinfo(PyZoneInfo_ZoneInfo *self, PyObject *dt)
+{
+    // datetime.time has a .tzinfo attribute that passes None as the dt
+    // argument; it only really has meaning for fixed-offset zones.
+    if (dt == Py_None) {
+        if (self->fixed_offset) {
+            return &(self->tzrule_after.std);
+        }
+        else {
+            return &NO_TTINFO;
+        }
+    }
+
+    int64_t ts;
+    if (get_local_timestamp(dt, &ts)) {
+        return NULL;
+    }
+
+    unsigned char fold = PyDateTime_DATE_GET_FOLD(dt);
+    assert(fold < 2);
+    int64_t *local_transitions = self->trans_list_wall[fold];
+    size_t num_trans = self->num_transitions;
+
+    if (num_trans && ts < local_transitions[0]) {
+        return self->ttinfo_before;
+    }
+    else if (!num_trans || ts > local_transitions[self->num_transitions - 1]) {
+        return find_tzrule_ttinfo(&(self->tzrule_after), ts, fold,
+                                  PyDateTime_GET_YEAR(dt));
+    }
+    else {
+        size_t idx = _bisect(ts, local_transitions, self->num_transitions) - 1;
+        assert(idx < self->num_transitions);
+        return self->trans_ttinfos[idx];
+    }
+}
+
+static int
+is_leap_year(int year)
+{
+    const unsigned int ayear = (unsigned int)year;
+    return ayear % 4 == 0 && (ayear % 100 != 0 || ayear % 400 == 0);
+}
+
+/* Calculates ordinal datetime from year, month and day. */
+static int
+ymd_to_ord(int y, int m, int d)
+{
+    y -= 1;
+    int days_before_year = (y * 365) + (y / 4) - (y / 100) + (y / 400);
+    int yearday = DAYS_BEFORE_MONTH[m];
+    if (m > 2 && is_leap_year(y + 1)) {
+        yearday += 1;
+    }
+
+    return days_before_year + yearday + d;
+}
+
+/* Calculate the number of seconds since 1970-01-01 in local time.
+ *
+ * This gets a datetime in the same "units" as self->trans_list_wall so that we
+ * can easily determine which transitions a datetime falls between. See the
+ * comment above ts_to_local for more information.
+ * */
+static int
+get_local_timestamp(PyObject *dt, int64_t *local_ts)
+{
+    assert(local_ts != NULL);
+
+    int hour, minute, second;
+    int ord;
+    if (PyDateTime_CheckExact(dt)) {
+        int y = PyDateTime_GET_YEAR(dt);
+        int m = PyDateTime_GET_MONTH(dt);
+        int d = PyDateTime_GET_DAY(dt);
+        hour = PyDateTime_DATE_GET_HOUR(dt);
+        minute = PyDateTime_DATE_GET_MINUTE(dt);
+        second = PyDateTime_DATE_GET_SECOND(dt);
+
+        ord = ymd_to_ord(y, m, d);
+    }
+    else {
+        PyObject *num = PyObject_CallMethod(dt, "toordinal", NULL);
+        if (num == NULL) {
+            return -1;
+        }
+
+        ord = PyLong_AsLong(num);
+        Py_DECREF(num);
+        if (ord == -1 && PyErr_Occurred()) {
+            return -1;
+        }
+
+        num = PyObject_GetAttrString(dt, "hour");
+        if (num == NULL) {
+            return -1;
+        }
+        hour = PyLong_AsLong(num);
+        Py_DECREF(num);
+        if (hour == -1) {
+            return -1;
+        }
+
+        num = PyObject_GetAttrString(dt, "minute");
+        if (num == NULL) {
+            return -1;
+        }
+        minute = PyLong_AsLong(num);
+        Py_DECREF(num);
+        if (minute == -1) {
+            return -1;
+        }
+
+        num = PyObject_GetAttrString(dt, "second");
+        if (num == NULL) {
+            return -1;
+        }
+        second = PyLong_AsLong(num);
+        Py_DECREF(num);
+        if (second == -1) {
+            return -1;
+        }
+    }
+
+    *local_ts = (int64_t)(ord - EPOCHORDINAL) * 86400 +
+                (int64_t)(hour * 3600 + minute * 60 + second);
+
+    return 0;
+}
+
+/////
+// Functions for cache handling
+
+/* Constructor for StrongCacheNode */
+static StrongCacheNode *
+strong_cache_node_new(PyObject *key, PyObject *zone)
+{
+    StrongCacheNode *node = PyMem_Malloc(sizeof(StrongCacheNode));
+    if (node == NULL) {
+        return NULL;
+    }
+
+    Py_INCREF(key);
+    Py_INCREF(zone);
+
+    node->next = NULL;
+    node->prev = NULL;
+    node->key = key;
+    node->zone = zone;
+
+    return node;
+}
+
+/* Destructor for StrongCacheNode */
+void
+strong_cache_node_free(StrongCacheNode *node)
+{
+    Py_XDECREF(node->key);
+    Py_XDECREF(node->zone);
+
+    PyMem_Free(node);
+}
+
+/* Frees all nodes at or after a specified root in the strong cache.
+ *
+ * This can be used on the root node to free the entire cache or it can be used
+ * to clear all nodes that have been expired (which, if everything is going
+ * right, will actually only be 1 node at a time).
+ */
+void
+strong_cache_free(StrongCacheNode *root)
+{
+    StrongCacheNode *node = root;
+    StrongCacheNode *next_node;
+    while (node != NULL) {
+        next_node = node->next;
+        strong_cache_node_free(node);
+
+        node = next_node;
+    }
+}
+
+/* Removes a node from the cache and update its neighbors.
+ *
+ * This is used both when ejecting a node from the cache and when moving it to
+ * the front of the cache.
+ */
+static void
+remove_from_strong_cache(StrongCacheNode *node)
+{
+    if (ZONEINFO_STRONG_CACHE == node) {
+        ZONEINFO_STRONG_CACHE = node->next;
+    }
+
+    if (node->prev != NULL) {
+        node->prev->next = node->next;
+    }
+
+    if (node->next != NULL) {
+        node->next->prev = node->prev;
+    }
+
+    node->next = NULL;
+    node->prev = NULL;
+}
+
+/* Retrieves the node associated with a key, if it exists.
+ *
+ * This traverses the strong cache until it finds a matching key and returns a
+ * pointer to the relevant node if found. Returns NULL if no node is found.
+ *
+ * root may be NULL, indicating an empty cache.
+ */
+static StrongCacheNode *
+find_in_strong_cache(const StrongCacheNode *const root, PyObject *const key)
+{
+    const StrongCacheNode *node = root;
+    while (node != NULL) {
+        if (PyObject_RichCompareBool(key, node->key, Py_EQ)) {
+            return (StrongCacheNode *)node;
+        }
+
+        node = node->next;
+    }
+
+    return NULL;
+}
+
+/* Ejects a given key from the class's strong cache, if applicable.
+ *
+ * This function is used to enable the per-key functionality in clear_cache.
+ */
+static void
+eject_from_strong_cache(const PyTypeObject *const type, PyObject *key)
+{
+    if (type != &PyZoneInfo_ZoneInfoType) {
+        return;
+    }
+
+    StrongCacheNode *node = find_in_strong_cache(ZONEINFO_STRONG_CACHE, key);
+    if (node != NULL) {
+        remove_from_strong_cache(node);
+
+        strong_cache_node_free(node);
+    }
+}
+
+/* Moves a node to the front of the LRU cache.
+ *
+ * The strong cache is an LRU cache, so whenever a given node is accessed, if
+ * it is not at the front of the cache, it needs to be moved there.
+ */
+static void
+move_strong_cache_node_to_front(StrongCacheNode **root, StrongCacheNode *node)
+{
+    StrongCacheNode *root_p = *root;
+    if (root_p == node) {
+        return;
+    }
+
+    remove_from_strong_cache(node);
+
+    node->prev = NULL;
+    node->next = root_p;
+
+    if (root_p != NULL) {
+        root_p->prev = node;
+    }
+
+    *root = node;
+}
+
+/* Retrieves a ZoneInfo from the strong cache if it's present.
+ *
+ * This function finds the ZoneInfo by key and if found will move the node to
+ * the front of the LRU cache and return a new reference to it. It returns NULL
+ * if the key is not in the cache.
+ *
+ * The strong cache is currently only implemented for the base class, so this
+ * always returns a cache miss for subclasses.
+ */
+static PyObject *
+zone_from_strong_cache(const PyTypeObject *const type, PyObject *const key)
+{
+    if (type != &PyZoneInfo_ZoneInfoType) {
+        return NULL;  // Strong cache currently only implemented for base class
+    }
+
+    StrongCacheNode *node = find_in_strong_cache(ZONEINFO_STRONG_CACHE, key);
+
+    if (node != NULL) {
+        move_strong_cache_node_to_front(&ZONEINFO_STRONG_CACHE, node);
+        Py_INCREF(node->zone);
+        return node->zone;
+    }
+
+    return NULL;  // Cache miss
+}
+
+/* Inserts a new key into the strong LRU cache.
+ *
+ * This function is only to be used after a cache miss — it creates a new node
+ * at the front of the cache and ejects any stale entries (keeping the size of
+ * the cache to at most ZONEINFO_STRONG_CACHE_MAX_SIZE).
+ */
+static void
+update_strong_cache(const PyTypeObject *const type, PyObject *key,
+                    PyObject *zone)
+{
+    if (type != &PyZoneInfo_ZoneInfoType) {
+        return;
+    }
+
+    StrongCacheNode *new_node = strong_cache_node_new(key, zone);
+
+    move_strong_cache_node_to_front(&ZONEINFO_STRONG_CACHE, new_node);
+
+    StrongCacheNode *node = new_node->next;
+    for (size_t i = 1; i < ZONEINFO_STRONG_CACHE_MAX_SIZE; ++i) {
+        if (node == NULL) {
+            return;
+        }
+        node = node->next;
+    }
+
+    // Everything beyond this point needs to be freed
+    if (node != NULL) {
+        if (node->prev != NULL) {
+            node->prev->next = NULL;
+        }
+        strong_cache_free(node);
+    }
+}
+
+/* Clears all entries into a type's strong cache.
+ *
+ * Because the strong cache is not implemented for subclasses, this is a no-op
+ * for everything except the base class.
+ */
+void
+clear_strong_cache(const PyTypeObject *const type)
+{
+    if (type != &PyZoneInfo_ZoneInfoType) {
+        return;
+    }
+
+    strong_cache_free(ZONEINFO_STRONG_CACHE);
+}
+
+static PyObject *
+new_weak_cache()
+{
+    PyObject *weakref_module = PyImport_ImportModule("weakref");
+    if (weakref_module == NULL) {
+        return NULL;
+    }
+
+    PyObject *weak_cache =
+        PyObject_CallMethod(weakref_module, "WeakValueDictionary", "");
+    Py_DECREF(weakref_module);
+    return weak_cache;
+}
+
+static int
+initialize_caches()
+{
+    if (TIMEDELTA_CACHE == NULL) {
+        TIMEDELTA_CACHE = PyDict_New();
+    }
+    else {
+        Py_INCREF(TIMEDELTA_CACHE);
+    }
+
+    if (TIMEDELTA_CACHE == NULL) {
+        return -1;
+    }
+
+    if (ZONEINFO_WEAK_CACHE == NULL) {
+        ZONEINFO_WEAK_CACHE = new_weak_cache();
+    }
+    else {
+        Py_INCREF(ZONEINFO_WEAK_CACHE);
+    }
+
+    if (ZONEINFO_WEAK_CACHE == NULL) {
+        return -1;
+    }
+
+    return 0;
+}
+
+static PyObject *
+zoneinfo_init_subclass(PyTypeObject *cls, PyObject *args, PyObject **kwargs)
+{
+    PyObject *weak_cache = new_weak_cache();
+    if (weak_cache == NULL) {
+        return NULL;
+    }
+
+    PyObject_SetAttrString((PyObject *)cls, "_weak_cache", weak_cache);
+    Py_RETURN_NONE;
+}
+
+/////
+// Specify the ZoneInfo type
+static PyMethodDef zoneinfo_methods[] = {
+    {"clear_cache", (PyCFunction)(void (*)(void))zoneinfo_clear_cache,
+     METH_VARARGS | METH_KEYWORDS | METH_CLASS,
+     PyDoc_STR("Clear the ZoneInfo cache.")},
+    {"no_cache", (PyCFunction)(void (*)(void))zoneinfo_no_cache,
+     METH_VARARGS | METH_KEYWORDS | METH_CLASS,
+     PyDoc_STR("Get a new instance of ZoneInfo, bypassing the cache.")},
+    {"from_file", (PyCFunction)(void (*)(void))zoneinfo_from_file,
+     METH_VARARGS | METH_KEYWORDS | METH_CLASS,
+     PyDoc_STR("Create a ZoneInfo file from a file object.")},
+    {"utcoffset", (PyCFunction)zoneinfo_utcoffset, METH_O,
+     PyDoc_STR("Retrieve a timedelta representing the UTC offset in a zone at "
+               "the given datetime.")},
+    {"dst", (PyCFunction)zoneinfo_dst, METH_O,
+     PyDoc_STR("Retrieve a timedelta representing the amount of DST applied "
+               "in a zone at the given datetime.")},
+    {"tzname", (PyCFunction)zoneinfo_tzname, METH_O,
+     PyDoc_STR("Retrieve a string containing the abbreviation for the time "
+               "zone that applies in a zone at a given datetime.")},
+    {"fromutc", (PyCFunction)zoneinfo_fromutc, METH_O,
+     PyDoc_STR("Given a datetime with local time in UTC, retrieve an adjusted "
+               "datetime in local time.")},
+    {"__reduce__", (PyCFunction)zoneinfo_reduce, METH_NOARGS,
+     PyDoc_STR("Function for serialization with the pickle protocol.")},
+    {"_unpickle", (PyCFunction)zoneinfo__unpickle, METH_VARARGS | METH_CLASS,
+     PyDoc_STR("Private method used in unpickling.")},
+    {"__init_subclass__", (PyCFunction)(void (*)(void))zoneinfo_init_subclass,
+     METH_VARARGS | METH_KEYWORDS,
+     PyDoc_STR("Function to initialize subclasses.")},
+    {NULL} /* Sentinel */
+};
+
+static PyMemberDef zoneinfo_members[] = {
+    {.name = "key",
+     .offset = offsetof(PyZoneInfo_ZoneInfo, key),
+     .type = T_OBJECT_EX,
+     .flags = READONLY,
+     .doc = NULL},
+    {NULL}, /* Sentinel */
+};
+
+static PyTypeObject PyZoneInfo_ZoneInfoType = {
+    PyVarObject_HEAD_INIT(NULL, 0)  //
+        .tp_name = "zoneinfo.ZoneInfo",
+    .tp_basicsize = sizeof(PyZoneInfo_ZoneInfo),
+    .tp_weaklistoffset = offsetof(PyZoneInfo_ZoneInfo, weakreflist),
+    .tp_repr = (reprfunc)zoneinfo_repr,
+    .tp_str = (reprfunc)zoneinfo_str,
+    .tp_getattro = PyObject_GenericGetAttr,
+    .tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE),
+    /* .tp_doc = zoneinfo_doc, */
+    .tp_methods = zoneinfo_methods,
+    .tp_members = zoneinfo_members,
+    .tp_new = zoneinfo_new,
+    .tp_dealloc = zoneinfo_dealloc,
+};
+
+/////
+// Specify the _zoneinfo module
+static PyMethodDef module_methods[] = {{NULL, NULL}};
+static void
+module_free()
+{
+    Py_XDECREF(_tzpath_find_tzfile);
+    _tzpath_find_tzfile = NULL;
+
+    Py_XDECREF(_common_mod);
+    _common_mod = NULL;
+
+    Py_XDECREF(io_open);
+    io_open = NULL;
+
+    xdecref_ttinfo(&NO_TTINFO);
+
+    Py_XDECREF(TIMEDELTA_CACHE);
+    if (!Py_REFCNT(TIMEDELTA_CACHE)) {
+        TIMEDELTA_CACHE = NULL;
+    }
+
+    Py_XDECREF(ZONEINFO_WEAK_CACHE);
+    if (!Py_REFCNT(ZONEINFO_WEAK_CACHE)) {
+        ZONEINFO_WEAK_CACHE = NULL;
+    }
+
+    strong_cache_free(ZONEINFO_STRONG_CACHE);
+    ZONEINFO_STRONG_CACHE = NULL;
+}
+
+static int
+zoneinfomodule_exec(PyObject *m)
+{
+    PyDateTime_IMPORT;
+    PyZoneInfo_ZoneInfoType.tp_base = PyDateTimeAPI->TZInfoType;
+    if (PyType_Ready(&PyZoneInfo_ZoneInfoType) < 0) {
+        goto error;
+    }
+
+    Py_INCREF(&PyZoneInfo_ZoneInfoType);
+    PyModule_AddObject(m, "ZoneInfo", (PyObject *)&PyZoneInfo_ZoneInfoType);
+
+    /* Populate imports */
+    PyObject *_tzpath_module = PyImport_ImportModule("zoneinfo._tzpath");
+    if (_tzpath_module == NULL) {
+        goto error;
+    }
+
+    _tzpath_find_tzfile =
+        PyObject_GetAttrString(_tzpath_module, "find_tzfile");
+    Py_DECREF(_tzpath_module);
+    if (_tzpath_find_tzfile == NULL) {
+        goto error;
+    }
+
+    PyObject *io_module = PyImport_ImportModule("io");
+    if (io_module == NULL) {
+        goto error;
+    }
+
+    io_open = PyObject_GetAttrString(io_module, "open");
+    Py_DECREF(io_module);
+    if (io_open == NULL) {
+        goto error;
+    }
+
+    _common_mod = PyImport_ImportModule("zoneinfo._common");
+    if (_common_mod == NULL) {
+        goto error;
+    }
+
+    if (NO_TTINFO.utcoff == NULL) {
+        NO_TTINFO.utcoff = Py_None;
+        NO_TTINFO.dstoff = Py_None;
+        NO_TTINFO.tzname = Py_None;
+
+        for (size_t i = 0; i < 3; ++i) {
+            Py_INCREF(Py_None);
+        }
+    }
+
+    if (initialize_caches()) {
+        goto error;
+    }
+
+    return 0;
+
+error:
+    return -1;
+}
+
+static PyModuleDef_Slot zoneinfomodule_slots[] = {
+    {Py_mod_exec, zoneinfomodule_exec}, {0, NULL}};
+
+static struct PyModuleDef zoneinfomodule = {
+    PyModuleDef_HEAD_INIT,
+    .m_name = "_zoneinfo",
+    .m_doc = "C implementation of the zoneinfo module",
+    .m_size = 0,
+    .m_methods = module_methods,
+    .m_slots = zoneinfomodule_slots,
+    .m_free = (freefunc)module_free};
+
+PyMODINIT_FUNC
+PyInit__zoneinfo(void)
+{
+    return PyModuleDef_Init(&zoneinfomodule);
+}
diff --git a/configure b/configure
index 64bcde6bfdf..56d66d02352 100755
--- a/configure
+++ b/configure
@@ -658,6 +658,7 @@ LIBFFI_INCLUDEDIR
 PKG_CONFIG_LIBDIR
 PKG_CONFIG_PATH
 PKG_CONFIG
+TZPATH
 SHLIBS
 CFLAGSFORSHARED
 LINKFORSHARED
@@ -819,6 +820,7 @@ with_assertions
 enable_optimizations
 with_lto
 with_hash_algorithm
+with_tzpath
 with_address_sanitizer
 with_memory_sanitizer
 with_undefined_behavior_sanitizer
@@ -1525,6 +1527,9 @@ Optional Packages:
   --with-hash-algorithm=[fnv|siphash24]
                           select hash algorithm for use in Python/pyhash.c
                           (default is SipHash24)
+  --with-tzpath=<list of absolute paths separated by pathsep>
+                           Select the default time zone search path for zoneinfo.TZPATH
+
   --with-address-sanitizer
                           enable AddressSanitizer memory error detector,
                           'asan' (default is no)
@@ -10154,6 +10159,47 @@ $as_echo "default" >&6; }
 fi
 
 
+validate_tzpath() {
+    # Checks that each element of hte path is an absolute path
+    if test -z "$1"; then
+        # Empty string is allowed: it indicates no system TZPATH
+        return 0
+    fi
+
+    # Bad paths are those that don't start with /
+        if ( echo $1 | grep -qE '(^|:)([^/]|$)' ); then
+        as_fn_error $? "--with-tzpath must contain only absolute paths, not $1" "$LINENO" 5
+        return 1;
+    fi
+}
+
+TZPATH="/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-tzpath" >&5
+$as_echo_n "checking for --with-tzpath... " >&6; }
+
+# Check whether --with-tzpath was given.
+if test "${with_tzpath+set}" = set; then :
+  withval=$with_tzpath;
+case "$withval" in
+    yes)
+        as_fn_error $? "--with-tzpath requires a value" "$LINENO" 5
+        ;;
+    *)
+        validate_tzpath "$withval"
+        TZPATH="$withval"
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: \"$withval\"" >&5
+$as_echo "\"$withval\"" >&6; }
+        ;;
+esac
+
+else
+  validate_tzpath "$TZPATH"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: \"$TZPATH\"" >&5
+$as_echo "\"$TZPATH\"" >&6; }
+fi
+
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-address-sanitizer" >&5
 $as_echo_n "checking for --with-address-sanitizer... " >&6; }
 
diff --git a/configure.ac b/configure.ac
index 21c47b56358..497d7c191d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2946,6 +2946,42 @@ esac
 ],
 [AC_MSG_RESULT(default)])
 
+validate_tzpath() {
+    # Checks that each element of hte path is an absolute path
+    if test -z "$1"; then
+        # Empty string is allowed: it indicates no system TZPATH
+        return 0
+    fi
+
+    # Bad paths are those that don't start with /
+    dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
+    if ( echo $1 | grep -qE '(^|:)(@<:@^/@:>@|$)' ); then
+        AC_MSG_ERROR([--with-tzpath must contain only absolute paths, not $1])
+        return 1;
+    fi
+}
+
+TZPATH="/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo"
+AC_MSG_CHECKING(for --with-tzpath)
+AC_ARG_WITH(tzpath,
+            AS_HELP_STRING([--with-tzpath=<list of absolute paths separated by pathsep>]
+                           [Select the default time zone search path for zoneinfo.TZPATH]),
+[
+case "$withval" in
+    yes)
+        AC_MSG_ERROR([--with-tzpath requires a value])
+        ;;
+    *)
+        validate_tzpath "$withval"
+        TZPATH="$withval"
+        AC_MSG_RESULT("$withval")
+        ;;
+esac
+],
+[validate_tzpath "$TZPATH"
+ AC_MSG_RESULT("$TZPATH")])
+AC_SUBST(TZPATH)
+
 AC_MSG_CHECKING(for --with-address-sanitizer)
 AC_ARG_WITH(address_sanitizer,
             AS_HELP_STRING([--with-address-sanitizer],
diff --git a/setup.py b/setup.py
index 794ba2f7662..68fc3120cc3 100644
--- a/setup.py
+++ b/setup.py
@@ -304,6 +304,17 @@ def find_library_file(compiler, libname, std_dirs, paths):
     else:
         assert False, "Internal error: Path not found in std_dirs or paths"
 
+def validate_tzpath():
+    base_tzpath = sysconfig.get_config_var('TZPATH')
+    if not base_tzpath:
+        return
+
+    tzpaths = base_tzpath.split(os.pathsep)
+    bad_paths = [tzpath for tzpath in tzpaths if not os.path.isabs(tzpath)]
+    if bad_paths:
+        raise ValueError('TZPATH must contain only absolute paths, '
+                         + f'found:\n{tzpaths!r}\nwith invalid paths:\n'
+                         + f'{bad_paths!r}')
 
 def find_module_file(module, dirlist):
     """Find a module in a set of possible folders. If it is not found
@@ -816,6 +827,8 @@ class PyBuildExt(build_ext):
         # uses modf().
         self.add(Extension('_datetime', ['_datetimemodule.c'],
                            libraries=['m']))
+        # zoneinfo module
+        self.add(Extension('_zoneinfo', ['_zoneinfo.c'])),
         # random number generator implemented in C
         self.add(Extension("_random", ["_randommodule.c"],
                            extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
@@ -2495,6 +2508,7 @@ def main():
         ProcessPoolExecutor = None
 
     sys.modules['concurrent.futures.process'] = DummyProcess
+    validate_tzpath()
 
     # turn off warnings when deprecated modules are imported
     import warnings