I posted the following question yesterday: http://serverfault.com/questions/217098/list-all-documents-webparts-and-sites-using-a-certain-solution-in-sharepoint-20 When you look at the site though, it shows "Asked 23 hours ago" in the signature area where my user card is. On the right side however it says "asked today."

I am guessing it says "today" if the difference between DateTime.Now and the original post date is less than 24 hours, but this is incorrect. This is likely a problem on all of stack exchange. I don't believe this is accurate behavior for noda-time, so I am guessing stack exchange doesn't use it; might be a nice addition though.

Here is a screenshot showing what actually was displayed in case this isn't seen until the time rolls over: alt text

Expected Behavior: I would kind of expect the behavior to be something like the following. This is hardly a complete example though since it doesn't deal with things like smaller or larger time spans (weeks, months, years, minutes, seconds) that would need different output. It also isn't perfect because there are situations here that are going to still be ambiguous or wrong. This is why I would think noda-time would be the way to go here:

if (diff_hours < 12) 
    dashH = string.Format("{0} hours ago", diff_hours);
else if (diff_hours >= 12 && diff_hours < 24 && op_day != now_day) 
    dashH = "Yesterday"; 
else if (diff_hours >= 12 && diff_hours < 24 && op_day == now_day) 
    dashH = "Today"; 
else if (diff_hours >= 24 && diff_hours < 48)
    dashH = "Yesterday";
else if (diff_hours >= 48)
    dashH = String.Format("{0} days ago", (int)diff_hours / 2);

Right now it seems like the behavior is more like the following, and while it is still an approximate, it allows for confusion with "yesterday" and "today" being possible on days that aren't actually "yesterday" or "today":

if (diff_hours < 24) 
    dashH = "Today"; 
else if (diff_hours >= 24 && diff_hours < 48) 
    dashH = "Yesterday"; 
else if (diff_hours >= 48)
    dashH = String.Format("{0} days ago", (int)diff_hours / 2);
link
feedback

1 Answer

I am guessing it says "today" if the difference between DateTime.Now and the original post date is less than 24 hours, but this is incorrect.

I don't think it's incorrect. What do you think the behavior should be?

link
If I post at 3pm on a Wednesday and then edit that post at 2pm the following Thursday, then it should say "edited yesterday" rather than "edited today" as it does in my example. While 23 hours is less than a day old, it has a completely different meaning to say "yesterday" vs "today" based on that timespan. In my example I posted my question at around 12pm on 12/29/2010. Showing "asked 23 hours ago" is correct, but saying "asked today" is completely wrong; it should say "asked yesterday". – tcnolan Dec 31 '10 at 1:00
1  
@tnolan doesn't this depend on your local time zone? We use UTC exclusively. – Jeff Atwood Dec 31 '10 at 1:50
My timezone is irrelevant then isn't it? If you use UTC exclusively, then my original post was made on 12/29/2010 at 11:58 EST (16:58 UTC). The screenshot I took was on 12/30/2010 at 11:12 EST (16:12 UTC). Saying "asked 23 hours ago" in the user card area is accurate. Saying "asked today" on the right side under the tag area is not accurate though since 12/29 was yesterday. – tcnolan Dec 31 '10 at 4:57
@tnolan - These "yesterday/today/X minutes ago" phrases are just intended to give you a "ballpark" idea when things were posted. If you want the exact timestamp, just hover over the word and the timestamp will be displayed via the span title attribute. – ErikA Dec 31 '10 at 21:34
@ErikA - I know they are meant as ballpark, but that doesn't change the fact that it was displaying incorrect information; "Today" and "yesterday" have very different meanings, even when speaking in ballpark terms. It's still a bug in my eyes. – tcnolan Dec 31 '10 at 22:43
@Jeff, I deleted my most recent comment and put in an edit to the OP that includes the expected behavior. – tcnolan Jan 2 '11 at 3:16
feedback

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged