diff --git a/plugins/Geography/plugin.py b/plugins/Geography/plugin.py index 95c66acaa..44404705b 100644 --- a/plugins/Geography/plugin.py +++ b/plugins/Geography/plugin.py @@ -29,6 +29,7 @@ ### import datetime +import re from supybot import conf, utils, plugins, ircutils, callbacks from supybot.commands import * @@ -133,15 +134,22 @@ class Geography(callbacks.Plugin): if timezone is None: continue + offset = str(datetime.datetime.now(tz=timezone).utcoffset()) + if not offset.startswith("-"): + offset = "+" + offset + + # hide seconds and minutes if they are zero + offset = re.sub("(:00)+$", "", offset) + # Extract a human-friendly name, depending on the type of # the timezone object: if hasattr(timezone, "key"): # instance of zoneinfo.ZoneInfo - irc.reply(timezone.key) + irc.reply(format("%s (currently UTC%s)", timezone.key, offset)) return elif hasattr(timezone, "zone"): # instance of pytz.timezone - irc.reply(timezone.zone) + irc.reply(format("%s (currently UTC%s)", timezone.zone, offset)) return else: # probably datetime.timezone built from a constant offset diff --git a/plugins/Geography/test.py b/plugins/Geography/test.py index 7cbb7a77b..89399e1b3 100644 --- a/plugins/Geography/test.py +++ b/plugins/Geography/test.py @@ -70,7 +70,9 @@ class GeographyTimezoneTestCase(PluginTestCase): tz = pytz.timezone("Europe/Paris") with patch.object(wikidata, "timezone_from_uri", return_value=tz): - self.assertResponse("timezone Foo Bar", "Europe/Paris") + self.assertRegexp( + "timezone Foo Bar", r"Europe/Paris \(currently UTC\+[12]\)" + ) @skipIf(not zoneinfo, "Python is older than 3.9") @mock @@ -78,7 +80,9 @@ class GeographyTimezoneTestCase(PluginTestCase): tz = zoneinfo.ZoneInfo("Europe/Paris") with patch.object(wikidata, "timezone_from_uri", return_value=tz): - self.assertResponse("timezone Foo Bar", "Europe/Paris") + self.assertRegexp( + "timezone Foo Bar", r"Europe/Paris \(currently UTC\+[12]\)" + ) @skipIf(not zoneinfo, "Python is older than 3.9") @mock @@ -95,7 +99,9 @@ class GeographyTimezoneTestCase(PluginTestCase): @skipIf(not network, "Network test") def testTimezoneIntegration(self): - self.assertResponse("timezone Metz, France", "Europe/Paris") + self.assertRegexp( + "timezone Metz, France", r"Europe/Paris \(currently UTC\+[12]\)" + ) self.assertResponse("timezone Saint-Denis, La RĂ©union", "UTC+04:00") @@ -173,7 +179,7 @@ class GeographyWikidataTestCase(SupyTestCase): @skipIf(not network, "Network test") def testParentAndIgnoreSelf(self): # The queried object has a TZ property, but it's useless to us; - # however it is part of an object that has a useful one.""" + # however it is part of an object that has a useful one. self.assertEqual( # New York City, NY wikidata.timezone_from_uri("http://www.wikidata.org/entity/Q60"),