From a1d949c861bf56a071e5392cc7bf37c798e8afd6 Mon Sep 17 00:00:00 2001 From: GLolol Date: Wed, 31 Dec 2014 23:49:25 -0500 Subject: [PATCH 1/3] Time: improvements to 'tztime' - Import pytz on load, not every time the command is called - Respect plugins.time.format - Use irc.error(e, Raise=True) instead of return --- plugins/Time/plugin.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/Time/plugin.py b/plugins/Time/plugin.py index 8ba323c7a..974dd7295 100644 --- a/plugins/Time/plugin.py +++ b/plugins/Time/plugin.py @@ -63,6 +63,11 @@ try: except ImportError: tzlocal = None +try: + import pytz +except ImportError: + pytz = None + class Time(callbacks.Plugin): """This plugin allows you to use different time-related functions.""" @internationalizeDocstring @@ -190,20 +195,17 @@ class Time(callbacks.Plugin): def tztime(self, irc, msg, args, timezone): """/ - Takes a city and its region, and returns the locale time. This + Takes a city and its region, and returns its local time. This command uses the IANA Time Zone Database.""" - try: - import pytz - except ImportError: + if pytz is None: irc.error(_('Python-tz is required by the command, but is not ' - 'installed on this computer.')) - return + 'installed on this computer.'), Raise=True) try: timezone = pytz.timezone(timezone) except pytz.UnknownTimeZoneError: - irc.error(_('Unknown timezone')) - return - irc.reply(datetime.now(timezone).strftime('%F %T%z')) + irc.error(_('Unknown timezone'), Raise=True) + format = self.registryValue("format", msg.args[0]) + irc.reply(datetime.now(timezone).strftime(format)) tztime = wrap(tztime, ['text']) From cc2780b78a39230cafcf1c3b397c79831fde8153 Mon Sep 17 00:00:00 2001 From: GLolol Date: Thu, 1 Jan 2015 00:00:25 -0500 Subject: [PATCH 2/3] Time.time: simply channel-handling code for getting formats --- plugins/Time/plugin.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/plugins/Time/plugin.py b/plugins/Time/plugin.py index 974dd7295..4509f5085 100644 --- a/plugins/Time/plugin.py +++ b/plugins/Time/plugin.py @@ -159,7 +159,7 @@ class Time(callbacks.Plugin): TIME.time)]) @internationalizeDocstring - def time(self, irc, msg, args, channel, format, seconds): + def time(self, irc, msg, args, format, seconds): """[] [] Returns the current time in format, or, if is not @@ -167,10 +167,7 @@ class Time(callbacks.Plugin): time is given, the current time is used. """ if not format: - if channel: - format = self.registryValue('format', channel) - else: - format = self.registryValue('format') + format = self.registryValue('format', msg.args[0]) if tzlocal: irc.reply(datetime.fromtimestamp(seconds, tzlocal()).strftime(format)) else: @@ -178,8 +175,7 @@ class Time(callbacks.Plugin): # including at least up to 2.7.5 and 3.2.3. Install dateutil if you # can't upgrade Python. irc.reply(time.strftime(format, time.localtime(seconds))) - time = wrap(time, [optional('channel'), optional('nonInt'), - additional('float', TIME.time)]) + time = wrap(time, [optional('nonInt'), additional('float', TIME.time)]) @internationalizeDocstring def elapsed(self, irc, msg, args, seconds): From 382f46d7be57bb90bebb7ce2463ca0bd7106acb9 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 2 Jan 2015 12:22:07 -0800 Subject: [PATCH 3/3] Time.time: reintroduce ability to specify --- plugins/Time/plugin.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/Time/plugin.py b/plugins/Time/plugin.py index 4509f5085..befe6943d 100644 --- a/plugins/Time/plugin.py +++ b/plugins/Time/plugin.py @@ -159,15 +159,16 @@ class Time(callbacks.Plugin): TIME.time)]) @internationalizeDocstring - def time(self, irc, msg, args, format, seconds): - """[] [] + def time(self, irc, msg, args, channel, format, seconds): + """[] [] [] Returns the current time in format, or, if is not given, uses the configurable format for the current channel. If no - time is given, the current time is used. + time is given, the current time is used. If + is given without , uses the format for . """ if not format: - format = self.registryValue('format', msg.args[0]) + format = self.registryValue('format', channel or msg.args[0]) if tzlocal: irc.reply(datetime.fromtimestamp(seconds, tzlocal()).strftime(format)) else: @@ -175,7 +176,8 @@ class Time(callbacks.Plugin): # including at least up to 2.7.5 and 3.2.3. Install dateutil if you # can't upgrade Python. irc.reply(time.strftime(format, time.localtime(seconds))) - time = wrap(time, [optional('nonInt'), additional('float', TIME.time)]) + time = wrap(time, [optional('channel'), optional('nonInt'), + additional('float', TIME.time)]) @internationalizeDocstring def elapsed(self, irc, msg, args, seconds):