Ejemplo n.º 1
0
 public function timeZoneSerialization()
 {
     date_default_timezone_set('Europe/Athens');
     $date = new Date('2007-11-20 21:45:33 Europe/Berlin');
     $this->assertEquals('Europe/Berlin', $date->getTimeZone()->getName());
     $this->assertEquals('+0100', $date->getOffset());
     $copy = unserialize(serialize($date));
     $this->assertEquals('+0100', $copy->getOffset());
 }
Ejemplo n.º 2
0
 /**
  * Formats a 
  *
  * @param   util.Date d
  * @return  string
  */
 public function format(Date $d)
 {
     $out = '';
     foreach ($this->format as $token) {
         switch ($token) {
             case '%Y':
                 $out .= $d->getYear();
                 break;
             case '%m':
                 $out .= str_pad($d->getMonth(), 2, '0', STR_PAD_LEFT);
                 break;
             case '%d':
                 $out .= str_pad($d->getDay(), 2, '0', STR_PAD_LEFT);
                 break;
             case '%H':
                 $out .= str_pad($d->getHours(), 2, '0', STR_PAD_LEFT);
                 break;
             case '%M':
                 $out .= str_pad($d->getMinutes(), 2, '0', STR_PAD_LEFT);
                 break;
             case '%S':
                 $out .= str_pad($d->getSeconds(), 2, '0', STR_PAD_LEFT);
                 break;
             case '%p':
                 $h = $d->getHours();
                 $out .= $h >= 12 ? 'PM' : 'AM';
                 break;
             case '%I':
                 $out .= str_pad($d->getHours() % 12, 2, '0', STR_PAD_LEFT);
                 break;
             case '%z':
                 $out .= $d->getTimeZone()->getName();
                 break;
             case '%Z':
                 $out .= $d->getOffset();
                 break;
             case is_array($token):
                 $out .= $token[1][call_user_func([$d, 'get' . $token[0]]) - 1];
                 break;
             default:
                 $out .= $token;
         }
     }
     return $out;
 }