Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/templater.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 | b5d39a09656a |
children | 052351e3e1cd |
comparison
equal
deleted
inserted
replaced
36635:4de15c54e59f | 36636:c6061cadb400 |
---|---|
27 scmutil, | 27 scmutil, |
28 templatefilters, | 28 templatefilters, |
29 templatekw, | 29 templatekw, |
30 util, | 30 util, |
31 ) | 31 ) |
32 from .utils import dateutil | |
32 | 33 |
33 class ResourceUnavailable(error.Abort): | 34 class ResourceUnavailable(error.Abort): |
34 pass | 35 pass |
35 | 36 |
36 class TemplateNotFound(error.Abort): | 37 class TemplateNotFound(error.Abort): |
647 fmt = None | 648 fmt = None |
648 if len(args) == 2: | 649 if len(args) == 2: |
649 fmt = evalstring(context, mapping, args[1]) | 650 fmt = evalstring(context, mapping, args[1]) |
650 try: | 651 try: |
651 if fmt is None: | 652 if fmt is None: |
652 return util.datestr(date) | 653 return dateutil.datestr(date) |
653 else: | 654 else: |
654 return util.datestr(date, fmt) | 655 return dateutil.datestr(date, fmt) |
655 except (TypeError, ValueError): | 656 except (TypeError, ValueError): |
656 # i18n: "date" is a keyword | 657 # i18n: "date" is a keyword |
657 raise error.ParseError(_("date expects a date information")) | 658 raise error.ParseError(_("date expects a date information")) |
658 | 659 |
659 @templatefunc('dict([[key=]value...])', argspec='*args **kwargs') | 660 @templatefunc('dict([[key=]value...])', argspec='*args **kwargs') |
952 # i18n: "localdate" is a keyword | 953 # i18n: "localdate" is a keyword |
953 raise error.ParseError(_("localdate expects one or two arguments")) | 954 raise error.ParseError(_("localdate expects one or two arguments")) |
954 | 955 |
955 date = evalfuncarg(context, mapping, args[0]) | 956 date = evalfuncarg(context, mapping, args[0]) |
956 try: | 957 try: |
957 date = util.parsedate(date) | 958 date = dateutil.parsedate(date) |
958 except AttributeError: # not str nor date tuple | 959 except AttributeError: # not str nor date tuple |
959 # i18n: "localdate" is a keyword | 960 # i18n: "localdate" is a keyword |
960 raise error.ParseError(_("localdate expects a date information")) | 961 raise error.ParseError(_("localdate expects a date information")) |
961 if len(args) >= 2: | 962 if len(args) >= 2: |
962 tzoffset = None | 963 tzoffset = None |
963 tz = evalfuncarg(context, mapping, args[1]) | 964 tz = evalfuncarg(context, mapping, args[1]) |
964 if isinstance(tz, bytes): | 965 if isinstance(tz, bytes): |
965 tzoffset, remainder = util.parsetimezone(tz) | 966 tzoffset, remainder = dateutil.parsetimezone(tz) |
966 if remainder: | 967 if remainder: |
967 tzoffset = None | 968 tzoffset = None |
968 if tzoffset is None: | 969 if tzoffset is None: |
969 try: | 970 try: |
970 tzoffset = int(tz) | 971 tzoffset = int(tz) |
971 except (TypeError, ValueError): | 972 except (TypeError, ValueError): |
972 # i18n: "localdate" is a keyword | 973 # i18n: "localdate" is a keyword |
973 raise error.ParseError(_("localdate expects a timezone")) | 974 raise error.ParseError(_("localdate expects a timezone")) |
974 else: | 975 else: |
975 tzoffset = util.makedate()[1] | 976 tzoffset = dateutil.makedate()[1] |
976 return (date[0], tzoffset) | 977 return (date[0], tzoffset) |
977 | 978 |
978 @templatefunc('max(iterable)') | 979 @templatefunc('max(iterable)') |
979 def max_(context, mapping, args, **kwargs): | 980 def max_(context, mapping, args, **kwargs): |
980 """Return the max of an iterable""" | 981 """Return the max of an iterable""" |