/**
 * Formatte une date ou une heure selon strftime
 *
 * @author Christophe Beyer <*****@*****.**>
 * @since 2012/02/22
 * @see http://php.net/manual/fr/function.strftime.php
 * @param string $string Date ou heure
 * @param string $format Format demandé
 * @return string
 */
function smarty_modifier_strftime($string, $format)
{
    if (preg_match('/^[0-9]{8}$/', $string)) {
        // Format YYYYMMDD
        $ts = CopixDateTime::yyyymmddToTimestamp($string);
    } else {
        throw new CopixException(sprintf('Date %s mal formatee', $string));
    }
    return strftime($format, $ts);
}
 public function testToTimestamp()
 {
     CopixI18N::setLang('fr');
     $this->assertEquals(220316400, CopixDateTime::yyyymmddToTimestamp('19761225'));
     $this->assertEquals(880930800, CopixDateTime::yyyymmddToTimestamp('19971201'));
     $this->assertEquals(220316400, CopixDateTime::dateTotimestamp('25/12/1976'));
     CopixI18N::setLang('en');
     $this->assertEquals(220316400, CopixDateTime::dateTotimestamp('12/25/1976'));
     $this->assertEquals(220352466, CopixDateTime::yyyymmddhhiissToTimestamp('19761225100106'));
     $this->assertEquals(880930866, CopixDateTime::yyyymmddhhiissToTimestamp('19971201000106'));
     CopixI18N::setLang('fr');
     $this->assertEquals(CopixDateTime::dateTotimestamp(false), null);
     $this->assertFalse(CopixDateTime::dateTotimestamp('19761225100106'));
     /*
     $this->assertEquals ('19761225000000',CopixDateTime::DateTimeToyyyymmddhhiiss('25/12/1976'));
     timeStampToyyyymmddhhiiss
     yyyymmddhhiissToTimeStamp
     */
 }
 /**
  * Construction du code HTML
  * On utilise également les modifications d'en tête HTML
  */
 public function process($pParams, $pContent = null)
 {
     extract($pParams);
     if (empty($name)) {
         throw new CopixTemplateTagException('[calendar] missing name parameter');
     }
     if (empty($image)) {
         $image = '"' . _resource("img/tools/calendar.png") . '"';
     } else {
         $image = '"' . $image . '"';
     }
     if (empty($extra)) {
         $extra = '';
     }
     if (empty($size)) {
         $size = 8;
     }
     if (!isset($mask)) {
         $mask = true;
     }
     _tag('mootools', array('plugin' => array('datepicker')));
     if ($mask) {
         _tag('mootools', array('plugin' => array('imask')));
         CopixHTMLHeader::addJsCode("\n             window.addEvent('domready', function () {\n                    new iMask({\n                         onFocus: function(obj) {\n                         },\n\n                         onBlur: function(obj) {\n                         },\n\n                         onValid: function(event, obj) {\n                         },\n\n                         onInvalid: function(event, obj) {\n                             if(!event.shift) {\n                             }\n                         }\n                     });\n             });\n             ", 'calendarmask');
     }
     if (empty($lang)) {
         $lang = CopixI18N::getLang();
     }
     if (empty($format)) {
         $format = str_replace(array('d', 'm', 'Y'), array('dd', 'mm', 'yyyy'), CopixI18N::getDateFormat('/'));
     } else {
         $format = strtolower($format);
     }
     $maskFormat = str_replace(array('d', 'm', 'y'), array('9', '9', '9'), $format);
     if (!empty($yyyymmdd)) {
         $value = date(str_replace(array('dd', 'mm', 'yyyy'), array('d', 'm', 'Y'), $format), CopixDateTime::yyyymmddToTimestamp($yyyymmdd));
     }
     if (!empty($timestamp)) {
         $value = date(str_replace(array('dd', 'mm', 'yyyy'), array('d', 'm', 'Y'), $format), $timestamp);
     }
     if (empty($sizeday)) {
         $sizeday = 3;
     }
     if (!isset($beforeyear)) {
         $beforeyear = 10;
     }
     if (!isset($afteryear)) {
         $afteryear = 10;
     }
     if (!isset($duration)) {
         $duration = 500;
     }
     if (!isset($closebuttonsrc)) {
         $closebuttonsrc = null;
     } else {
         $closebuttonsrc = _resource($closebuttonsrc);
     }
     if (!isset($draggable)) {
         $draggable = true;
     }
     $draggable = $draggable ? 'true' : 'false';
     if (!isset($title)) {
         $title = null;
     }
     if (empty($value)) {
         if ($mask) {
             $value = str_replace('9', '_', $maskFormat);
         } else {
             $value = null;
         }
     }
     $strMask = '';
     if ($mask) {
         $strMask = 'style="text-align:center" class="iMask" alt="{  type:\'fixed\', mask:\'' . $maskFormat . '\', stripMask: false }"';
     }
     $out = '<input type="text" id="' . $name . '" name="' . $name . '" value="' . _copix_utf8_htmlentities($value) . '" ' . $extra . ' size="' . $size . '" ';
     //name of the input.
     if (!empty($tabindex)) {
         $out .= ' tabindex="' . $tabindex . '" ';
     }
     $out .= $strMask . ' />' . "\n\r";
     $out .= '<script type="text/javascript">' . "\n\r";
     $out .= "\$('" . $name . "').makeDatePicker({draggable:{$draggable}, title: '" . str_replace("'", "\\'", $title) . "', closebuttonsrc: '" . $closebuttonsrc . "', value: '" . $value . "', format: '" . $format . "', language: '" . $lang . "', sizeday:" . $sizeday . ", beforeyear:" . $beforeyear . ", afteryear:" . $afteryear . ", duration:" . $duration . ", imageCalendar:" . $image;
     //class du calendrier.
     if (!empty($classe)) {
         $out .= ', classe:"' . $classe . '"';
     }
     $out .= "});" . "\n\r";
     return $out .= '</script>';
 }