6
Functions for working with timestamps.
11
from datetime import datetime
13
from Translations import _, ngettext
16
"""Returns a datetime objects with the current timestamp."""
19
def locale_date(timestamp):
20
"""Returns a string with the date in the current locales format."""
21
return timestamp.strftime(locale.nl_langinfo(locale.D_FMT))
23
def locale_datetime(timestamp):
24
"""Returns a string with the date and time in the current locales format."""
25
return timestamp.strftime(locale.nl_langinfo(locale.D_T_FMT))
27
def locale_time(timestamp):
28
"""Returns a string with the time in the current locales format."""
29
return timestamp.strftime(locale.nl_langinfo(locale.T_FMT))
31
def time_ago_in_words(timestamp):
32
"""Returns a string in a format such as "less than a minute ago" or "2 hours ago"
33
the distance in time from timestamp to now. If the difference is more than
34
a day, returns locale_datetime instead."""
35
delta = now() - timestamp
44
return _("less than a minute ago")
47
return ngettext("1 minute ago", "{0} minutes ago", m).format(m)
50
return ngettext("1 hour ago", "{0} hours ago", h).format(h)
54
return locale_datetime(timestamp)