12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- class CatalyzDate {
- /**
- * CatalyzDate::formatShort()
- *
- * @param int $timestamp
- */
- public static function formatShort($timestamp) {
- $return = '';
- switch (sfContext::getInstance()->getI18N()->getCulture()) {
- case 'fr':
- $return = date('d/m/Y', $timestamp);
- break;
- default:
- $return = date('m/d/Y', $timestamp);
- }
- return $return;
- }
- /**
- * CatalyzDate::formatLong()
- *
- * @param int $timestamp
- */
- public static function formatLong($timestamp) {
- $return = '';
- switch (sfContext::getInstance()->getI18N()->getCulture()) {
- case 'fr':
- $return = utf8_encode(strftime('%e %B %Y', $timestamp));
- break;
- default:
- $return = date('F jS Y', $timestamp);
- }
- return $return;
- }
- public static function frenchDateFormatToTimestamp($date_format) {
- if (!preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $date_format)) {
- throw new Exception(sprintf('Le format de date suivant n\'est pas valide : "%s" (requis : JJ/MM/AAAA)', $date_format));
- return false;
- }
- list($d, $m, $y) = explode('/', $date_format);
- if (false === $timestamp = strtotime("$y-$m-$d")) {
- throw new Exception(sprintf('La date suivante n\'est pas valide : "%s"', $date_format));
- return false;
- }
- return $timestamp;
- }
- }
|