|
@ -23,13 +23,11 @@ class Format |
|
|
static protected $date_format = 'd.m.Y'; |
|
|
static protected $date_format = 'd.m.Y'; |
|
|
static protected $date_time_format = 'H:i d.m.Y'; |
|
|
static protected $date_time_format = 'H:i d.m.Y'; |
|
|
static protected $timezone_offset = 0; |
|
|
static protected $timezone_offset = 0; |
|
|
static protected $cache_time = array(); |
|
|
|
|
|
|
|
|
|
|
|
/* money */ |
|
|
/* money */ |
|
|
static protected $decimal_point = ','; |
|
|
static protected $decimal_point = ','; |
|
|
static protected $currency_symbol = 'руб.'; |
|
|
static protected $currency_symbol = 'руб.'; |
|
|
static protected $frac_digits = 2; |
|
|
static protected $frac_digits = 2; |
|
|
static protected $cache_money = array(); |
|
|
|
|
|
|
|
|
|
|
|
static public function getCurrency() |
|
|
static public function getCurrency() |
|
|
{ |
|
|
{ |
|
@ -45,25 +43,19 @@ class Format |
|
|
*/ |
|
|
*/ |
|
|
static public function int2money($int = 0, $currency = false, $show_decimals = true) |
|
|
static public function int2money($int = 0, $currency = false, $show_decimals = true) |
|
|
{ |
|
|
{ |
|
|
$key = $int . '_' . (int)$currency . '_' . (int)$show_decimals; |
|
|
|
|
|
|
|
|
|
|
|
if(!isset(self::$cache_money[$key])){ |
|
|
|
|
|
self::$cache_money[$key] = number_format($int/100, ($show_decimals) ? self::$frac_digits : 0, self::$decimal_point, ' '); |
|
|
|
|
|
} |
|
|
|
|
|
return self::$cache_money[$key] . (($currency) ? ' '.self::$currency_symbol : ''); |
|
|
|
|
|
|
|
|
$money = number_format($int/100, ($show_decimals) ? self::$frac_digits : 0, self::$decimal_point, ' '); |
|
|
|
|
|
return $money . (($currency) ? ' '.self::$currency_symbol : ''); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static public function money2int($money) |
|
|
static public function money2int($money) |
|
|
{ |
|
|
{ |
|
|
$money = str_replace(' ', '', $money); |
|
|
$money = str_replace(' ', '', $money); |
|
|
if(!isset(self::$cache_money[$money])){ |
|
|
|
|
|
if(!strstr($money, self::$decimal_point) && !strstr($money, '.')){ |
|
|
|
|
|
self::$cache_money[$money] = (int)$money * 100; |
|
|
|
|
|
}else{ |
|
|
|
|
|
self::$cache_money[$money] = (int)str_replace(array('.', self::$decimal_point), '', $money); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if(!strstr($money, self::$decimal_point) && !strstr($money, '.')){ |
|
|
|
|
|
$int = (int)$money * 100; |
|
|
|
|
|
}else{ |
|
|
|
|
|
$int = (int)str_replace(array('.', self::$decimal_point), '', $money); |
|
|
} |
|
|
} |
|
|
return self::$cache_money[$money]; |
|
|
|
|
|
|
|
|
return $int; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -75,10 +67,8 @@ class Format |
|
|
*/ |
|
|
*/ |
|
|
static public function int2time($timestamp = 0) |
|
|
static public function int2time($timestamp = 0) |
|
|
{ |
|
|
{ |
|
|
if(!isset(self::$cache_time[$timestamp])){ |
|
|
|
|
|
self::$cache_time[$timestamp] = date(self::$time_format, $timestamp-self::$timezone_offset); |
|
|
|
|
|
} |
|
|
|
|
|
return self::$cache_time[$timestamp]; |
|
|
|
|
|
|
|
|
$time = date(self::$time_format, $timestamp - self::$timezone_offset); |
|
|
|
|
|
return $time; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -90,20 +80,18 @@ class Format |
|
|
*/ |
|
|
*/ |
|
|
static public function int2date($timestamp = 0, $hours = true) |
|
|
static public function int2date($timestamp = 0, $hours = true) |
|
|
{ |
|
|
{ |
|
|
if(!isset(self::$cache_time[$timestamp])){ |
|
|
|
|
|
self::$cache_time[$timestamp] = date(($hours) ? self::$date_time_format : self::$date_format , $timestamp); |
|
|
|
|
|
} |
|
|
|
|
|
return self::$cache_time[$timestamp]; |
|
|
|
|
|
|
|
|
$date = date(($hours) ? self::$date_time_format : self::$date_format , $timestamp); |
|
|
|
|
|
return $date; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static public function int2rusDate($timestamp = 0, $hours = false) |
|
|
static public function int2rusDate($timestamp = 0, $hours = false) |
|
|
{ |
|
|
{ |
|
|
$month = array("января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"); |
|
|
|
|
|
|
|
|
|
|
|
if(!isset(self::$cache_time[$timestamp])){ |
|
|
|
|
|
self::$cache_time[$timestamp] = ($hours) ? date("H:i d", $timestamp) . " " . $month[date("m", $timestamp) - 1] . " " .date("Y", $timestamp) : date("d", $timestamp) . " " . $month[date("m", $timestamp) - 1] . " " .date("Y", $timestamp); |
|
|
|
|
|
} |
|
|
|
|
|
return self::$cache_time[$timestamp]; |
|
|
|
|
|
|
|
|
$month = array('января', 'февраля', 'марта', |
|
|
|
|
|
'апреля', 'мая', 'июня', |
|
|
|
|
|
'июля', 'августа', 'сентября', |
|
|
|
|
|
'октября', 'ноября', 'декабря'); |
|
|
|
|
|
$date = ($hours) ? date('H:i d', $timestamp) . ' ' . $month[date('m', $timestamp) - 1] . ' ' .date('Y', $timestamp) : date('d', $timestamp) . ' ' . $month[date('m', $timestamp) - 1] . ' ' .date('Y', $timestamp); |
|
|
|
|
|
return $date; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -124,16 +112,14 @@ class Format |
|
|
*/ |
|
|
*/ |
|
|
static public function time2int($time) |
|
|
static public function time2int($time) |
|
|
{ |
|
|
{ |
|
|
if(!isset(self::$cache_time[$time])){ |
|
|
|
|
|
$elements = explode(':', $time); |
|
|
|
|
|
if(count($elements) == 3){ |
|
|
|
|
|
list($h, $m, $s) = $elements; |
|
|
|
|
|
self::$cache_time[$time] = ($h * 60 * 60) + ($m * 60) + $s; |
|
|
|
|
|
} else { |
|
|
|
|
|
self::$cache_time[$time] = (int)$time; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$elements = explode(':', $time); |
|
|
|
|
|
if(count($elements) == 3){ |
|
|
|
|
|
list($h, $m, $s) = $elements; |
|
|
|
|
|
$int = ($h * 60 * 60) + ($m * 60) + $s; |
|
|
|
|
|
} else { |
|
|
|
|
|
$int = (int)$time; |
|
|
} |
|
|
} |
|
|
return self::$cache_time[$time]; |
|
|
|
|
|
|
|
|
return $int; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -144,10 +130,7 @@ class Format |
|
|
*/ |
|
|
*/ |
|
|
static public function date2int($time) |
|
|
static public function date2int($time) |
|
|
{ |
|
|
{ |
|
|
if(!isset(self::$cache_time[$time])){ |
|
|
|
|
|
self::$cache_time[$time] = strtotime($time); |
|
|
|
|
|
} |
|
|
|
|
|
return self::$cache_time[$time]; |
|
|
|
|
|
|
|
|
return strtotime($time); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static public function int2phone($intphone) |
|
|
static public function int2phone($intphone) |
|
@ -155,20 +138,20 @@ class Format |
|
|
$intphone = (string) $intphone; |
|
|
$intphone = (string) $intphone; |
|
|
|
|
|
|
|
|
if (strlen($intphone) == 10) { |
|
|
if (strlen($intphone) == 10) { |
|
|
return '('.substr($intphone, 0, 3).') '.substr($intphone, 3, 3).'-'.substr($intphone, 6, 2).'-'.substr($intphone, 8, 2); |
|
|
|
|
|
|
|
|
return '(' . substr($intphone, 0, 3) . ') ' . substr($intphone, 3, 3) . '-' . substr($intphone, 6, 2) . '-' . substr($intphone, 8, 2); |
|
|
} elseif (strlen($intphone) == 7) { |
|
|
} elseif (strlen($intphone) == 7) { |
|
|
return substr($intphone, 0, 3).'-'.substr($intphone, 3, 2).'-'.substr($intphone, 5, 2); |
|
|
|
|
|
|
|
|
return substr($intphone, 0, 3) . '-' . substr($intphone, 3, 2) . '-' . substr($intphone, 5, 2); |
|
|
} |
|
|
} |
|
|
return ''; |
|
|
return ''; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static public function phone2int($phone) |
|
|
static public function phone2int($phone) |
|
|
{ |
|
|
{ |
|
|
$phone = str_replace(array(' ','-','(',')'), '', $phone); |
|
|
|
|
|
|
|
|
$phone = str_replace(array(' ', '-', '(', ')'), '', $phone); |
|
|
$phone_length = strlen($phone); |
|
|
$phone_length = strlen($phone); |
|
|
if (is_numeric($phone) && ($phone_length == 7 || $phone_length == 10)) { //бывают семизначные прямые номера
|
|
|
if (is_numeric($phone) && ($phone_length == 7 || $phone_length == 10)) { //бывают семизначные прямые номера
|
|
|
if ($phone_length == 7) { |
|
|
if ($phone_length == 7) { |
|
|
$phone = '495'.$phone; |
|
|
|
|
|
|
|
|
$phone = '495' . $phone; |
|
|
} |
|
|
} |
|
|
return $phone; |
|
|
return $phone; |
|
|
} |
|
|
} |
|
|