Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Use of the term "Yesterday" is incorrect #15

Closed
chrisben opened this issue May 13, 2013 · 6 comments
Closed

Use of the term "Yesterday" is incorrect #15

chrisben opened this issue May 13, 2013 · 6 comments

Comments

@chrisben
Copy link
Collaborator

Looking at the code, I see that the library returns the string "yesterday" if the difference in time between the given date and now is more than 24 hours ago but less than 2*24 hours ago.
Saying "yesterday" is wrong because the given date could be actually the day before yesterday.
For instance:

Date: Monday 11am
Now: Wednesday 10am
difference : 1day and 23hours
=> returns "Yesterday", but "Yesterday" here was Tuesday.

I suggest using "calendar days" instead of just plain days (=24 hours) to calculate the difference. Yesterday will have its true meaning then.

For an example on how to do this, see the second answer: http://stackoverflow.com/questions/4739483/number-of-days-between-two-nsdates

By the way, same problem with "last month" / "last year" => months are not always 31 days long, and years are not 365.25 days long.

@kevinlawler
Copy link
Owner

This is not an oversight but intentional. The intent is to express approximately how far in the past something happened, not the exact interval. A comment written a two years ago is antique in internet terms. It doesn't matter if it is really 20 months old or 28 months old. This is acceptable in the context of approximations. Many users are even accustomed to this particular behavior, for better or worse.

As another example of issues we ignore, when it is 2AM and something occurred at 11PM the previous day, is it more accurate to say it happened 3 hours ago, or that it happened yesterday?

You could improve accuracy in a superficial way by grossly complicating the code. Such a project, if done thoroughly, might be interesting. If I remember correctly when I originally looked at it, it is unavoidably ambiguous. You cannot arrive at meaningful consensus. Regardless, if it was done well enough I would be open to merging it.

@chrisben
Copy link
Collaborator Author

I agree that for anything longer than weeks approximation can be enough, but between "yesterday" and "the day before yesterday" people care about some precision.

In your example, both "3 hours ago" and "yesterday" are correct: the second is less precise but nevertheless correct. I wouldn't mind seeing one instead of the other one as long as it's correct.

In my example, "yesterday" wasn't correct at all: it was actually the day before yesterday.

The code won't be more complex by checking calendar days instead of plain 24 hours, I'll do the change on a fork later to show you how it can be done in a simple manner using tools given by the iOS sdk just for that: NSDateComponents and NSDayCalendarUnit.

@kevinlawler
Copy link
Owner

OK, I like this so far.

Anything that makes a precise decision about an ambiguous window should be grouped and clearly exposed.

@kevinlawler
Copy link
Owner

I've added @chrisben as a collaborator on the repo.

@chrisben
Copy link
Collaborator Author

Thanks. I will have a look at that this week end - I hope.
I wil also look into how to add the ability to customise the output strings or the precision logic. I will work on a fork first, and if you're happy with those changes, i'll merge them into this library.
Cheers.

@chrisben
Copy link
Collaborator Author

As I dig into this, I see now that the problem is deeper than just "yesterday".

There's a real difference between saying "one day ago" and "yesterday", as it is to say "one year ago" and "last year".

For instance on the 2nd of January "last year" means "any time between 2 days ago and 367 days ago". When you say "one year ago" you're saying "any time between 365 days ago and 365*2 days ago".

This is a huge difference and can lead to misunderstandings.

For that reason, I will create two new methods:

  • dateTimeAgo that will only return "{value} {unit} ago" strings.
  • dateTimeUntilNow that will return "yesterday" / "last week" / "last month"... which is less precise perhaps but more natural (that's how we speak in common terms instead of absolute 24 hour periods) - for less than a few hours difference, same behaviour as dateTimeAgo, or could be less precise with just "today". Perhaps I'll even introduce a: "this morning".

timeAgo will be kept as it is now for compatibility reasons when people upgrade this library.

I'll commit something today (i.e less than 12 hours from now ;) ) to my fork for you to check.

chrisben pushed a commit to chrisben/NSDate-TimeAgo that referenced this issue May 18, 2013
As discussed in issue kevinlawler#15, added two new methods that can be used as
drop-in replacement to timeAgo: dateTimeAgo and dateTimeUntilNow. See
header file for more details about those methods.

Also refactored some code in timeAgo to simplify it.
chrisben added a commit that referenced this issue May 20, 2013
Issue #15 : added 2 new methods
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants