Вход Регистрация
Файл: adultscript-2.0.3-pro/files/libraries/framework/date.php
Строк: 111
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VDate
{
    public static function 
compare($first, $second)
    {    
    }
    
    public static function 
difference($first, $second, $format='years')
    {
    }
    
    public static function 
age($birth_date)
    {
        list(
$Y, $m, $d) = explode('-', $birth_date);
        return (
date('md') < $m.$d ? date('Y')-$Y-1 : date('Y')-$Y );
    }

    public static function 
duration($seconds)
    {
        if (
$seconds >= 3600) {
            
$hours       = $seconds / 3600 % 24;
            
$minutes  = $seconds / 60 % 60;
            
$seconds  = $seconds % 60;
            
            return 
str_pad($hours, 2, 0, STR_PAD_LEFT).':'.
                   
str_pad($minutes, 2, 0, STR_PAD_LEFT).':'.
                   
str_pad($seconds, 2, 0, STR_PAD_LEFT);
        }
        
        
$minutes  = floor($seconds/60);
        
$seconds %= 60;
        
        return 
str_pad($minutes, 2, 0, STR_PAD_LEFT).':'.
               
str_pad($seconds, 2, 0, STR_PAD_LEFT);

//        return sprintf('%02d', $minutes).':'.sprintf('%02d', $seconds);
    
}
    
    public static function 
nice($unix_date)
    {
        if (!
is_numeric($unix_date)) {
            
$unix_date = strtotime($unix_date);
        }

        if (empty(
$unix_date)) {
            return 
'';
        }
        
        
$periods    = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');
        
$plurals    = array('seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years', 'decades');
          
$lengths    = array('60','60','24','7','4.35','12','10');
          
          
// i could save this in a static var and not call time() functione very time
          
$now        = time();
          
          if(
$now > $unix_date) {
              
$difference = $now - $unix_date;
            
$tense        = __('ago');
          } else {
              
$difference    = $unix_date - $now;
            
$tense        = __('from-now');
          }
   
          for (
$j = 0; $difference >= $lengths[$j] && $j < 6; $j++) {
              
$difference /= $lengths[$j];
          }
          
          
$difference = (int) round($difference);
          if (
$j === 2 && $difference < 24) {
              return 
'today';
          }
          
        
$period        = ($difference === 1) ? __($periods[$j]) : __($plurals[$j]);
        
          return 
"$difference $period $tense";
    }
    
    public static function 
format($date, $format='F j, Y h:i a')
    {
        if (
is_numeric($date)) {
            
$date = date('Y-m-d h:i:s', $date);
        }
        
        
$timestamp = strtotime($date);
        
        return 
date($format, $timestamp);
    }
    
    public static function 
time_to_seconds($timecode)
    {
        
$hours_end  = strpos($timecode, ':', 0);
        
$hours      = substr($timecode, 0, $hours_end);
        
$mins       = substr($timecode, $hours_end+1, 2);
        
$secs       = trim(substr($timecode, $hours_end+4));
        if (
$secs == '') {
            
$mins     = $hours;
            
$secs     = $mins;
            
$hours     = 0;
        }

        return (
$hours*3600) + ($mins*60) + $secs;
    }
    
    public static function 
seconds_to_time($seconds, $hours=TRUE, $custom=FALSE)
    {
        
$seconds = (int) $seconds;
        if (
$seconds === 0 ) {
            return;
        }
        
        
$format = ($hours === TRUE) ? 'H:i:s' : 'i:s';
        if (
$custom) {
            
$format = $custom;
        }
        
        return 
date($format, mktime(0, 0, $seconds, 0, 0));
    }
}
?>
Онлайн: 2
Реклама