From: Ed Page Date: Thu, 16 Apr 2009 13:45:27 +0000 (-0500) Subject: Fixing bugs, improving output, and adding tests to fuzzy date stuff X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;ds=sidebyside;h=9c052e10a8ea601905c4476dd9e452e757f1341f;p=doneit Fixing bugs, improving output, and adding tests to fuzzy date stuff --- diff --git a/src/toolbox.py b/src/toolbox.py index 9b8e2b0..4601f3f 100644 --- a/src/toolbox.py +++ b/src/toolbox.py @@ -149,6 +149,20 @@ def is_same_day(targetDate, todaysDate = datetime.datetime.today()): def to_fuzzy_date(targetDate, todaysDate = datetime.datetime.today()): """ Conert a date/time/datetime object to a fuzzy date + + >>> todaysDate = datetime.date(2009, 4, 16) + >>> to_fuzzy_date(datetime.date(1, 4, 6), todaysDate) + 'Forever ago' + >>> to_fuzzy_date(datetime.date(2008, 4, 13), todaysDate) + 'Last year' + >>> to_fuzzy_date(datetime.date(2009, 4, 13), todaysDate) + 'Last Monday' + >>> to_fuzzy_date(datetime.date(2009, 4, 20), todaysDate) + 'This Monday' + >>> to_fuzzy_date(datetime.date(2010, 4, 13), todaysDate) + 'Next year' + >>> to_fuzzy_date(datetime.date(2012, 12, 12), todaysDate) + 'Forever from now' """ delta = targetDate - todaysDate days = abs(delta.days) @@ -158,16 +172,16 @@ def to_fuzzy_date(targetDate, todaysDate = datetime.datetime.today()): directionByN = "Later" if isFuture else "Earlier" yearDelta = abs(targetDate.year - todaysDate.year) - if 2 < yearDelta: + if 1 < yearDelta: directionByInf = "from now" if isFuture else "ago" return "Forever %s" % directionByInf - elif 1 < yearDelta: + elif 1 == yearDelta: return "%s year" % directionBy1 monthDelta = abs(targetDate.month - todaysDate.month) - if 2 < monthDelta: + if 1 < monthDelta: return "%s this year" % directionByN - elif 1 < monthDelta: + elif 1 == monthDelta: return "%s month" % directionBy1 dayDelta = abs(targetDate.day - todaysDate.day)