# HG changeset patch
# User Yuya Nishihara <y...@tcha.org>
# Date 1521881959 -32400
#      Sat Mar 24 17:59:19 2018 +0900
# Node ID cb223b044175c8444053bd55aa6d78992243c30a
# Parent  61e21a5a89d421909c45718ffc50f72cf83ee4b5
templater: make date wrapper support dot/map operations

No idea if it will be useful, but it just works.

diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -172,7 +172,7 @@ class wrappedvalue(wrapped):
     def tovalue(self, context, mapping):
         return self._value
 
-class date(wrapped):
+class date(mappable, wrapped):
     """Wrapper for date tuple"""
 
     def __init__(self, value):
@@ -192,15 +192,15 @@ class date(wrapped):
     def getmax(self, context, mapping):
         raise error.ParseError(_('date is not iterable'))
 
-    def itermaps(self, context):
-        raise error.ParseError(_("date is not iterable"))
-
     def join(self, context, mapping, sep):
         raise error.ParseError(_("date is not iterable"))
 
     def show(self, context, mapping):
         return '%d %d' % (self._unixtime, self._tzoffset)
 
+    def tomap(self, context):
+        return {'unixtime': self._unixtime, 'tzoffset': self._tzoffset}
+
     def tovalue(self, context, mapping):
         return (self._unixtime, self._tzoffset)
 
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -3398,6 +3398,8 @@ Test evaluation of dot operator:
   ce3cec86e6c26bd9bdfc590a6b92abc9680f1796
   $ hg log -R latesttag -r0 -T '{extras.branch}\n'
   default
+  $ hg log -R latesttag -r0 -T '{date.unixtime} {localdate(date, 
"+0200").tzoffset}\n'
+  0 -7200
 
   $ hg log -R latesttag -l1 -T '{author.invalid}\n'
   hg: parse error: 'test' is not a dictionary
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to