Import Time plugin from Supybot-plugin repo

This commit is contained in:
Valentin Lorentz 2011-01-22 09:54:53 +01:00
parent a1f093defc
commit d29ca0a227
5 changed files with 88 additions and 20 deletions

View File

@ -42,7 +42,9 @@ __author__ = supybot.authors.jemfinch
# This is a dictionary mapping supybot.Author instances to lists of # This is a dictionary mapping supybot.Author instances to lists of
# contributions. # contributions.
__contributors__ = {} __contributors__ = {'tztime': supybot.Author('Valentin Lorentz', 'ProgVal',
'progval@gmail.com')}
import config import config
import plugin import plugin

View File

@ -1,7 +1,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Supybot-fr\n" "Project-Id-Version: Supybot-fr\n"
"POT-Creation-Date: 2010-10-20 09:38+CEST\n" "POT-Creation-Date: 2010-11-17 09:46+CET\n"
"PO-Revision-Date: \n" "PO-Revision-Date: \n"
"Last-Translator: Valentin Lorentz <progval@gmail.com>\n" "Last-Translator: Valentin Lorentz <progval@gmail.com>\n"
"Language-Team: Supybot-fr <progval@gmail.com>\n" "Language-Team: Supybot-fr <progval@gmail.com>\n"
@ -21,7 +21,7 @@ msgid ""
" the empty string, the timestamp will not be shown." " the empty string, the timestamp will not be shown."
msgstr "Détermine la chaîne de format pour les timestamps. Référez-vous à la documentation du module Python time pour voir quels formats sont acceptés. Si vous définissez cette variable à une chaîne vide, le timestamp ne sera pas affiché." msgstr "Détermine la chaîne de format pour les timestamps. Référez-vous à la documentation du module Python time pour voir quels formats sont acceptés. Si vous définissez cette variable à une chaîne vide, le timestamp ne sera pas affiché."
#: plugin.py:60 #: plugin.py:61
msgid "" msgid ""
"[<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s]\n" "[<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s]\n"
"\n" "\n"
@ -36,7 +36,7 @@ msgstr ""
"\n" "\n"
"Retourne le nombre de secondes de la date donnée. Un exemple d'utilisation est \"seconds 2h 30m\", ce qui retournera 9000. Utile pour planifier des évènement à un certain nombre de secondes dans le futur." "Retourne le nombre de secondes de la date donnée. Un exemple d'utilisation est \"seconds 2h 30m\", ce qui retournera 9000. Utile pour planifier des évènement à un certain nombre de secondes dans le futur."
#: plugin.py:95 #: plugin.py:96
msgid "" msgid ""
"<time string>\n" "<time string>\n"
"\n" "\n"
@ -49,12 +49,12 @@ msgstr ""
"\n" "\n"
"Retourne le nombre de secondes depuis le <moment>. Le <moment> peut être n'importe lequel des formats naturels, essayez seulement, et voyez si ça marche." "Retourne le nombre de secondes depuis le <moment>. Le <moment> peut être n'importe lequel des formats naturels, essayez seulement, et voyez si ça marche."
#: plugin.py:106 #: plugin.py:107
#: plugin.py:122 #: plugin.py:123
msgid "That's right now!" msgid "That's right now!"
msgstr "C'est maintenant !" msgstr "C'est maintenant !"
#: plugin.py:111 #: plugin.py:112
msgid "" msgid ""
"<time string>\n" "<time string>\n"
"\n" "\n"
@ -65,7 +65,7 @@ msgstr ""
"\n" "\n"
"Retourne le nombre de secondes depuis le <moment>." "Retourne le nombre de secondes depuis le <moment>."
#: plugin.py:127 #: plugin.py:128
msgid "" msgid ""
"[<seconds since epoch>]\n" "[<seconds since epoch>]\n"
"\n" "\n"
@ -77,11 +77,11 @@ msgstr ""
"\n" "\n"
" Renvoie le ctime pour le moment il y a <temps> secondes, ou le ctime courant, si aucun <temps> n'est donné." " Renvoie le ctime pour le moment il y a <temps> secondes, ou le ctime courant, si aucun <temps> n'est donné."
#: plugin.py:133 #: plugin.py:134
msgid "number of seconds since epoch" msgid "number of seconds since epoch"
msgstr "nombre de secondes depuis une époque" msgstr "nombre de secondes depuis une époque"
#: plugin.py:138 #: plugin.py:139
msgid "" msgid ""
"[<format>] [<seconds since epoch>]\n" "[<format>] [<seconds since epoch>]\n"
"\n" "\n"
@ -94,7 +94,7 @@ msgstr ""
"\n" "\n"
"Retourne le temps courant dans le <format>, ou, si le <format> n'est pas donné, utilise le format actuellement configuré pour le canal. Si le <temps> n'est pas donné, le temps actuel est utilisé." "Retourne le temps courant dans le <format>, ou, si le <format> n'est pas donné, utilise le format actuellement configuré pour le canal. Si le <temps> n'est pas donné, le temps actuel est utilisé."
#: plugin.py:155 #: plugin.py:156
msgid "" msgid ""
"<seconds>\n" "<seconds>\n"
"\n" "\n"
@ -106,3 +106,25 @@ msgstr ""
"\n" "\n"
"Retourne le nombre de <secondes>, joliement formatté." "Retourne le nombre de <secondes>, joliement formatté."
#: plugin.py:166
msgid ""
"<region>/<city>\n"
"\n"
" Takes a city and its region, and returns the locale time."
msgstr ""
"<zone>/<ville>\n"
"\n"
"Prend en argument une ville et sa zone, et retourne le temps local."
#: plugin.py:172
msgid "Python-tz is required by the command, but is not installed on this computer."
msgstr "Python-tz est requis par la commande, mais n'est pas installé sur cet ordinateur."
#: plugin.py:175
msgid "A timezone must be in the format region/city."
msgstr "Une timezone doit être dans le format zone/ville."
#: plugin.py:179
msgid "Unknown timezone"
msgstr "Timezone inconnue"

View File

@ -5,7 +5,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2010-10-20 09:38+CEST\n" "POT-Creation-Date: 2010-11-17 09:46+CET\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -23,7 +23,7 @@ msgid ""
" the empty string, the timestamp will not be shown." " the empty string, the timestamp will not be shown."
msgstr "" msgstr ""
#: plugin.py:60 #: plugin.py:61
#, docstring #, docstring
msgid "" msgid ""
"[<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s]\n" "[<years>y] [<weeks>w] [<days>d] [<hours>h] [<minutes>m] [<seconds>s]\n"
@ -36,7 +36,7 @@ msgid ""
" " " "
msgstr "" msgstr ""
#: plugin.py:95 #: plugin.py:96
#, docstring #, docstring
msgid "" msgid ""
"<time string>\n" "<time string>\n"
@ -47,11 +47,11 @@ msgid ""
" " " "
msgstr "" msgstr ""
#: plugin.py:106 plugin.py:122 #: plugin.py:107 plugin.py:123
msgid "That's right now!" msgid "That's right now!"
msgstr "" msgstr ""
#: plugin.py:111 #: plugin.py:112
#, docstring #, docstring
msgid "" msgid ""
"<time string>\n" "<time string>\n"
@ -60,7 +60,7 @@ msgid ""
" " " "
msgstr "" msgstr ""
#: plugin.py:127 #: plugin.py:128
#, docstring #, docstring
msgid "" msgid ""
"[<seconds since epoch>]\n" "[<seconds since epoch>]\n"
@ -70,11 +70,11 @@ msgid ""
" " " "
msgstr "" msgstr ""
#: plugin.py:133 #: plugin.py:134
msgid "number of seconds since epoch" msgid "number of seconds since epoch"
msgstr "" msgstr ""
#: plugin.py:138 #: plugin.py:139
#, docstring #, docstring
msgid "" msgid ""
"[<format>] [<seconds since epoch>]\n" "[<format>] [<seconds since epoch>]\n"
@ -85,7 +85,7 @@ msgid ""
" " " "
msgstr "" msgstr ""
#: plugin.py:155 #: plugin.py:156
#, docstring #, docstring
msgid "" msgid ""
"<seconds>\n" "<seconds>\n"
@ -95,3 +95,23 @@ msgid ""
" " " "
msgstr "" msgstr ""
#: plugin.py:166
#, docstring
msgid ""
"<region>/<city>\n"
"\n"
" Takes a city and its region, and returns the locale time."
msgstr ""
#: plugin.py:172
msgid "Python-tz is required by the command, but is not installed on this computer."
msgstr ""
#: plugin.py:175
msgid "A timezone must be in the format region/city."
msgstr ""
#: plugin.py:179
msgid "Unknown timezone"
msgstr ""

View File

@ -29,6 +29,7 @@
import time import time
TIME = time # For later use. TIME = time # For later use.
from datetime import datetime
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
@ -160,6 +161,25 @@ class Time(callbacks.Plugin):
irc.reply(utils.timeElapsed(seconds)) irc.reply(utils.timeElapsed(seconds))
elapsed = wrap(elapsed, ['int']) elapsed = wrap(elapsed, ['int'])
@internationalizeDocstring
def tztime(self, irc, msg, args, timezone):
"""<region>/<city>
Takes a city and its region, and returns the locale time."""
try:
import pytz
except ImportError:
irc.error(_('Python-tz is required by the command, but is not '
'installed on this computer.'))
if len(timezone.split('/')) != 2:
irc.error(_('A timezone must be in the format region/city.'))
try:
timezone = pytz.timezone(timezone)
except pytz.UnknownTimeZoneError:
irc.error(_('Unknown timezone'))
irc.reply(str(datetime.now(timezone)))
tztime = wrap(tztime, ['text'])
Class = Time Class = Time

View File

@ -50,12 +50,16 @@ class TimeTestCase(PluginTestCase):
def testNoErrors(self): def testNoErrors(self):
self.assertNotError('ctime') self.assertNotError('ctime')
self.assertNotError('time %Y') self.assertNotError('time %Y')
self.assertNotError('tztime Europe/Paris')
def testNoNestedErrors(self): def testNoNestedErrors(self):
self.assertNotError('echo [until 4:00]') self.assertNotError('echo [until 4:00]')
self.assertNotError('echo [at now]') self.assertNotError('echo [at now]')
self.assertNotError('echo [seconds 4m]') self.assertNotError('echo [seconds 4m]')
def testErrors(self):
self.assertError('tztime Europe/Gniarf')
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: