/**
  * Defined by Zend_Filter_Interface
  *
  * Normalizes the given input
  *
  * @param  string $value Value to normalized
  * @return string|array The normalized value
  */
 public function filter($value)
 {
     if (Format::isNumber($value, $this->_options)) {
         return Format::getNumber($value, $this->_options);
     } else {
         if ($this->_options['date_format'] === null && strpos($value, ':') !== false) {
             // Special case, no date format specified, detect time input
             return Format::getTime($value, $this->_options);
         } else {
             if (Format::checkDateFormat($value, $this->_options)) {
                 // Detect date or time input
                 return Format::getDate($value, $this->_options);
             }
         }
     }
     return $value;
 }
Example #2
0
    /**
     * Set a new value
     *
     * @param  integer|string             $value   Value as string, integer, real or float
     * @param  string                     $type    OPTIONAL A measure type f.e. Zend_Measure_Length::METER
     * @param  string|Zend\Locale\Locale  $locale  OPTIONAL Locale for parsing numbers
     * @throws Zend\Measure\Exception
     * @return Zend\Measure\AbstractMeasure
     */
    public function setValue($value, $type = null, $locale = null)
    {
        if (($type !== null) and (Locale\Locale::isLocale($type))) {
            $locale = $type;
            $type = null;
        }

        if ($locale === null) {
            $locale = $this->_locale;
        }

        $this->setLocale($locale, true);
        if ($type === null) {
            $type = $this->_units['STANDARD'];
        }

        if (empty($this->_units[$type])) {
            throw new Exception("Type ($type) is unknown");
        }

        try {
            $value = Locale\Format::getNumber($value, array('locale' => $locale));
        } catch(\Exception $e) {
            throw new Exception($e->getMessage(), $e->getCode(), $e);
        }

        $this->_value = $value;
        $this->setType($type);
        return $this;
    }
Example #3
0
 /**
  * @group ZF-9160
  */
 public function testGetNumberWithZeroPrecision()
 {
     $this->assertEquals(1234, Format::getNumber('1234.567', array('locale' => 'en_US', 'precision' => 0)));
 }