Commit 7f40354a authored by Bram Schoenmakers's avatar Bram Schoenmakers

Print humanized due dates in the Dot chart

The humanize_date function was therefore moved out ListFormat.py towards
Utils.py.
parent d1e8d7d6
...@@ -22,6 +22,7 @@ notation. Useful for displaying dependencies. ...@@ -22,6 +22,7 @@ notation. Useful for displaying dependencies.
from textwrap import wrap from textwrap import wrap
from topydo.lib.PrettyPrinter import Printer from topydo.lib.PrettyPrinter import Printer
from topydo.lib.Utils import humanize_date
class DotPrinter(Printer): class DotPrinter(Printer):
...@@ -54,7 +55,7 @@ class DotPrinter(Printer): ...@@ -54,7 +55,7 @@ class DotPrinter(Printer):
node_result += '<TR><TD ALIGN="LEFT">Prio:</TD><TD ALIGN="LEFT">{}</TD></TR>'.format(p_todo.priority()) node_result += '<TR><TD ALIGN="LEFT">Prio:</TD><TD ALIGN="LEFT">{}</TD></TR>'.format(p_todo.priority())
if p_todo.due_date(): if p_todo.due_date():
node_result += '<TR><TD ALIGN="LEFT">Due:</TD><TD ALIGN="LEFT">{}</TD></TR>'.format(p_todo.due_date().isoformat()) node_result += '<TR><TD ALIGN="LEFT">Due:</TD><TD ALIGN="LEFT">{} ({})</TD></TR>'.format(p_todo.due_date().isoformat(), humanize_date(p_todo.due_date()))
node_result += '</TABLE>>' node_result += '</TABLE>>'
......
...@@ -20,7 +20,7 @@ import arrow ...@@ -20,7 +20,7 @@ import arrow
import re import re
from topydo.lib.Config import config from topydo.lib.Config import config
from topydo.lib.Utils import get_terminal_size from topydo.lib.Utils import get_terminal_size, humanize_date
MAIN_PATTERN = (r'^({{(?P<before>.+?)}})?' MAIN_PATTERN = (r'^({{(?P<before>.+?)}})?'
r'(?P<placeholder>{ph}|\[{ph}\])' r'(?P<placeholder>{ph}|\[{ph}\])'
...@@ -38,12 +38,6 @@ def _filler(p_str, p_len): ...@@ -38,12 +38,6 @@ def _filler(p_str, p_len):
to_fill = p_len - len(p_str) to_fill = p_len - len(p_str)
return to_fill*' ' + p_str return to_fill*' ' + p_str
def humanize_date(p_datetime):
""" Returns a relative date string from a datetime object. """
now = arrow.now()
date = now.replace(day=p_datetime.day, month=p_datetime.month, year=p_datetime.year)
return date.humanize()
def humanize_dates(p_due=None, p_start=None, p_creation=None): def humanize_dates(p_due=None, p_start=None, p_creation=None):
""" """
Returns string with humanized versions of p_due, p_start and p_creation. Returns string with humanized versions of p_due, p_start and p_creation.
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
Various utility functions. Various utility functions.
""" """
import arrow
import re import re
from collections import namedtuple from collections import namedtuple
...@@ -72,3 +73,10 @@ def get_terminal_size(): ...@@ -72,3 +73,10 @@ def get_terminal_size():
sz = terminal_size((80, 24)) sz = terminal_size((80, 24))
return sz return sz
def humanize_date(p_datetime):
""" Returns a relative date string from a datetime object. """
now = arrow.now()
date = now.replace(day=p_datetime.day, month=p_datetime.month, year=p_datetime.year)
return date.humanize()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment