[ Index ] |
|
Code source de Dotclear 2.0-beta6 |
1 <?php 2 # ***** BEGIN LICENSE BLOCK ***** 3 # This file is part of Clearbricks. 4 # Copyright (c) 2006 Olivier Meunier and contributors. All rights 5 # reserved. 6 # 7 # Clearbricks is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # Clearbricks is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with Clearbricks; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # 21 # ***** END LICENSE BLOCK ***** 22 23 class dt 24 { 25 public static function str($p,$ts=null,$tz=null) 26 { 27 if ($ts === NULL) { $ts = time(); } 28 29 $hash = '799b4e471dc78154865706469d23d512'; 30 $p = preg_replace('/(?<!%)%(a|A)/','{{'.$hash.'__$1%w__}}',$p); 31 $p = preg_replace('/(?<!%)%(b|B)/','{{'.$hash.'__$1%m__}}',$p); 32 33 if ($tz) { 34 $T = date('T'); 35 self::setTZ($tz); 36 } 37 38 $res = strftime($p,$ts); 39 40 if ($tz) { 41 self::setTZ($T); 42 } 43 44 $res = preg_replace_callback('/{{'.$hash.'__(a|A|b|B)([0-9]{1,2})__}}/',array('self','_callback'),$res); 45 46 return $res; 47 } 48 49 public static function dt2str($p,$dt,$tz=null) 50 { 51 return dt::str($p,strtotime($dt),$tz); 52 } 53 54 public static function iso8601($ts,$tz='UTC') 55 { 56 $o = self::getTimeOffset($tz,$ts); 57 $o = sprintf('%02u:%02u',$o/3600,($o%3600)/60); 58 return date('Y-m-d\\TH:i:s',$ts).'+'.$o; 59 } 60 61 public static function rfc822($ts,$tz='UTC') 62 { 63 # Get offset 64 $o = self::getTimeOffset($tz,$ts); 65 $o = sprintf('%02u%02u',$o/3600,($o%3600)/60); 66 67 return strftime('%a, %d %b %Y %H:%M:%S +'.$o,$ts); 68 } 69 70 public static function setTZ($tz) 71 { 72 if (function_exists('date_default_timezone_set')) { 73 date_default_timezone_set($tz); 74 return; 75 } 76 77 if (!ini_get('safe_mode')) { 78 putenv('TZ='.$tz); 79 } 80 } 81 82 public static function getTimeOffset($utc_tz,$ts=false) 83 { 84 if (!$ts) { 85 $ts = time(); 86 } 87 88 $server_tz = date('T',$ts); 89 $server_offset = date('Z',$ts); 90 91 self::setTZ($utc_tz); 92 $cur_offset = date('Z',$ts); 93 94 self::setTZ($server_tz); 95 96 return $cur_offset-$server_offset; 97 } 98 99 public static function toUTC($ts) 100 { 101 return $ts + self::getTimeOffset('UTC',$ts); 102 } 103 104 public static function addTimeZone($tz,$ts=false) 105 { 106 if (!$ts) { 107 $ts = time(); 108 } 109 110 return $ts + self::getTimeOffset($tz,$ts); 111 } 112 113 public static function getZones($flip=false,$groups=false) 114 { 115 try { 116 $tz = file(dirname(__FILE__).'/tz.dat'); 117 } catch (Exception $e) { 118 return array(); 119 } 120 121 $res = array(); 122 123 foreach ($tz as $v) 124 { 125 $v = trim($v); 126 if ($v) { 127 $res[$v] = str_replace('_',' ',$v); 128 } 129 } 130 131 if ($flip) { 132 $res = array_flip($res); 133 if ($groups) { 134 $tmp = array(); 135 foreach ($res as $k => $v) { 136 $g = explode('/',$k); 137 $tmp[$g[0]][$k] = $v; 138 } 139 $res = $tmp; 140 } 141 } 142 143 return $res; 144 } 145 146 private static function _callback($args) 147 { 148 $b = array(1=>'_Jan',2=>'_Feb',3=>'_Mar',4=>'_Apr',5=>'_May',6=>'_Jun', 149 7=>'_Jul',8=>'_Aug',9=>'_Sep',10=>'_Oct',11=>'_Nov',12=>'_Dec'); 150 151 $B = array(1=>'January',2=>'February',3=>'March',4=>'April', 152 5=>'May',6=>'June',7=>'July',8=>'August',9=>'September', 153 10=>'October',11=>'November',12=>'December'); 154 155 $a = array(1=>'_Mon',2=>'_Tue',3=>'_Wed',4=>'_Thu',5=>'_Fri', 156 6=>'_Sat',0=>'_Sun'); 157 158 $A = array(1=>'Monday',2=>'Tuesday',3=>'Wednesday',4=>'Thursday', 159 5=>'Friday',6=>'Saturday',0=>'Sunday'); 160 161 return __(${$args[1]}[(integer) $args[2]]); 162 } 163 } 164 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Feb 23 22:16:06 2007 | par Balluche grâce à PHPXref 0.7 |