Re: Date Format: ex: about 2 hours ago

2008-12-24 Thread Matthew

 All of the clients
and the web post friendly things like about 2 hours ago. Can anyone
provide a standard routine for converting the pure date element into
these english strings?

take a look at the way Rails does it as well,
http://github.com/rails/rails/tree/master/actionpack/lib/action_view/helpers/date_helper.rb

It's quite a common thing,
so perhaps you should look at the source for Struts,
or some similar java framework,
see if you can steal the code directly from there.


Re: Date Format: ex: about 2 hours ago

2008-12-24 Thread Chad Etzel
Here's the code I have been using for such a task (written in javascript).
Consider it a Christmas present :)

var getdatediff = function (now_ms, gmt)
{
  var dt_ms = Date.parse(gmt);

  var delta = now_ms - dt_ms;
  delta = Math.floor(delta / 1000);  // turn into seconds

  if (delta  86400) {
return '' + Math.floor(delta/86400) + ' days ago';
  } else if (delta  3600) {
return '' + Math.floor(delta/3600) + ' hours ' + Math.floor(delta/60) +
' minutes ago';
  } else if (delta  60) {
return '' + Math.floor(delta/60) + ' minutes ' + (delta % 60) + '
seconds ago';
  } else { // seconds
return '' + (delta % 60) + ' seconds ago';
  }

}


var main_or_whatever = function()
{

  //it is assumed tweet_arr is an array with tweets returned from a .json
API call or something...

  var tstamp = new Date(tweet_arr.results[i].created_at).toLocaleString();
  var now = new Date();
  var now_ms = now.getTime();

  var datediff = getdatediff(now_ms, tstamp);

  //print datediff in some fashion
  document.write(datediff);

}


-Chad

On Wed, Dec 24, 2008 at 6:08 AM, Matthew matthewrudyjac...@gmail.comwrote:


  All of the clients
 and the web post friendly things like about 2 hours ago. Can anyone
 provide a standard routine for converting the pure date element into
 these english strings?

 take a look at the way Rails does it as well,

 http://github.com/rails/rails/tree/master/actionpack/lib/action_view/helpers/date_helper.rb

 It's quite a common thing,
 so perhaps you should look at the source for Struts,
 or some similar java framework,
 see if you can steal the code directly from there.



Re: Date Format: ex: about 2 hours ago

2008-12-24 Thread Cameron Kaiser

 Here's the code I have been using for such a task (written in javascript).
 Consider it a Christmas present :)

Very elegant. :)

-- 
 personal: http://www.cameronkaiser.com/ --
  Cameron Kaiser * Floodgap Systems * www.floodgap.com * ckai...@floodgap.com
-- A kindness done today is the surest way to a brighter tomorrow. -- Anonymous