sugar-toolkit-gtk3/sugar/date.py

25 lines
691 B
Python
Raw Normal View History

2007-02-13 15:54:24 +01:00
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