Actually commit the file
This commit is contained in:
parent
64b92c4398
commit
bf29a98b82
24
sugar/date.py
Normal file
24
sugar/date.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user