CatalyzDate.class.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. class CatalyzDate {
  3. /**
  4. * CatalyzDate::formatShort()
  5. *
  6. * @param int $timestamp
  7. */
  8. public static function formatShort($timestamp) {
  9. $return = '';
  10. switch (sfContext::getInstance()->getI18N()->getCulture()) {
  11. case 'fr':
  12. $return = date('d/m/Y', $timestamp);
  13. break;
  14. default:
  15. $return = date('m/d/Y', $timestamp);
  16. }
  17. return $return;
  18. }
  19. /**
  20. * CatalyzDate::formatLong()
  21. *
  22. * @param int $timestamp
  23. */
  24. public static function formatLong($timestamp) {
  25. $return = '';
  26. switch (sfContext::getInstance()->getI18N()->getCulture()) {
  27. case 'fr':
  28. $return = utf8_encode(strftime('%e %B %Y', $timestamp));
  29. break;
  30. default:
  31. $return = date('F jS Y', $timestamp);
  32. }
  33. return $return;
  34. }
  35. public static function frenchDateFormatToTimestamp($date_format) {
  36. if (!preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $date_format)) {
  37. throw new Exception(sprintf('Le format de date suivant n\'est pas valide : "%s" (requis : JJ/MM/AAAA)', $date_format));
  38. return false;
  39. }
  40. list($d, $m, $y) = explode('/', $date_format);
  41. if (false === $timestamp = strtotime("$y-$m-$d")) {
  42. throw new Exception(sprintf('La date suivante n\'est pas valide : "%s"', $date_format));
  43. return false;
  44. }
  45. return $timestamp;
  46. }
  47. }