From 89411f2ef890a41b70eb91c0659ce816231a8c6a Mon Sep 17 00:00:00 2001 From: Ben Armstrong Date: Sun, 10 Oct 2021 18:56:00 -0300 Subject: [PATCH] [Timezone] Output "same" when time zones match. (#250) * [timezone] Output "same" when time zones match. * Semantic changes * Make time_diff_text not rely on rstrip as `0.0` was returning an empty string * Don't compare `time_diff` (a float) to ints in `plural` and `position_text`, use time_diff_text's string content and compare to strings * Version number Co-authored-by: aikaterna <20862007+aikaterna@users.noreply.github.com> --- timezone/timezone.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/timezone/timezone.py b/timezone/timezone.py index a31658d..8bec8eb 100644 --- a/timezone/timezone.py +++ b/timezone/timezone.py @@ -8,7 +8,7 @@ from redbot.core.utils.chat_formatting import pagify from redbot.core.utils.menus import close_menu, menu, DEFAULT_CONTROLS -__version__ = "2.1.0" +__version__ = "2.1.1" class Timezone(commands.Cog): @@ -199,13 +199,14 @@ class Timezone(commands.Cog): user_diff = user_now.utcoffset().total_seconds() / 60 / 60 other_now = datetime.now(other_tz) other_diff = other_now.utcoffset().total_seconds() / 60 / 60 - time_diff = str(abs(user_diff - other_diff)).rstrip(".0") + time_diff = abs(user_diff - other_diff) + time_diff_text = f"{time_diff:g}" fmt = "**%H:%M %Z (UTC %z)**" other_time = other_now.strftime(fmt) - plural = "" if time_diff == 1 else "s" - time_amt = "the same time zone as you" if time_diff == 0 else f"{time_diff} hour{plural}" + plural = "" if time_diff_text == "1" else "s" + time_amt = "the same time zone as you" if time_diff_text == "0" else f"{time_diff_text} hour{plural}" position = "ahead of" if user_diff < other_diff else "behind" - position_text = "" if time_diff == 0 else f" {position} you" + position_text = "" if time_diff_text == "0" else f" {position} you" await ctx.send(f"{user.display_name}'s time is {other_time} which is {time_amt}{position_text}.")