Repository: ultrabug/py3status

Issue:
clock.py:269: PytzUsageWarning: The zone attribute is specific to pytz's interface
**Describe the bug**
clock.py:269: PytzUsageWarning: The zone attribute is specific to pytz's interface; please migrate to a new time zone provider. For more details on how to do so, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html

**Your py3status version**
py3status version 3.47 (python 3.8.10) on i3
Ubuntu 20.04

**To Reproduce**
Steps to reproduce the behavior along with your py3status configuration (filter out any private values):
1. Run clock.py module inside of terminal emulator.

**Expected behavior**
No warning shown.



Discussion:

Resolving patch:
diff --git a/py3status/modules/clock.py b/py3status/modules/clock.py
--- a/py3status/modules/clock.py
+++ b/py3status/modules/clock.py
@@ -6,12 +6,11 @@
 Timezones are defined in the `format` using the TZ name in squiggly brackets eg
 `{GMT}`, `{Portugal}`, `{Europe/Paris}`, `{America/Argentina/Buenos_Aires}`.
 
-ISO-3166 two letter country codes eg `{de}` can also be used but if more than
-one timezone exists for the country eg `{us}` the first one will be selected.
+See https://docs.python.org/3/library/zoneinfo.html for supported formats.
 
 `{Local}` can be used for the local settings of your computer.
 
-Note: Timezones are case sensitive
+Note: Timezones are case sensitive!
 
 A full list of timezones can be found at
 https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
@@ -54,10 +53,6 @@
     {timezone_unclear} full timezone name eg `America/Argentina/Buenos_Aires`
         but is empty if only one timezone is provided
 
-Requires:
-    pytz: cross platform time zone library for python
-    tzlocal: tzinfo object for the local timezone
-
 Examples:
 ```
 # cycling through London, Warsaw, Tokyo
@@ -80,7 +75,7 @@
 }
 ```
 
-@author tobes
+@author tobes ultrabug
 @license BSD
 
 SAMPLE OUTPUT
@@ -95,8 +90,11 @@
 import time
 from datetime import datetime
 
-import pytz
-import tzlocal
+try:
+    import zoneinfo
+# Fall back for python 3.7 and python 3.8
+except ImportError:
+    from backports import zoneinfo
 
 CLOCK_BLOCKS = "🕛🕧🕐🕜🕑🕝🕒🕞🕓🕟🕔🕠🕕🕡🕖🕢🕗🕣🕘🕤🕙🕥🕚🕦"
 
@@ -192,24 +190,13 @@ def _get_timezone(self, tz):
         # special Local timezone
         if tz == "Local":
             try:
-                return tzlocal.get_localzone()
-            except pytz.UnknownTimeZoneError:
+                return zoneinfo.ZoneInfo("localtime")
+            except zoneinfo.ZoneInfoNotFoundError:
                 return "?"
-
-        # we can use a country code to get tz
-        # FIXME this is broken for multi-timezone countries eg US
-        # for now we just grab the first one
-        if len(tz) == 2:
-            try:
-                zones = pytz.country_timezones(tz)
-            except KeyError:
-                return "?"
-            tz = zones[0]
-
         # get the timezone
         try:
-            zone = pytz.timezone(tz)
-        except pytz.UnknownTimeZoneError:
+            zone = zoneinfo.ZoneInfo(tz)
+        except zoneinfo.ZoneInfoNotFoundError:
             return "?"
         return zone
 
@@ -264,12 +251,7 @@ def clock(self):
                     idx = int(h / self.block_hours * len(self.blocks))
                     icon = self.blocks[idx]
 
-                try:
-                    # tzlocal < 3.0
-                    timezone = zone.zone
-                except AttributeError:
-                    # tzlocal >= 3.0
-                    timezone = zone.key
+                timezone = zone.key
                 tzname = timezone.split("/")[-1].replace("_", " ")
 
                 if self.multiple_tz:


Test patch: