Source for file date.php

Documentation is available at date.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  HTML
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Extended Utility class for handling date display.
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  HTML
  17.  * @since       2.5
  18.  */
  19. abstract class JHtmlDate
  20. {
  21.     /**
  22.      * Function to convert a static time into a relative measurement
  23.      *
  24.      * @param   string  $date  The date to convert
  25.      * @param   string  $unit  The optional unit of measurement to return
  26.      *                          if the value of the diff is greater than one
  27.      * @param   string  $time  An optional time to compare to, defaults to now
  28.      *
  29.      * @return  string  The converted time string
  30.      *
  31.      * @since   2.5
  32.      */
  33.     public static function relative($date$unit null$time null)
  34.     {
  35.         if (is_null($time))
  36.         {
  37.             // Get now
  38.             $time JFactory::getDate('now');
  39.         }
  40.  
  41.         // Get the difference in seconds between now and the time
  42.         $diff strtotime($timestrtotime($date);
  43.  
  44.         // Less than a minute
  45.         if ($diff 60)
  46.         {
  47.             return JText::_('JLIB_HTML_DATE_RELATIVE_LESSTHANAMINUTE');
  48.         }
  49.  
  50.         // Round to minutes
  51.         $diff round($diff 60);
  52.  
  53.         // 1 to 59 minutes
  54.         if ($diff 60 || $unit == 'minute')
  55.         {
  56.             return JText::plural('JLIB_HTML_DATE_RELATIVE_MINUTES'$diff);
  57.         }
  58.  
  59.         // Round to hours
  60.         $diff round($diff 60);
  61.  
  62.         // 1 to 23 hours
  63.         if ($diff 24 || $unit == 'hour')
  64.         {
  65.             return JText::plural('JLIB_HTML_DATE_RELATIVE_HOURS'$diff);
  66.         }
  67.  
  68.         // Round to days
  69.         $diff round($diff 24);
  70.  
  71.         // 1 to 6 days
  72.         if ($diff || $unit == 'day')
  73.         {
  74.             return JText::plural('JLIB_HTML_DATE_RELATIVE_DAYS'$diff);
  75.         }
  76.  
  77.         // Round to weeks
  78.         $diff round($diff 7);
  79.  
  80.         // 1 to 4 weeks
  81.         if ($diff <= || $unit == 'week')
  82.         {
  83.             return JText::plural('JLIB_HTML_DATE_RELATIVE_WEEKS'$diff);
  84.         }
  85.  
  86.         // Over a month, return the absolute time
  87.         return JHtml::_('date'$date);
  88.     }
  89. }

Documentation generated on Tue, 19 Nov 2013 14:57:56 +0100 by phpDocumentor 1.4.3