public function convertToPHPValue($value, AbstractPlatform $platform) { if ($value === null) { return null; } $dateTimeFormatString = \Zend_Locale_Format::convertPhpToIsoFormat($platform->getDateTimeFormatString()); $val = new \Zend_Date($value, $dateTimeFormatString); if (!$val) { throw ConversionException::conversionFailed($value, $this->getName()); } return $val; }
/** * Internal function for checking the options array of proper input values * See {@link setOptions()} for details. * * @param array $options Array of options, keyed by option name: format_type = 'iso' | 'php', fix_date = true | false, * locale = Zend_Locale | locale string, precision = whole number between -1 and 30 * @throws Zend_Locale_Exception * @return Options array if no option was given */ private static function _checkOptions(array $options = array()) { if (count($options) == 0) { return self::$_options; } foreach ($options as $name => $value) { $name = strtolower($name); if ($name !== 'locale') { if (gettype($value) === 'string') { $value = strtolower($value); } } switch ($name) { case 'number_format': if ($value == Zend_Locale_Format::STANDARD) { $locale = self::$_options['locale']; if (isset($options['locale'])) { $locale = $options['locale']; } $options['number_format'] = Zend_Locale_Data::getContent($locale, 'decimalnumber'); } else { if (gettype($value) !== 'string' and $value !== NULL) { // require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unknown number format type '" . gettype($value) . "'. " . "Format '{$value}' must be a valid number format string."); } } break; case 'date_format': if ($value == Zend_Locale_Format::STANDARD) { $locale = self::$_options['locale']; if (isset($options['locale'])) { $locale = $options['locale']; } $options['date_format'] = Zend_Locale_Format::getDateFormat($locale); } else { if (gettype($value) !== 'string' and $value !== NULL) { // require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unknown dateformat type '" . gettype($value) . "'. " . "Format '{$value}' must be a valid ISO or PHP date format string."); } else { if (isset($options['format_type']) === true and $options['format_type'] == 'php' or isset($options['format_type']) === false and self::$_options['format_type'] == 'php') { $options['date_format'] = Zend_Locale_Format::convertPhpToIsoFormat($value); } } } break; case 'format_type': if ($value != 'php' && $value != 'iso') { // require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unknown date format type '{$value}'. Only 'iso' and 'php'" . " are supported."); } break; case 'fix_date': if ($value !== true && $value !== false) { // require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Enabling correction of dates must be either true or false" . "(fix_date='{$value}')."); } break; case 'locale': $options['locale'] = Zend_Locale::findLocale($value); break; case 'cache': if ($value instanceof Zend_Cache_Core) { Zend_Locale_Data::setCache($value); } break; case 'disablecache': Zend_Locale_Data::disableCache($value); break; case 'precision': if ($value === NULL) { $value = -1; } if ($value < -1 || $value > 30) { // require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("'{$value}' precision is not a whole number less than 30."); } break; default: // require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unknown option: '{$name}' = '{$value}'"); break; } } return $options; }
/** * Checks if the given date is a real date or datepart. * Returns false if a expected datepart is missing or a datepart exceeds its possible border. * But the check will only be done for the expected dateparts which are given by format. * If no format is given the standard dateformat for the actual locale is used. * f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY' * * @param string|array|Zend_Date $date Date to parse for correctness * @param string $format (Optional) Format for parsing the date string * @param string|Zend_Locale $locale (Optional) Locale for parsing date parts * @return boolean True when all date parts are correct */ public static function isDate($date, $format = null, $locale = null) { if (!is_string($date) && !is_numeric($date) && !$date instanceof Zend_Date && !is_array($date)) { return false; } if ($format !== null && $format != 'ee' && $format != 'ss' && $format != 'GG' && $format != 'MM' && $format != 'EE' && $format != 'TT' && Zend_Locale::isLocale($format, null, false)) { $locale = $format; $format = null; } $locale = Zend_Locale::findLocale($locale); if ($format === null) { $format = Zend_Locale_Format::getDateFormat($locale); } else { if (self::$_options['format_type'] == 'php' && !defined($format)) { $format = Zend_Locale_Format::convertPhpToIsoFormat($format); } } $format = self::_getLocalizedToken($format, $locale); if (!is_array($date)) { try { $parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale, 'date_format' => $format, 'format_type' => 'iso', 'fix_date' => false)); } catch (Zend_Locale_Exception $e) { // Date can not be parsed return false; } } else { $parsed = $date; } if ((strpos($format, 'Y') !== false or strpos($format, 'y') !== false) and !isset($parsed['year'])) { // Year expected but not found return false; } if (strpos($format, 'M') !== false and !isset($parsed['month'])) { // Month expected but not found return false; } if (strpos($format, 'd') !== false and !isset($parsed['day'])) { // Day expected but not found return false; } if ((strpos($format, 'H') !== false or strpos($format, 'h') !== false) and !isset($parsed['hour'])) { // Hour expected but not found return false; } if (strpos($format, 'm') !== false and !isset($parsed['minute'])) { // Minute expected but not found return false; } if (strpos($format, 's') !== false and !isset($parsed['second'])) { // Second expected but not found return false; } // Set not given dateparts if (isset($parsed['hour']) === false) { $parsed['hour'] = 12; } if (isset($parsed['minute']) === false) { $parsed['minute'] = 0; } if (isset($parsed['second']) === false) { $parsed['second'] = 0; } if (isset($parsed['month']) === false) { $parsed['month'] = 1; } if (isset($parsed['day']) === false) { $parsed['day'] = 1; } if (isset($parsed['year']) === false) { $parsed['year'] = 1970; } if (self::isYearLeapYear($parsed['year'])) { $parsed['year'] = 1972; } else { $parsed['year'] = 1971; } $date = new self($parsed, null, $locale); $timestamp = $date->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $parsed['month'], $parsed['day'], $parsed['year']); if ($parsed['year'] != $date->date('Y', $timestamp)) { // Given year differs from parsed year return false; } if ($parsed['month'] != $date->date('n', $timestamp)) { // Given month differs from parsed month return false; } if ($parsed['day'] != $date->date('j', $timestamp)) { // Given day differs from parsed day return false; } if ($parsed['hour'] != $date->date('G', $timestamp)) { // Given hour differs from parsed hour return false; } if ($parsed['minute'] != $date->date('i', $timestamp)) { // Given minute differs from parsed minute return false; } if ($parsed['second'] != $date->date('s', $timestamp)) { // Given second differs from parsed second return false; } return true; }
/** * Checks if the given date is a real date or datepart. * Returns false if a expected datepart is missing or a datepart exceeds its possible border. * But the check will only be done for the expected dateparts which are given by format. * If no format is given the standard dateformat for the actual locale is used. * f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY' * * @param string $date Date to parse for correctness * @param string $format (Optional) Format for parsing the date string * @param string|Zend_Locale $locale (Optional) Locale for parsing date parts * @return boolean True when all date parts are correct */ public static function isDate($date, $format = null, $locale = null) { if (!is_string($date) and !is_numeric($date) and !$date instanceof Zend_Date) { return false; } if ($format !== null and Zend_Locale::isLocale($format, null, false)) { $locale = $format; $format = null; } if (empty($locale)) { require_once 'Zend/Registry.php'; if (Zend_Registry::isRegistered('Zend_Locale') === true) { $locale = Zend_Registry::get('Zend_Locale'); } } if (!Zend_Locale::isLocale($locale, true, false)) { if (!Zend_Locale::isLocale($locale, false, false)) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("Given locale ({$locale}) does not exist", (string) $locale); } $locale = new Zend_Locale($locale); } $locale = (string) $locale; if ($format === null) { $format = Zend_Locale_Format::getDateFormat($locale); } else { if (self::$_options['format_type'] == 'php') { $format = Zend_Locale_Format::convertPhpToIsoFormat($format); } } try { $parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale, 'date_format' => $format, 'format_type' => 'iso', 'fix_date' => false)); if (isset($parsed['year']) and (strpos(strtoupper($format), 'YY') !== false and strpos(strtoupper($format), 'YYYY') === false)) { $parsed['year'] = self::getFullYear($parsed['year']); } } catch (Zend_Locale_Exception $e) { // Date can not be parsed return false; } if ((strpos($format, 'Y') !== false or strpos($format, 'y') !== false) and !isset($parsed['year'])) { // Year expected but not found return false; } if (strpos($format, 'M') !== false and !isset($parsed['month'])) { // Month expected but not found return false; } if (strpos($format, 'd') !== false and !isset($parsed['day'])) { // Day expected but not found return false; } if ((strpos($format, 'H') !== false or strpos($format, 'h') !== false) and !isset($parsed['hour'])) { // Hour expected but not found return false; } if (strpos($format, 'm') !== false and !isset($parsed['minute'])) { // Minute expected but not found return false; } if (strpos($format, 's') !== false and !isset($parsed['second'])) { // Second expected but not found return false; } // Set not given dateparts if (isset($parsed['hour']) === false) { $parsed['hour'] = 0; } if (isset($parsed['minute']) === false) { $parsed['minute'] = 0; } if (isset($parsed['second']) === false) { $parsed['second'] = 0; } if (isset($parsed['month']) === false) { $parsed['month'] = 1; } if (isset($parsed['day']) === false) { $parsed['day'] = 1; } if (isset($parsed['year']) === false) { $parsed['year'] = 1970; } $date = new self($parsed, null, $locale); $timestamp = $date->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $parsed['month'], $parsed['day'], $parsed['year']); if ($parsed['year'] != $date->date('Y', $timestamp)) { // Given year differs from parsed year return false; } if ($parsed['month'] != $date->date('n', $timestamp)) { // Given month differs from parsed month return false; } if ($parsed['day'] != $date->date('j', $timestamp)) { // Given day differs from parsed day return false; } if ($parsed['hour'] != $date->date('G', $timestamp)) { // Given hour differs from parsed hour return false; } if ($parsed['minute'] != $date->date('i', $timestamp)) { // Given minute differs from parsed minute return false; } if ($parsed['second'] != $date->date('s', $timestamp)) { // Given second differs from parsed second return false; } return true; }
/** * Internal function for checking the options array of proper input values * See {@link setOptions()} for details. * * @param array $options Array of options, keyed by option name: format_type = 'iso' | 'php', fix_date = true | false, * locale = Zend_Locale | locale string, precision = whole number between -1 and 30 * @throws Zend_Locale_Exception * @return Options array if no option was given */ private static function checkOptions(array $options = array()) { if (count($options) == 0) { return self::$_Options; } foreach ($options as $name => $value) { $name = strtolower($name); if ($name !== 'locale') { if (gettype($value) === 'string') { $value = strtolower($value); } } if (array_key_exists($name, self::$_Options)) { switch($name) { case 'number_format' : if ($value == 'standard') { $locale = self::$_Options['locale']; if (isset($options['locale'])) { $locale = $options['locale']; } $options['number_format'] = Zend_Locale_Data::getContent($locale, 'decimalnumber'); } else if ((gettype($value) !== 'string') and ($value !== NULL)) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unknown number format type '" . gettype($value) . "'. " . "Format '$value' must be a valid number format string."); } break; case 'date_format' : if ($value == 'standard') { $locale = self::$_Options['locale']; if (isset($options['locale'])) { $locale = $options['locale']; } $options['date_format'] = Zend_Locale_Format::getDateFormat($locale); } else if ((gettype($value) !== 'string') and ($value !== NULL)) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unknown dateformat type '" . gettype($value) . "'. " . "Format '$value' must be a valid ISO or PHP date format string."); } else { if (((array_key_exists('format_type', $options)) and ($options['format_type'] == 'php')) or ((!array_key_exists('format_type', $options)) and (self::$_Options['format_type'] == 'php'))) { $options['date_format'] = Zend_Locale_Format::convertPhpToIsoFormat($value); } } break; case 'format_type' : if (($value != 'php') && ($value != 'iso')) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unknown date format type '$value'. Only 'iso' and 'php'" . " are supported."); } break; case 'fix_date' : if (($value !== true) && ($value !== false)) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Enabling correction of dates must be either true or false" . "(fix_date='$value')."); } break; case 'locale' : if (gettype($value) === 'string' && strtolower($value) == 'standard') { $options['locale'] = new Zend_Locale(); } else if (!empty($value) && (!Zend_Locale::isLocale($value))) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("'" . (gettype($value) === 'object' ? get_class($value) : $value) . "' is not a known locale."); } break; case 'cache' : if ($value instanceof Zend_Cache_Core) { Zend_Locale_Data::setCache($value); } break; case 'precision' : if ($value === NULL) { $value = -1; } if (($value < -1) || ($value > 30)) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("'$value' precision is not a whole number less than 30."); } break; } } else { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unknown option: '$name' = '$value'"); } } return $options; }
protected function _addValidators() { parent::_addValidators(); $this->addValidator(new Kwf_Validate_Date(array('outputFormat' => Zend_Locale_Format::convertPhpToIsoFormat(trlKwf('Y-m-d'))))); }
/** * Checks if the given date is a real date or datepart. * Returns false is a expected datepart is missing or a datepart exceeds its possible border. * But the check will only be done for the expected dateparts which are given by format. * If no format is given the standard dateformat for the actual locale is used. * f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY' * * @param string $date Date to parse for correctness * @param string $format OPTIONAL Format for parsing the date string * @param string|Zend_Locale $locale OPTIONAL Locale for parsing date parts * @return boolean True when all date parts are correct */ public static function isDate($date, $format = null, $locale = null) { if (Zend_Locale::isLocale($format)) { $locale = $format; $format = null; } if ($locale === null) { $locale = new Zend_Locale(); $locale = $locale->toString(); } if ($format === null) { $format = Zend_Locale_Format::getDateFormat($locale); } else { if (self::$_Options['format_type'] == 'php') { $format = Zend_Locale_Format::convertPhpToIsoFormat($format); } } try { $parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale, 'date_format' => $format, 'format_type' => 'iso', 'fix_date' => false)); } catch (Zend_Locale_Exception $e) { // date can not be parsed return false; } if ((strpos($format, 'Y') !== false or strpos($format, 'y') !== false) and !isset($parsed['year'])) { // year expected but not found return false; } if (strpos($format, 'M') !== false and !isset($parsed['month'])) { // month expected but not found return false; } if (strpos($format, 'd') !== false and !isset($parsed['day'])) { // day expected but not found return false; } if ((strpos($format, 'H') !== false or strpos($format, 'h') !== false) and !isset($parsed['hour'])) { // hour expected but not found return false; } if (strpos($format, 'm') !== false and !isset($parsed['minute'])) { // minute expected but not found return false; } if (strpos($format, 's') !== false and !isset($parsed['second'])) { // second expected but not found return false; } // set not given dateparts if (!isset($parsed['hour'])) { $parsed['hour'] = 0; } if (!isset($parsed['minute'])) { $parsed['minute'] = 0; } if (!isset($parsed['second'])) { $parsed['second'] = 0; } if (!isset($parsed['month'])) { $parsed['month'] = 1; } if (!isset($parsed['day'])) { $parsed['day'] = 1; } if (!isset($parsed['year'])) { $parsed['year'] = 1970; } $date = new self($locale); $timestamp = $date->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $parsed['month'], $parsed['day'], $parsed['year']); if ($parsed['year'] != $date->date('Y', $timestamp)) { // given year differs from parsed year return false; } if ($parsed['month'] != $date->date('n', $timestamp)) { // given month differs from parsed month return false; } if ($parsed['day'] != $date->date('j', $timestamp)) { // given day differs from parsed day return false; } if ($parsed['hour'] != $date->date('G', $timestamp)) { // given hour differs from parsed hour return false; } if ($parsed['minute'] != $date->date('i', $timestamp)) { // given minute differs from parsed minute return false; } if ($parsed['second'] != $date->date('s', $timestamp)) { // given second differs from parsed second return false; } return true; }
/** * test convertPhpToIso * expected boolean */ public function testConvertPhpToIso() { $this->assertSame('dd', Zend_Locale_Format::convertPhpToIsoFormat('d')); $this->assertSame('EE', Zend_Locale_Format::convertPhpToIsoFormat('D')); $this->assertSame('d', Zend_Locale_Format::convertPhpToIsoFormat('j')); $this->assertSame('EEEE', Zend_Locale_Format::convertPhpToIsoFormat('l')); $this->assertSame('e', Zend_Locale_Format::convertPhpToIsoFormat('N')); $this->assertSame('SS', Zend_Locale_Format::convertPhpToIsoFormat('S')); $this->assertSame('eee', Zend_Locale_Format::convertPhpToIsoFormat('w')); $this->assertSame('D', Zend_Locale_Format::convertPhpToIsoFormat('z')); $this->assertSame('w', Zend_Locale_Format::convertPhpToIsoFormat('W')); $this->assertSame('MMMM', Zend_Locale_Format::convertPhpToIsoFormat('F')); $this->assertSame('MM', Zend_Locale_Format::convertPhpToIsoFormat('m')); $this->assertSame('MMM', Zend_Locale_Format::convertPhpToIsoFormat('M')); $this->assertSame('M', Zend_Locale_Format::convertPhpToIsoFormat('n')); $this->assertSame('ddd', Zend_Locale_Format::convertPhpToIsoFormat('t')); $this->assertSame('l', Zend_Locale_Format::convertPhpToIsoFormat('L')); $this->assertSame('YYYY', Zend_Locale_Format::convertPhpToIsoFormat('o')); $this->assertSame('yyyy', Zend_Locale_Format::convertPhpToIsoFormat('Y')); $this->assertSame('yy', Zend_Locale_Format::convertPhpToIsoFormat('y')); $this->assertSame('a', Zend_Locale_Format::convertPhpToIsoFormat('a')); $this->assertSame('a', Zend_Locale_Format::convertPhpToIsoFormat('A')); $this->assertSame('B', Zend_Locale_Format::convertPhpToIsoFormat('B')); $this->assertSame('h', Zend_Locale_Format::convertPhpToIsoFormat('g')); $this->assertSame('H', Zend_Locale_Format::convertPhpToIsoFormat('G')); $this->assertSame('hh', Zend_Locale_Format::convertPhpToIsoFormat('h')); $this->assertSame('HH', Zend_Locale_Format::convertPhpToIsoFormat('H')); $this->assertSame('mm', Zend_Locale_Format::convertPhpToIsoFormat('i')); $this->assertSame('ss', Zend_Locale_Format::convertPhpToIsoFormat('s')); $this->assertSame('zzzz', Zend_Locale_Format::convertPhpToIsoFormat('e')); $this->assertSame('I', Zend_Locale_Format::convertPhpToIsoFormat('I')); $this->assertSame('Z', Zend_Locale_Format::convertPhpToIsoFormat('O')); $this->assertSame('ZZZZ', Zend_Locale_Format::convertPhpToIsoFormat('P')); $this->assertSame('z', Zend_Locale_Format::convertPhpToIsoFormat('T')); $this->assertSame('X', Zend_Locale_Format::convertPhpToIsoFormat('Z')); $this->assertSame('yyyy-MM-ddTHH:mm:ssZZZZ', Zend_Locale_Format::convertPhpToIsoFormat('c')); $this->assertSame('r', Zend_Locale_Format::convertPhpToIsoFormat('r')); $this->assertSame('U', Zend_Locale_Format::convertPhpToIsoFormat('U')); $this->assertSame('HHmmss', Zend_Locale_Format::convertPhpToIsoFormat('His')); }
/** * Returns the calculated date * * @param string $calc Calculation to make * @param string|integer|Zend_Date $date Date to calculate with, if null the actual date is taken * @param string $format Date format for parsing * @param string|Zend_Locale $locale Locale for parsing input * @return integer|Zend_Date new date * @throws Zend_Date_Exception */ private function _date($calc, $date, $format, $locale) { if (is_null($date)) { throw new Zend_Date_Exception('parameter $date must be set, null is not allowed'); } if ($locale === null) { $locale = $this->getLocale(); } if ($date instanceof Zend_Date) { // extract date from object $date = $date->get(Zend_Date::DATE_MEDIUM, $locale); } else { if (self::$_Options['format_type'] == 'php') { $format = Zend_Locale_Format::convertPhpToIsoFormat($format); } try { $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'locale' => $locale, 'format_type' => 'iso')); } catch (Zend_Locale_Exception $e) { throw new Zend_Date_Exception($e->getMessage()); } $date = new Zend_Date(0, Zend_Date::TIMESTAMP, $locale); $date->set($parsed['year'], Zend_Date::YEAR); $date->set($parsed['month'], Zend_Date::MONTH); $date->set($parsed['day'], Zend_Date::DAY); $date = $date->get(Zend_Date::DATE_MEDIUM, $locale); } $return = $this->_calcdetail($calc, $date, Zend_Date::DATE_MEDIUM, $locale); if ($calc != 'cmp') { return $this; } return $return; }
/** * Defined by Zend_Filter_Interface * * Returns the date formatted for the format defined with the constructor. * Will return the date for the 1970-1-1 if the passed argument * was not in a valid date-format. * * @param mixed $value * @return integer */ public function filter($value) { // get Zend_Date options $dateOptions = Zend_Date::setOptions(); // set format type to iso Zend_Date::setOptions(array('format_type' => 'iso')); $inputFormat = $this->_inputFormat; $format = $this->_format; if ($inputFormat) { $inputFormat = Zend_Locale_Format::convertPhpToIsoFormat($inputFormat); } $format = Zend_Locale_Format::convertPhpToIsoFormat($format); $d = $value; if (!is_numeric($value)) { $d = strtotime($value); } if ($d === false) { try { $date = new Zend_Date($value, $inputFormat); } catch (Zend_Date_Exception $e) { $date = new Zend_Date("1970-01-01 00:00:00"); } } else { try { $date = new Zend_Date($d, Zend_Date::TIMESTAMP); } catch (Zend_Date_Exception $e) { $date = new Zend_Date("1970-01-01 00:00:00"); } } $d = $date->get($format); Zend_Date::setOptions(array('format_type' => $dateOptions['format_type'])); return $d; }
protected function _cleanupValues($attr, &$oldValue, &$newValue) { // trying to work around PHP's weakly typed mess... if (!empty($attr['frontend_input'])) { switch ($attr['frontend_input']) { case 'media_image': if (!is_null($oldValue)) { if ($oldValue == 'no_selection') { $oldValue = ''; } } break; case 'multiselect': if (is_null($oldValue)) { $oldValue = array(); } if ($newValue === '') { $newValue = array(); } break; } } if (!empty($attr['backend_type'])) { switch ($attr['backend_type']) { case 'int': if (!is_null($newValue) && !is_array($newValue)) { if ($newValue === '') { $newValue = null; } else { $newValue = $this->_locale->getNumber($newValue); if ($newValue != (int) $newValue) { $this->_profile->addValue('num_errors'); $this->_profile->getLogger()->error($this->__("Invalid int value")); } else { $newValue = (int) $newValue; } } } if (!is_null($oldValue) && !is_array($oldValue)) { if ($oldValue === '') { $oldValue = null; } else { $oldValue = (int) $oldValue; } } break; case 'decimal': if (!is_null($newValue)) { if ($newValue === '') { $newValue = null; } else { $newValue = $this->_locale->getNumber($newValue); if (!is_numeric($newValue)) { $this->_profile->addValue('num_errors'); $this->_profile->getLogger()->error($this->__("Invalid decimal value")); } else { $newValue *= 1.0; } } } if (!is_null($oldValue)) { if ($oldValue === '') { $oldValue = null; } else { $oldValue *= 1.0; } } break; case 'datetime': if (!is_null($newValue)) { if ($newValue === '') { $newValue = null; } else { static $_dp; if (null === $_dp) { $_dp = Mage::getStoreConfig('urapidflow/import_options/date_processor'); if ($_dp == 'date_parse_from_format' && !version_compare(phpversion(), '5.3.0', '>=')) { $_dp = 'strtotime'; } } static $_attrFormat = array(); $_attrCode = $attr['attribute_code']; if (!isset($_attrFormat[$_attrCode])) { if (isset($this->_fields[$_attrCode]['format'])) { $_attrFormat[$_attrCode] = $this->_fields[$_attrCode]['format']; } else { $_attrFormat[$_attrCode] = $this->_profile->getDefaultDatetimeFormat(); } if ($_dp == 'zend_date') { $_attrFormat[$_attrCode] = Zend_Locale_Format::convertPhpToIsoFormat($_attrFormat[$_attrCode]); } } switch ($_dp) { case 'zend_date': static $_zendDate; if (null === $_zendDate) { $_zendDate = new Zend_Date($newValue, $_attrFormat[$_attrCode], $this->_profile->getProfileLocale()); } else { $_zendDate->set($newValue, $_attrFormat[$_attrCode]); } $newValue = $_zendDate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); break; case 'date_parse_from_format': $_phpDatetime = DateTime::createFromFormat($_attrFormat[$_attrCode], $newValue); $newValue = $_phpDatetime->format("Y-m-d H:i:s"); break; default: $newValue = date("Y-m-d H:i:s", strtotime($newValue)); break; } if (!$newValue) { $this->_profile->addValue('num_errors'); $this->_profile->getLogger()->error($this->__("Invalid datetime value")); } } } if (!is_null($oldValue)) { if ($oldValue === '') { $oldValue = null; } } break; case 'varchar': case 'text': if ($oldValue === '' && is_null($newValue)) { $newValue = ''; } elseif (is_null($oldValue) && $newValue === '') { $newValue = null; } elseif (is_numeric($newValue)) { $newValue = (string) $newValue; } break; } } }
public function init() { $this->addValidator('Date', true, array(Zend_Locale_Format::convertPhpToIsoFormat('Y-m-d H:i:s'))); }
public function init() { if (parent::getAttrib('type') !== 'multyrange') { $this->addValidator('Date', true, array(Zend_Locale_Format::convertPhpToIsoFormat('Y-m-d'))); } }