1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- class dt
- {
- function str($p,$ts=NULL)
- {
- if ($ts == NULL) { $ts = time(); }
-
- $hash = '799b4e471dc78154865706469d23d512';
- $p = preg_replace('/(?<!%)%(a|A)/','{{'.$hash.'__$1%w__}}',$p);
- $p = preg_replace('/(?<!%)%(b|B)/','{{'.$hash.'__$1%m__}}',$p);
-
- $res = strftime($p,$ts);
-
- $res = preg_replace_callback('/{{'.$hash.'__(a|A|b|B)([0-9]{1,2})__}}/',array('dt','_callback'),$res);
-
- return $res;
- }
-
- function dt2str($p,$dt)
- {
- return dt::str($p,strtotime($dt));
- }
-
- function iso8601($ts)
- {
- $tz = date('O',$ts);
- $tz = substr($tz,0,-2).':'.substr($tz,-2);
- return date('Y-m-d\\TH:i:s',$ts).$tz;
- }
-
- function _callback($args)
- {
- $b = array(1=>'Jan',2=>'Feb',3=>'Mar',4=>'Apr',5=>'May',6=>'Jun',
- 7=>'Jul',8=>'Aug',9=>'Sep',10=>'Oct',11=>'Nov',12=>'Dec');
-
- $B = array(1=>'January',2=>'February',3=>'March',4=>'April',
- 5=>'May',6=>'June',7=>'July',8=>'August',9=>'September',
- 10=>'October',11=>'November',12=>'December');
-
- $a = array(1=>'Mon',2=>'Tue',3=>'Wed',4=>'Thu',5=>'Fri',
- 6=>'Sat',0=>'Sun');
-
- $A = array(1=>'Monday',2=>'Tuesday',3=>'Wednesday',4=>'Thursday',
- 5=>'Friday',6=>'Saturday',0=>'Sunday');
-
- return __(${$args[1]}[(integer) $args[2]]);
- }
- }
- ?>
|