Extract shortdate from util.py to utils/dateutil.py
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
lothiraldan |
hg-reviewers |
Extract shortdate from util.py to utils/dateutil.py
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/commands.py (2 lines) | |||
M | mercurial/templatefilters.py (4 lines) | |||
M | mercurial/util.py (10 lines) | |||
M | mercurial/utils/dateutil.py (5 lines) |
Status | Author | Revision | |
---|---|---|---|
Abandoned | lothiraldan | ||
Abandoned | durin42 | D2056 util: extract matchdate | |
Abandoned | durin42 | D2055 util: extract parsedate | |
Abandoned | durin42 | D2054 util: extract strdate | |
Abandoned | durin42 | ||
Abandoned | durin42 | D2052 util: extract shortdate | |
Abandoned | durin42 | D2051 util: extract datestr | |
Abandoned | durin42 | D2050 util: extract makedate | |
Abandoned | durin42 | ||
Abandoned | lothiraldan | ||
Abandoned | durin42 |
rev = opts.get('rev') | rev = opts.get('rev') | ||||
if rev: | if rev: | ||||
repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') | repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') | ||||
ctx = scmutil.revsingle(repo, rev) | ctx = scmutil.revsingle(repo, rev) | ||||
rootfm = ui.formatter('annotate', opts) | rootfm = ui.formatter('annotate', opts) | ||||
if ui.quiet: | if ui.quiet: | ||||
datefunc = util.shortdate | datefunc = dateutil.shortdate | ||||
else: | else: | ||||
datefunc = dateutil.datestr | datefunc = dateutil.datestr | ||||
if ctx.rev() is None: | if ctx.rev() is None: | ||||
def hexfn(node): | def hexfn(node): | ||||
if node is None: | if node is None: | ||||
return None | return None | ||||
else: | else: | ||||
return rootfm.hexfunc(node) | return rootfm.hexfunc(node) |
if then > now: | if then > now: | ||||
future = True | future = True | ||||
delta = max(1, int(then - now)) | delta = max(1, int(then - now)) | ||||
if delta > agescales[0][1] * 30: | if delta > agescales[0][1] * 30: | ||||
return 'in the distant future' | return 'in the distant future' | ||||
else: | else: | ||||
delta = max(1, int(now - then)) | delta = max(1, int(now - then)) | ||||
if delta > agescales[0][1] * 2: | if delta > agescales[0][1] * 2: | ||||
return util.shortdate(date) | return dateutil.shortdate(date) | ||||
for t, s, a in agescales: | for t, s, a in agescales: | ||||
n = delta // s | n = delta // s | ||||
if n >= 2 or s == 1: | if n >= 2 or s == 1: | ||||
if future: | if future: | ||||
return '%s from now' % fmt(t, n, a) | return '%s from now' % fmt(t, n, a) | ||||
return '%s ago' % fmt(t, n, a) | return '%s ago' % fmt(t, n, a) | ||||
S: skipped, U: untested, I: ignored). Returns single space if `text` | S: skipped, U: untested, I: ignored). Returns single space if `text` | ||||
is not a valid bisection status. | is not a valid bisection status. | ||||
""" | """ | ||||
return hbisect.shortlabel(text) or ' ' | return hbisect.shortlabel(text) or ' ' | ||||
@templatefilter('shortdate') | @templatefilter('shortdate') | ||||
def shortdate(text): | def shortdate(text): | ||||
"""Date. Returns a date like "2006-09-18".""" | """Date. Returns a date like "2006-09-18".""" | ||||
return util.shortdate(text) | return dateutil.shortdate(text) | ||||
@templatefilter('slashpath') | @templatefilter('slashpath') | ||||
def slashpath(path): | def slashpath(path): | ||||
"""Any text. Replaces the native path separator with slash.""" | """Any text. Replaces the native path separator with slash.""" | ||||
return util.pconvert(path) | return util.pconvert(path) | ||||
@templatefilter('splitlines') | @templatefilter('splitlines') | ||||
def splitlines(text): | def splitlines(text): |
nbytes = min(limit, size) | nbytes = min(limit, size) | ||||
s = nbytes and f.read(nbytes) | s = nbytes and f.read(nbytes) | ||||
if not s: | if not s: | ||||
break | break | ||||
if limit: | if limit: | ||||
limit -= len(s) | limit -= len(s) | ||||
yield 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): | def parsetimezone(s): | ||||
"""find a trailing timezone, if any, in string, and return a | """find a trailing timezone, if any, in string, and return a | ||||
(offset, remainder) pair""" | (offset, remainder) pair""" | ||||
if s.endswith("GMT") or s.endswith("UTC"): | if s.endswith("GMT") or s.endswith("UTC"): | ||||
return 0, s[:-3].rstrip() | return 0, s[:-3].rstrip() | ||||
# Unix-style timezones [+-]hhmm | # Unix-style timezones [+-]hhmm | ||||
return dateutil.makedate(*args, **kwargs) | return dateutil.makedate(*args, **kwargs) | ||||
def datestr(*args, **kwargs): | def datestr(*args, **kwargs): | ||||
msg = ("'util.datestr' is deprecated, " | msg = ("'util.datestr' is deprecated, " | ||||
"use 'utils.dateutil.datestr'") | "use 'utils.dateutil.datestr'") | ||||
nouideprecwarn(msg, "4.6") | nouideprecwarn(msg, "4.6") | ||||
return dateutil.datestr(*args, **kwargs) | 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) | |||||
elif d < -0x80000000: | elif d < -0x80000000: | ||||
d = -0x80000000 | d = -0x80000000 | ||||
# Never use time.gmtime() and datetime.datetime.fromtimestamp() | # Never use time.gmtime() and datetime.datetime.fromtimestamp() | ||||
# because they use the gmtime() system call which is buggy on Windows | # because they use the gmtime() system call which is buggy on Windows | ||||
# for negative values. | # for negative values. | ||||
t = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=d) | t = datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=d) | ||||
s = encoding.strtolocal(t.strftime(encoding.strfromlocal(format))) | s = encoding.strtolocal(t.strftime(encoding.strfromlocal(format))) | ||||
return s | return s | ||||
def shortdate(date=None): | |||||
"""turn (timestamp, tzoff) tuple into iso 8631 date.""" | |||||
return datestr(date, format='%Y-%m-%d') | |||||