Displaying a "script last modified" timeframe

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

I'm developing a small script for a game I play occasionally and I've got a link to the development version of the script up in their forum for people to upload test data. I wanted to add a little marker on the bottom of the script that tells them how long ago the script was modified so I don't have to keep updating the forum thread with bug updates except for when something major has changed.

This is what I came up with. I know the get_included_files function includes the name of the files included/required as well as the file that did all of that including.

Anyone see any problems ?

PHP Code: [ Select ]
$oldest_include = 0;
foreach(get_included_files() as $key => $val)
{
   $oldest_include = max($oldest_include, filemtime($val));
}
printf('<p class="info">beta code last modified: %1$s ago.</p>', new rough_age(time() - $oldest_include));
  1. $oldest_include = 0;
  2. foreach(get_included_files() as $key => $val)
  3. {
  4.    $oldest_include = max($oldest_include, filemtime($val));
  5. }
  6. printf('<p class="info">beta code last modified: %1$s ago.</p>', new rough_age(time() - $oldest_include));


Here's the source for that rough_age class.

PHP Code: [ Select ]
class rough_age
{
   public $size;
   protected static $suffixes = array(
      'Years'   => '31536000',
      'Months' => '2592000',
      'Weeks'   => '604800',
      'Days'     => '86400',
      'Hours'   => '3600',
      'Minutes'      => '60',
      'Seconds'      => '1'
   );
 
   public function __construct($size = '0')
   {
      $this->size = (string)$size;
      return $this;
   }
 
 
   public function __toString()
   {
      $str = '';
      foreach(self::$suffixes as $suffix => $divisor)
      {
         if(bccomp($this->size, $divisor) > -1)
         {
            $num  = bcdiv($this->size, $divisor, 0);
            $this->size = bcsub($this->size, bcmul($num, $divisor));
            $str  .= "$num $suffix ";
         }
      }
      return strlen($str) ? $str : 'None';
   }
}
  1. class rough_age
  2. {
  3.    public $size;
  4.    protected static $suffixes = array(
  5.       'Years'   => '31536000',
  6.       'Months' => '2592000',
  7.       'Weeks'   => '604800',
  8.       'Days'     => '86400',
  9.       'Hours'   => '3600',
  10.       'Minutes'      => '60',
  11.       'Seconds'      => '1'
  12.    );
  13.  
  14.    public function __construct($size = '0')
  15.    {
  16.       $this->size = (string)$size;
  17.       return $this;
  18.    }
  19.  
  20.  
  21.    public function __toString()
  22.    {
  23.       $str = '';
  24.       foreach(self::$suffixes as $suffix => $divisor)
  25.       {
  26.          if(bccomp($this->size, $divisor) > -1)
  27.          {
  28.             $num  = bcdiv($this->size, $divisor, 0);
  29.             $this->size = bcsub($this->size, bcmul($num, $divisor));
  30.             $str  .= "$num $suffix ";
  31.          }
  32.       }
  33.       return strlen($str) ? $str : 'None';
  34.    }
  35. }
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

the only problem I see is "new rough_age". Sounds like a dietry suppliment :D

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 66 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.