lib.date.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear 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. # DotClear 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 DotClear; 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. class dt
  23. {
  24. function str($p,$ts=NULL)
  25. {
  26. if ($ts == NULL) { $ts = time(); }
  27. $hash = '799b4e471dc78154865706469d23d512';
  28. $p = preg_replace('/(?<!%)%(a|A)/','{{'.$hash.'__$1%w__}}',$p);
  29. $p = preg_replace('/(?<!%)%(b|B)/','{{'.$hash.'__$1%m__}}',$p);
  30. $res = strftime($p,$ts);
  31. $res = preg_replace_callback('/{{'.$hash.'__(a|A|b|B)([0-9]{1,2})__}}/',array('dt','_callback'),$res);
  32. return $res;
  33. }
  34. function dt2str($p,$dt)
  35. {
  36. return dt::str($p,strtotime($dt));
  37. }
  38. function iso8601($ts)
  39. {
  40. $tz = date('O',$ts);
  41. $tz = substr($tz,0,-2).':'.substr($tz,-2);
  42. return date('Y-m-d\\TH:i:s',$ts).$tz;
  43. }
  44. function _callback($args)
  45. {
  46. $b = array(1=>'Jan',2=>'Feb',3=>'Mar',4=>'Apr',5=>'May',6=>'Jun',
  47. 7=>'Jul',8=>'Aug',9=>'Sep',10=>'Oct',11=>'Nov',12=>'Dec');
  48. $B = array(1=>'January',2=>'February',3=>'March',4=>'April',
  49. 5=>'May',6=>'June',7=>'July',8=>'August',9=>'September',
  50. 10=>'October',11=>'November',12=>'December');
  51. $a = array(1=>'Mon',2=>'Tue',3=>'Wed',4=>'Thu',5=>'Fri',
  52. 6=>'Sat',0=>'Sun');
  53. $A = array(1=>'Monday',2=>'Tuesday',3=>'Wednesday',4=>'Thursday',
  54. 5=>'Friday',6=>'Saturday',0=>'Sunday');
  55. return __(${$args[1]}[(integer) $args[2]]);
  56. }
  57. }
  58. ?>