diff options
Diffstat (limited to 'alot')
-rw-r--r-- | alot/helper.py | 57 | ||||
-rw-r--r-- | alot/settings/manager.py | 63 |
2 files changed, 60 insertions, 60 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 diff --git a/alot/settings/manager.py b/alot/settings/manager.py index f6da5332..ab5e70fb 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -1,6 +1,9 @@ # Copyright (C) 2011-2012 Patrick Totzke <patricktotzke@gmail.com> # This file is released under the GNU GPL, version 3 or a later revision. # For further details see the COPYING file + +from datetime import datetime, timedelta + import importlib.util import itertools import logging @@ -13,7 +16,7 @@ from configobj import ConfigObj, Section from ..account import SendmailAccount from ..addressbook.abook import AbookAddressBook from ..addressbook.external import ExternalAddressbook -from ..helper import pretty_datetime, string_decode, get_xdg_env +from ..helper import string_decode, get_xdg_env from ..utils import configobj as checks from .errors import ConfigError, NoMatchingAccount @@ -26,6 +29,60 @@ DEFAULTSPATH = os.path.join(os.path.dirname(__file__), '..', 'defaults') DATA_DIRS = get_xdg_env('XDG_DATA_DIRS', '/usr/local/share:/usr/share').split(':') +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 class SettingsManager: """Organizes user settings""" @@ -523,7 +580,7 @@ class SettingsManager: 1) look if a fixed 'timestamp_format' is given in the config 2) check if a 'timestamp_format' hook is defined - 3) use :func:`~alot.helper.pretty_datetime` as fallback + 3) use :func:`_pretty_datetime` as fallback """ fixed_format = self.get('timestamp_format') @@ -534,5 +591,5 @@ class SettingsManager: if format_hook: rep = string_decode(format_hook(d), 'UTF-8') else: - rep = pretty_datetime(d) + rep = _pretty_datetime(d) return rep |