keyword: declare input type of date filters as date
authorYuya Nishihara <yuya@tcha.org>
Sun, 18 Mar 2018 17:02:39 +0900
changeset 37228 a0b17f744cbc
parent 37227 9bcf096a2da2
child 37229 05db42732fce
keyword: declare input type of date filters as date Dropped redundant dateutil.parsedate(), which is now handled by the templater.
hgext/keyword.py
--- a/hgext/keyword.py	Sun Mar 18 16:12:44 2018 +0900
+++ b/hgext/keyword.py	Sun Mar 18 17:02:39 2018 +0900
@@ -109,6 +109,7 @@
     registrar,
     scmutil,
     templatefilters,
+    templateutil,
     util,
 )
 from mercurial.utils import (
@@ -156,27 +157,27 @@
     default=False,
 )
 # date like in cvs' $Date
-@templatefilter('utcdate')
-def utcdate(text):
+@templatefilter('utcdate', intype=templateutil.date)
+def utcdate(date):
     '''Date. Returns a UTC-date in this format: "2009/08/18 11:00:13".
     '''
     dateformat = '%Y/%m/%d %H:%M:%S'
-    return dateutil.datestr((dateutil.parsedate(text)[0], 0), dateformat)
+    return dateutil.datestr((date[0], 0), dateformat)
 # date like in svn's $Date
-@templatefilter('svnisodate')
-def svnisodate(text):
+@templatefilter('svnisodate', intype=templateutil.date)
+def svnisodate(date):
     '''Date. Returns a date in this format: "2009-08-18 13:00:13
     +0200 (Tue, 18 Aug 2009)".
     '''
-    return dateutil.datestr(text, '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
+    return dateutil.datestr(date, '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
 # date like in svn's $Id
-@templatefilter('svnutcdate')
-def svnutcdate(text):
+@templatefilter('svnutcdate', intype=templateutil.date)
+def svnutcdate(date):
     '''Date. Returns a UTC-date in this format: "2009-08-18
     11:00:13Z".
     '''
     dateformat = '%Y-%m-%d %H:%M:%SZ'
-    return dateutil.datestr((dateutil.parsedate(text)[0], 0), dateformat)
+    return dateutil.datestr((date[0], 0), dateformat)
 
 # make keyword tools accessible
 kwtools = {'hgcmd': ''}