From 7a641198433762c83a84e9464f103e33e38f8fa9 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sat, 18 Aug 2007 22:24:51 +0000 Subject: Start playing with unit tests. --- (limited to 'sugar/date.py') diff --git a/sugar/date.py b/sugar/date.py index 3b68818..3f4dcc2 100644 --- a/sugar/date.py +++ b/sugar/date.py @@ -21,12 +21,13 @@ import datetime class Date(object): """Date-object storing a simple time.time() float - - XXX not sure about the rationale for this class, - possibly it makes transfer over dbus easier? + + Useful to display dates in the UI in an + abbreviated and easy to read format. """ def __init__(self, timestamp): """Initialise via a timestamp (floating point value)""" + self._today = datetime.date.today() self._timestamp = timestamp def __str__(self): @@ -39,14 +40,13 @@ class Date(object): the year in the date. """ date = datetime.date.fromtimestamp(self._timestamp) - today = datetime.date.today() # FIXME localization - if date == today: + if date == self._today: result = 'Today' - elif date == today - datetime.timedelta(1): + elif date == self._today - datetime.timedelta(1): result = 'Yesterday' - elif date.year == today.year: + elif date.year == self._today.year: result = date.strftime('%B %d') else: result = date.strftime('%B %d, %Y') -- cgit v0.9.1