pike.git / lib / modules / Web.pmod / Api.pmod / module.pmod

version» Context lines:

pike.git/lib/modules/Web.pmod/Api.pmod/module.pmod:1: + //! The @tt{WebApi@} has modules and classes for communicating with various + //! @tt{(RESTful)@} web api's such as @[WebApi.Facebook], + //! @[WebApi.Instagram], @[WebApi.Twitter] etc.    -  + //! Default user agent in HTTP calls + constant USER_AGENT = "Mozilla 4.0 (Pike/" + __REAL_MAJOR__ + "." + +  __REAL_MINOR__ + "." + __REAL_BUILD__ + ")"; +  + //! Human readable representation of @[timestamp]. + //! + //! Examples are: + //! + //! @code + //! 0 .. 30 seconds: Just now + //! 0 .. 120 seconds: Just recently + //! 121 .. 3600 seconds: x minutes ago + //! 3601 .. 86400 seconds: x hours ago + //! .. and so on + //! @endcode + //! + //! @param timestamp + string time_elapsed(int timestamp) + { +  int diff = (int) time(timestamp); +  int t; +  +  switch (diff) +  { +  case 0 .. 30: return "Just now"; +  case 31 .. 120: return "Just recently"; +  case 121 .. 3600: return sprintf("%d minutes ago",(int)(diff/60.0)); +  case 3601 .. 86400: +  t = (int)((diff/60.0)/60.0); +  return sprintf("%d hour%s ago", t, t > 1 ? "s" : ""); +  +  case 86401 .. 604800: +  t = (int)(((diff/60.0)/60.0)/24); +  return sprintf("%d day%s ago", t, t > 1 ? "s" : ""); +  +  case 604801 .. 31449600: +  t = (int)((((diff/60.0)/60.0)/24)/7); +  return sprintf("%d week%s ago", t, t > 1 ? "s" : ""); +  } +  +  return "A long time ago"; + }   Newline at end of file added.