Closed kseistrup closed 8 years ago
sorry, what is the meaning?
# -*- mode: python; coding: utf-8 -*-
import datetime
import timeago
delta = datetime.timedelta(seconds=3*60)
now = datetime.datetime.now()
past = now - delta
future = now + delta
# date < now
print(timeago.format(past, now)) # will print “3 minutes ago”
# date > now
print(timeago.format(future, now)) # will print “in 3 minutes”
# date == now
print(timeago.format(now, now)) # will print “just now”
# eof
nice work, may be I should raise a exception, when date > now
.
in 3 minutes
may make user confused.
how is it?
“In three minutes” is plain English and means “this will happen [after] 3 minutes from now”. It's “the opposite” of “3 minutes ago”.
Rather than limiting your module to only work with the past, my suggestion (and the reason why I opened this issue) is that you let it deal with the past, the present and the future. I will even go as far as suggesting that .format()
should be able to take a timedelta
as its sole argument such that a positive timedelta denotes the future, a negeative timedelta the past and a timedelta of zero the present.
thx for you suggestion, I will do it as below:
timeago.format(datetime)
timeago.format(timestamp)
timeago.format(datedelta)
timeago.format(date_string)
and support ago
and in
.
how to tranlate just now
with negative? I translate it to a while
, is it ok?
Please include the future so that the answer is “in X” if date > now, corresponding to “X ago” if date < now. And perhaps a “just now” if date == now.