Esempio n. 1
0
 /**
  * (non-PHPdoc)
  * @see Constraint::doValidate()
  */
 public function doValidate($ctx)
 {
     $value = $ctx->getRequest()->getString($this->getName(), '');
     // Validate only if there is a value
     if (!$value) {
         return true;
     }
     $converter = DataConverter::getInstance();
     if (!$converter->parseDate($value)) {
         $msg = sprintf(Application::getTranslator()->_('The field %1$s must be a valid date'), $this->getLabel());
         $this->addFieldError($ctx, $this->getName(), $msg);
         return false;
     }
     return true;
 }
 /**
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->converter = \DataConverter::getInstance();
 }
Esempio n. 3
0
 /**
  * Get the date value associated with the given key.
  *
  * @param String $key the key
  * @param timestamp $defaultValue value to return in case the key doesn't exist in the request.
  * @param String $timezone If not passed, the user timezone will be used.
  * @return timestamp Unix timestamp - the number of seconds since January 1 1970 00:00:00 GMT
  */
 public function getDate($key, $defaultValue = self::UNDEFINED, $timezone = null)
 {
     try {
         $str = $this->getString($key);
         $converter = DataConverter::getInstance();
         if ($timezone && $converter->getTimeZoneName() != $timezone) {
             $converter = new DataConverter($timezone);
         }
         return $converter->parseDate($str);
     } catch (UndefinedKeyException $e) {
         if ($defaultValue != self::UNDEFINED) {
             return $defaultValue;
         }
         throw $e;
     }
 }