D2052: util: extract shortdate
lothiraldan (Boris Feld)
phabricator at mercurial-scm.org
Mon Feb 5 16:24:38 UTC 2018
lothiraldan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
Extract shortdate from util.py to utils/dateutil.py
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D2052
AFFECTED FILES
mercurial/commands.py
mercurial/templatefilters.py
mercurial/util.py
mercurial/utils/dateutil.py
CHANGE DETAILS
diff --git a/mercurial/utils/dateutil.py b/mercurial/utils/dateutil.py
--- a/mercurial/utils/dateutil.py
+++ b/mercurial/utils/dateutil.py
@@ -106,3 +106,8 @@
t = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=d)
s = encoding.strtolocal(t.strftime(encoding.strfromlocal(format)))
return s
+
+def shortdate(date=None):
+ """turn (timestamp, tzoff) tuple into iso 8631 date."""
+ return datestr(date, format='%Y-%m-%d')
+
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1906,10 +1906,6 @@
limit -= len(s)
yield s
-def shortdate(date=None):
- """turn (timestamp, tzoff) tuple into iso 8631 date."""
- return dateutil.datestr(date, format='%Y-%m-%d')
-
def parsetimezone(s):
"""find a trailing timezone, if any, in string, and return a
(offset, remainder) pair"""
@@ -3875,3 +3871,9 @@
nouideprecwarn(msg, "4.6")
return dateutil.datestr(*args, **kwargs)
+def shortdate(*args, **kwargs):
+ msg = ("'util.shortdate' is deprecated, "
+ "use 'utils.dateutil.shortdate'")
+ nouideprecwarn(msg, "4.6")
+ return dateutil.shortdate(*args, **kwargs)
+
diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -79,7 +79,7 @@
else:
delta = max(1, int(now - then))
if delta > agescales[0][1] * 2:
- return util.shortdate(date)
+ return dateutil.shortdate(date)
for t, s, a in agescales:
n = delta // s
@@ -347,7 +347,7 @@
@templatefilter('shortdate')
def shortdate(text):
"""Date. Returns a date like "2006-09-18"."""
- return util.shortdate(text)
+ return dateutil.shortdate(text)
@templatefilter('slashpath')
def slashpath(path):
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -302,7 +302,7 @@
rootfm = ui.formatter('annotate', opts)
if ui.quiet:
- datefunc = util.shortdate
+ datefunc = dateutil.shortdate
else:
datefunc = dateutil.datestr
if ctx.rev() is None:
To: lothiraldan, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list