title: Fuzzy Date algorithm in Objective-C
body: <p>I would like to write a fuzzy date method for calculating dates in Objective-C for iPhone. There is a popular explanation here: </p>
  
  <p><a href="https://stackoverflow.com/questions/11/how-do-i-calculate-relative-time">Calculate relative time in C#</a></p>
  
  <p>However it contains missing arguments. How could this be used in Objective-C?. Thanks.</p>
  
  <pre><code>const int SECOND = 1;
  const int MINUTE = 60 * SECOND;
  const int HOUR = 60 * MINUTE;
  const int DAY = 24 * HOUR;
  const int MONTH = 30 * DAY;
  
  if (delta &lt; 1 * MINUTE)
  {
    return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago";
  }
  if (delta &lt; 2 * MINUTE)
  {
    return "a minute ago";
  }
  if (delta &lt; 45 * MINUTE)
  {
    return ts.Minutes + " minutes ago";
  }
  if (delta &lt; 90 * MINUTE)
  {
    return "an hour ago";
  }
  if (delta &lt; 24 * HOUR)
  {
    return ts.Hours + " hours ago";
  }
  if (delta &lt; 48 * HOUR)
  {
    return "yesterday";
  }
  if (delta &lt; 30 * DAY)
  {
    return ts.Days + " days ago";
  }
  if (delta &lt; 12 * MONTH)
  {
    int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30));
    return months &lt;= 1 ? "one month ago" : months + " months ago";
  }
  else
  {
    int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365));
    return years &lt;= 1 ? "one year ago" : years + " years ago";
  }
  </code></pre>