diff options
author | joelostblom <joel.ostblom@gmail.com> | 2018-12-25 22:52:37 +0100 |
---|---|---|
committer | joelostblom <joel.ostblom@gmail.com> | 2018-12-25 22:57:51 +0100 |
commit | e14946c116d707f60d0cfb7e2fb2c3da0490aafb (patch) | |
tree | 30a229c99520b8ac8b18f9faa37d05da18022cea /ranger | |
parent | 9bd860528f2453b56ca4c4f23fba2b11e026813c (diff) | |
download | ranger-e14946c116d707f60d0cfb7e2fb2c3da0490aafb.tar.gz |
Break out common code into helper funciton
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/core/linemode.py | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/ranger/core/linemode.py b/ranger/core/linemode.py index c2e11d1a..a98db193 100644 --- a/ranger/core/linemode.py +++ b/ranger/core/linemode.py @@ -142,15 +142,7 @@ class HumanMtimeLinemode(LinemodeBase): def infostring(self, fobj, metadata): if fobj.stat is None: return '?' - file_date = datetime.fromtimestamp(fobj.stat.st_mtime) - time_diff = datetime.now().date() - file_date.date() - if time_diff.days >= 365: - return file_date.strftime("%-d %b %Y") - if time_diff.days >= 7: - return file_date.strftime("%-d %b") - if time_diff.days >= 1: - return file_date.strftime("%a") - return file_date.strftime("%H:%M") + return print_human_mtime(fobj.stat.st_mtime) class SizeHumanMtimeLinemode(LinemodeBase): @@ -163,12 +155,16 @@ class SizeHumanMtimeLinemode(LinemodeBase): if fobj.stat is None: return '?' size = human_readable(fobj.size) - file_date = datetime.fromtimestamp(fobj.stat.st_mtime) - time_diff = datetime.now().date() - file_date.date() - if time_diff.days >= 365: - return "%s %11s" % (size, file_date.strftime("%-d %b %Y")) - if time_diff.days >= 7: - return "%s %11s" % (size, file_date.strftime("%-d %b")) - if time_diff.days >= 1: - return "%s %11s" % (size, file_date.strftime("%a")) - return "%s %11s" % (size, file_date.strftime("%H:%M")) + return "%s %11s" % (size, print_human_mtime(fobj.stat.st_mtime)) + + +def print_human_mtime(file_mtime): + file_date = datetime.fromtimestamp(file_mtime) + time_diff = datetime.now().date() - file_date.date() + if time_diff.days >= 365: + return file_date.strftime("%-d %b %Y") + if time_diff.days >= 7: + return file_date.strftime("%-d %b") + if time_diff.days >= 1: + return file_date.strftime("%a") + return file_date.strftime("%H:%M") |