Patchwork [08,of,11] keyword: declare input type of date filters as date

login
register
mail settings
Submitter Yuya Nishihara
Date March 31, 2018, 1:49 a.m.
Message ID <068cf6f31d4733d74d08.1522460976@mimosa>
Download mbox | patch
Permalink /patch/30045/
State Accepted
Headers show

Comments

Yuya Nishihara - March 31, 2018, 1:49 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1521360159 -32400
#      Sun Mar 18 17:02:39 2018 +0900
# Node ID 068cf6f31d4733d74d084d0cca61a9ff04939ea5
# Parent  baf331e387375dd7ad56b45b59fce950c385d17b
keyword: declare input type of date filters as date

Dropped redundant dateutil.parsedate(), which is now handled by the
templater.

Patch

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -109,6 +109,7 @@  from mercurial import (
     registrar,
     scmutil,
     templatefilters,
+    templateutil,
     util,
 )
 from mercurial.utils import (
@@ -156,27 +157,27 @@  configitem('keywordset', 'svn',
     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': ''}