mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-03-29 10:56:57 +01:00
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
This commit is contained in:
parent
a178e4a3d0
commit
a1d949c861
@ -63,6 +63,11 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
tzlocal = None
|
tzlocal = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
import pytz
|
||||||
|
except ImportError:
|
||||||
|
pytz = None
|
||||||
|
|
||||||
class Time(callbacks.Plugin):
|
class Time(callbacks.Plugin):
|
||||||
"""This plugin allows you to use different time-related functions."""
|
"""This plugin allows you to use different time-related functions."""
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
@ -190,20 +195,17 @@ class Time(callbacks.Plugin):
|
|||||||
def tztime(self, irc, msg, args, timezone):
|
def tztime(self, irc, msg, args, timezone):
|
||||||
"""<region>/<city>
|
"""<region>/<city>
|
||||||
|
|
||||||
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."""
|
command uses the IANA Time Zone Database."""
|
||||||
try:
|
if pytz is None:
|
||||||
import pytz
|
|
||||||
except ImportError:
|
|
||||||
irc.error(_('Python-tz is required by the command, but is not '
|
irc.error(_('Python-tz is required by the command, but is not '
|
||||||
'installed on this computer.'))
|
'installed on this computer.'), Raise=True)
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
timezone = pytz.timezone(timezone)
|
timezone = pytz.timezone(timezone)
|
||||||
except pytz.UnknownTimeZoneError:
|
except pytz.UnknownTimeZoneError:
|
||||||
irc.error(_('Unknown timezone'))
|
irc.error(_('Unknown timezone'), Raise=True)
|
||||||
return
|
format = self.registryValue("format", msg.args[0])
|
||||||
irc.reply(datetime.now(timezone).strftime('%F %T%z'))
|
irc.reply(datetime.now(timezone).strftime(format))
|
||||||
tztime = wrap(tztime, ['text'])
|
tztime = wrap(tztime, ['text'])
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user