hustcc / timeago

:hourglass: Simple library used to format datetime with `*** time ago` statement. eg: "3 hours ago".
http://timeago.org
MIT License
223 stars 37 forks source link

Please include the future #1

Closed kseistrup closed 8 years ago

kseistrup commented 8 years ago

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.

hustcc commented 8 years ago

sorry, what is the meaning?

kseistrup commented 8 years ago
# -*- 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
hustcc commented 8 years ago

nice work, may be I should raise a exception, when date > now.

in 3 minutes may make user confused.

how is it?

kseistrup commented 8 years ago

“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.

hustcc commented 8 years ago

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.

hustcc commented 8 years ago

how to tranlate just now with negative? I translate it to a while, is it ok?