diff options
author | Anton Khirnov <anton@khirnov.net> | 2021-01-16 09:39:30 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-01-16 09:39:44 +0100 |
commit | 7ba6454a8c029462c7f86bb1090fe74ff28d093f (patch) | |
tree | f5338aaa3e3df7a4dc9cb048e1c93800e0c5ae14 /alot/helper.py | |
parent | 55171ecf0bd62c3b83aea85ac3c7e1d4967ebda4 (diff) |
helper: move pretty_datetime to the only place where it is used
Also, drop now-unnecessary call to decode_string
Diffstat (limited to 'alot/helper.py')
-rw-r--r-- | alot/helper.py | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/alot/helper.py b/alot/helper.py index 1ab6ead0..4511059f 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -3,8 +3,6 @@ # Copyright © 2017-2018 Dylan Baker # This file is released under the GNU GPL, version 3 or a later revision. # For further details see the COPYING file -from datetime import timedelta -from datetime import datetime from collections import deque import logging import mimetypes @@ -157,61 +155,6 @@ def shorten_author_string(authors_string, maxlength): return authorsstring -def pretty_datetime(d): - """ - translates :class:`datetime` `d` to a "sup-style" human readable string. - - >>> now = datetime.now() - >>> now.strftime('%c') - 'Sat 31 Mar 2012 14:47:26 ' - >>> pretty_datetime(now) - 'just now' - >>> pretty_datetime(now - timedelta(minutes=1)) - '1min ago' - >>> pretty_datetime(now - timedelta(hours=5)) - '5h ago' - >>> pretty_datetime(now - timedelta(hours=12)) - '02:54am' - >>> pretty_datetime(now - timedelta(days=1)) - 'yest 02pm' - >>> pretty_datetime(now - timedelta(days=2)) - 'Thu 02pm' - >>> pretty_datetime(now - timedelta(days=7)) - 'Mar 24' - >>> pretty_datetime(now - timedelta(days=356)) - 'Apr 2011' - """ - ampm = d.strftime('%p').lower() - if len(ampm): - hourfmt = '%I' + ampm - hourminfmt = '%I:%M' + ampm - else: - hourfmt = '%Hh' - hourminfmt = '%H:%M' - - now = datetime.now() - today = now.date() - if d.date() == today or d > now - timedelta(hours=6): - delta = datetime.now() - d - if delta.seconds < 60: - string = 'just now' - elif delta.seconds < 3600: - string = '%dmin ago' % (delta.seconds // 60) - elif delta.seconds < 6 * 3600: - string = '%dh ago' % (delta.seconds // 3600) - else: - string = d.strftime(hourminfmt) - elif d.date() == today - timedelta(1): - string = d.strftime('yest ' + hourfmt) - elif d.date() > today - timedelta(7): - string = d.strftime('%a ' + hourfmt) - elif d.year != today.year: - string = d.strftime('%b %Y') - else: - string = d.strftime('%b %d') - return string_decode(string, 'UTF-8') - - def call_cmd(cmdlist, stdin=None): """ get a shell commands output, error message and return value and immediately |