Jeff PHP framework  0.99
Modular, extensible, OOP, MVC, lightweight php framework designed to ease the programmers in the development of web applications.
dtime.class.php
Go to the documentation of this file.
00001 <?php
00045 class dtime {
00046 
00052         private $_settings;
00053 
00057         private $_datetime;
00058 
00064         function __construct($registry) {
00065         
00066                 $this->_settings = new datetimeSettings();
00067 
00068         }
00069 
00076         public function now($format=null) {
00077 
00078                 $this->_datetime = new Datetime();
00079 
00080                 return $this->parseFormat($format);
00081 
00082         }
00083         
00095         public function view($date, $format=null) {
00096         
00097                 if(!$date) return '';
00098 
00099                 $this->_datetime = new datetime($date);
00100 
00101                 return $this->parseFormat($format);
00102 
00103         }
00104 
00111         private function parseFormat($format) {
00112                 
00113                 if($format=='date') $string = $this->_settings->date_format;
00114                 elseif($format=='time') $string = $this->_settings->time_format;
00115                 elseif($format=='datetime') $string = $this->_settings->datetime_format;
00116                 elseif($format) $string = $format;
00117                 else $string = $this->_settings->datetime_format;
00118 
00119                 $chars = array(
00120                         "#%(Y)#", // 4 digits year 
00121                         "#%(m)#", // 2 digits month
00122                         "#%(d)#", // 2 digits day
00123                         "#%(H)#", // 2 digits hour
00124                         "#%(i)#", // 2 digits minute
00125                         "#%(s)#", // 2 digits second
00126                         "#%(F)#", // full month name (January, ..., December)
00127                         "#%(M)#", // 3 digits month name (Jan, ..., Dec)
00128                         "#%(D)#", // 3 digits day name (Mon, ..., Sun)
00129                         "#%(y)#", // 2 digits year
00130                         "#%(U)#"  // Unix Timestamp
00131                 );
00132 
00133                 $result = preg_replace_callback($chars, array($this, 'applyFormat'), $string);
00134 
00135                 return $result;
00136         }
00137 
00144         private function applyFormat($matches) {
00145                 
00146                 return $this->_datetime->format($matches[1]);
00147 
00148         }
00149 
00150 }
00151 
00152 ?>