Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/templatefilters.py @ 36636:c6061cadb400
util: extract all date-related utils in utils/dateutil module
With this commit, util.py lose 262 lines
Note for extensions author, if this commit breaks your extension, you can pull
the step-by-step split here to help you more easily pinpoint the renaming that
broke your extension:
hg pull https://bitbucket.org/octobus/mercurial-devel/ -r ac1f6453010d
Differential Revision: https://phab.mercurial-scm.org/D2282
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Thu, 15 Feb 2018 17:18:26 +0100 |
parents | 9b6b02a5b589 |
children | 71f189941791 |
comparison
equal
deleted
inserted
replaced
36635:4de15c54e59f | 36636:c6061cadb400 |
---|---|
20 registrar, | 20 registrar, |
21 templatekw, | 21 templatekw, |
22 url, | 22 url, |
23 util, | 23 util, |
24 ) | 24 ) |
25 from .utils import dateutil | |
25 | 26 |
26 urlerr = util.urlerr | 27 urlerr = util.urlerr |
27 urlreq = util.urlreq | 28 urlreq = util.urlreq |
28 | 29 |
29 if pycompat.ispy3: | 30 if pycompat.ispy3: |
76 if delta > agescales[0][1] * 30: | 77 if delta > agescales[0][1] * 30: |
77 return 'in the distant future' | 78 return 'in the distant future' |
78 else: | 79 else: |
79 delta = max(1, int(now - then)) | 80 delta = max(1, int(now - then)) |
80 if delta > agescales[0][1] * 2: | 81 if delta > agescales[0][1] * 2: |
81 return util.shortdate(date) | 82 return dateutil.shortdate(date) |
82 | 83 |
83 for t, s, a in agescales: | 84 for t, s, a in agescales: |
84 n = delta // s | 85 n = delta // s |
85 if n >= 2 or s == 1: | 86 if n >= 2 or s == 1: |
86 if future: | 87 if future: |
201 @templatefilter('isodate') | 202 @templatefilter('isodate') |
202 def isodate(text): | 203 def isodate(text): |
203 """Date. Returns the date in ISO 8601 format: "2009-08-18 13:00 | 204 """Date. Returns the date in ISO 8601 format: "2009-08-18 13:00 |
204 +0200". | 205 +0200". |
205 """ | 206 """ |
206 return util.datestr(text, '%Y-%m-%d %H:%M %1%2') | 207 return dateutil.datestr(text, '%Y-%m-%d %H:%M %1%2') |
207 | 208 |
208 @templatefilter('isodatesec') | 209 @templatefilter('isodatesec') |
209 def isodatesec(text): | 210 def isodatesec(text): |
210 """Date. Returns the date in ISO 8601 format, including | 211 """Date. Returns the date in ISO 8601 format, including |
211 seconds: "2009-08-18 13:00:13 +0200". See also the rfc3339date | 212 seconds: "2009-08-18 13:00:13 +0200". See also the rfc3339date |
212 filter. | 213 filter. |
213 """ | 214 """ |
214 return util.datestr(text, '%Y-%m-%d %H:%M:%S %1%2') | 215 return dateutil.datestr(text, '%Y-%m-%d %H:%M:%S %1%2') |
215 | 216 |
216 def indent(text, prefix): | 217 def indent(text, prefix): |
217 '''indent each non-empty line of text after first with prefix.''' | 218 '''indent each non-empty line of text after first with prefix.''' |
218 lines = text.splitlines() | 219 lines = text.splitlines() |
219 num_lines = len(lines) | 220 num_lines = len(lines) |
323 @templatefilter('rfc3339date') | 324 @templatefilter('rfc3339date') |
324 def rfc3339date(text): | 325 def rfc3339date(text): |
325 """Date. Returns a date using the Internet date format | 326 """Date. Returns a date using the Internet date format |
326 specified in RFC 3339: "2009-08-18T13:00:13+02:00". | 327 specified in RFC 3339: "2009-08-18T13:00:13+02:00". |
327 """ | 328 """ |
328 return util.datestr(text, "%Y-%m-%dT%H:%M:%S%1:%2") | 329 return dateutil.datestr(text, "%Y-%m-%dT%H:%M:%S%1:%2") |
329 | 330 |
330 @templatefilter('rfc822date') | 331 @templatefilter('rfc822date') |
331 def rfc822date(text): | 332 def rfc822date(text): |
332 """Date. Returns a date using the same format used in email | 333 """Date. Returns a date using the same format used in email |
333 headers: "Tue, 18 Aug 2009 13:00:13 +0200". | 334 headers: "Tue, 18 Aug 2009 13:00:13 +0200". |
334 """ | 335 """ |
335 return util.datestr(text, "%a, %d %b %Y %H:%M:%S %1%2") | 336 return dateutil.datestr(text, "%a, %d %b %Y %H:%M:%S %1%2") |
336 | 337 |
337 @templatefilter('short') | 338 @templatefilter('short') |
338 def short(text): | 339 def short(text): |
339 """Changeset hash. Returns the short form of a changeset hash, | 340 """Changeset hash. Returns the short form of a changeset hash, |
340 i.e. a 12 hexadecimal digit string. | 341 i.e. a 12 hexadecimal digit string. |
351 return hbisect.shortlabel(text) or ' ' | 352 return hbisect.shortlabel(text) or ' ' |
352 | 353 |
353 @templatefilter('shortdate') | 354 @templatefilter('shortdate') |
354 def shortdate(text): | 355 def shortdate(text): |
355 """Date. Returns a date like "2006-09-18".""" | 356 """Date. Returns a date like "2006-09-18".""" |
356 return util.shortdate(text) | 357 return dateutil.shortdate(text) |
357 | 358 |
358 @templatefilter('slashpath') | 359 @templatefilter('slashpath') |
359 def slashpath(path): | 360 def slashpath(path): |
360 """Any text. Replaces the native path separator with slash.""" | 361 """Any text. Replaces the native path separator with slash.""" |
361 return util.pconvert(path) | 362 return util.pconvert(path) |