1

Possible Duplicate:
Timesensitive: Calculation of Yesterday is off

Maybe it is just me, but this seems like a bug.

I looked at one of my posts, and it says Asked Yesterday and the date (when hovered) says:
2013-01-08 but today's date is 2013-01-10. In my opinion, that is a 2 day span, so shouldn't it say 2 days ago or something similar?

Using php, this is how I would calculate it:

<?php
function date_posted($datePosted){
    $posted  = strtotime($datePosted);
    $now     = time();
    $seconds = ($now - $posted);
    $minutes = floor($seconds / 60);
    $days    = floor($minutes / 60);
    $years   = floor($days / 365);

    if($seconds <= 60){
        return "About a minute ago";
    }
    if($minutes < 60){
        return $minutes . " minute ago";
    }
    if($days <= 0){
        return "Today";
    }
    if($days <= 1){
        return "Yesterday";
    }
    if($days < 365){
        return $days . " days ago";
    }
    return $years . " years ago";
}

echo date_posted('2013-01-10 09:15:00');
echo "\n";

marked as duplicate by mmyers Jan 10 '13 at 16:18

This question was marked as an exact duplicate of an existing question.

  • Is it less than 48 hours though..? The times are relative. – ben is uǝq backwards Jan 10 '13 at 16:10
  • A link would be better :-) – Waffle's Crazy Peanut Jan 10 '13 at 16:10
  • Wait a bit more than an hour and all will be fine. – Bart Jan 10 '13 at 16:13
  • What does that mean? – Get Off My Lawn Jan 10 '13 at 16:13
  • The question was asked 1 day and 23 hours ago (roughly). The time is UTC time. It will change in about an hour to 2 days. – Bart Jan 10 '13 at 16:14
  • That seems like an odd way to calculate it IMO. Most sites calculate things like that based on the date and not the time. – Get Off My Lawn Jan 10 '13 at 16:15
  • Nothing wrong with being unique. – Bart Jan 10 '13 at 16:17
  • stackoverflow.com/a/12/13531 – mmyers Jan 10 '13 at 16:17
  • I agree that it is odd given the time is now 10/01/2013 16:17 I'd expect yesterday to mean anything from 09/01/2012 00:00 to 09/01/2012 23:59. After that I'd revert to hours. Guess SE people have their reasons though. – George Duckett Jan 10 '13 at 16:19
  • @mmyers my calculation is easier :) – Get Off My Lawn Jan 10 '13 at 16:44
  • 1
    @RyanNaddy: Doesn't that have the same problem? i.e. you're basing yesterday on the number of seconds since the current time, not midnight. I think you've got the same problem with today. i.e. Post at 17:00; treated as today until after 16:59 next day, UTC. I don't think a 'yesterday' or 'today' can work. – George Duckett Jan 10 '13 at 16:59
  • Fixed, I ran it through php and it works. – Get Off My Lawn Jan 10 '13 at 17:19

Browse other questions tagged .