diff options
author | Marco Pesenti Gritti <mpg@redhat.com> | 2007-02-13 14:54:24 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <mpg@redhat.com> | 2007-02-13 14:54:24 (GMT) |
commit | bf29a98b829c2b102d2b1f56edab0a292bd912df (patch) | |
tree | 52580c03f571db4b75e08210b16bc216961a2684 /sugar | |
parent | 64b92c439897dd95ae4bb4b02e096a7a22836de8 (diff) |
Actually commit the file
Diffstat (limited to 'sugar')
-rw-r--r-- | sugar/date.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/sugar/date.py b/sugar/date.py new file mode 100644 index 0000000..331124b --- /dev/null +++ b/sugar/date.py @@ -0,0 +1,24 @@ +import datetime + +class Date(object): + def __init__(self, timestamp): + self._timestamp = timestamp + + def __str__(self): + date = datetime.date.fromtimestamp(self._timestamp) + today = datetime.date.today() + + # FIXME localization + if date == today: + result = 'Today' + elif date == today - datetime.timedelta(1): + result = 'Yesterday' + elif date.year == today.year: + result = date.strftime('%B %d') + else: + result = date.strftime('%B %d, %Y') + + time = datetime.datetime.fromtimestamp(self._timestamp) + result = result + ', ' + time.strftime('%I:%M %p') + + return result |