Exemple #1
0
 /**
  * Returns the calculated month
  *
  * @param  string                          $calc    Calculation to make
  * @param  string|integer|array|\Zend\Date\Date  $month   Month to calculate with, if null the actual month is taken
  * @param  string|\Zend\Locale\Locale              $locale  Locale for parsing input
  * @return integer|\Zend\Date\Date  new time
  * @throws \Zend\Date\Exception
  */
 private function _month($calc, $month, $locale)
 {
     if ($month === null) {
         throw new Exception\InvalidArgumentException('parameter $month must be set, null is not allowed');
     }
     if ($locale === null) {
         $locale = $this->getLocale();
     }
     if ($month instanceof Date) {
         // extract month from object
         $found = $month->toString(self::MONTH_SHORT, 'iso', $locale);
     } else {
         if (is_numeric($month)) {
             $found = $month;
         } else {
             if (is_array($month)) {
                 if (isset($month['month']) === true) {
                     $month = $month['month'];
                 } else {
                     throw new Exception\InvalidArgumentException("no month given in array");
                 }
             } else {
                 $monthlist = Cldr::getList($locale, 'month');
                 $monthlist2 = Cldr::getList($locale, 'month', array('gregorian', 'format', 'abbreviated'));
                 $monthlist = array_merge($monthlist, $monthlist2);
                 $found = 0;
                 $cnt = 0;
                 foreach ($monthlist as $key => $value) {
                     if (strtoupper($value) == strtoupper($month)) {
                         $found = $key % 12 + 1;
                         break;
                     }
                     ++$cnt;
                 }
                 if ($found == 0) {
                     foreach ($monthlist2 as $key => $value) {
                         if (strtoupper(iconv_substr($value, 0, 1, 'UTF-8')) == strtoupper($month)) {
                             $found = $key + 1;
                             break;
                         }
                         ++$cnt;
                     }
                 }
                 if ($found == 0) {
                     throw new Exception\InvalidArgumentException("unknown month name ({$month})");
                 }
             }
         }
     }
     $return = $this->_calcdetail($calc, $found, self::MONTH_SHORT, $locale);
     if ($calc != 'cmp') {
         return $this;
     }
     return $return;
 }
Exemple #2
0
 /**
  * Convert the DateTime into an AMF Date
  *
  * @param  DateTime|\Zend\Date\Date $data
  * @return Zend\AMF\Parser\AMF0\Serializer
  */
 public function writeDate($data)
 {
     if ($data instanceof \DateTime) {
         $dateString = $data->format('U');
     } elseif ($data instanceof Date\Date) {
         $dateString = $data->toString('U');
     } else {
         throw new AMF\Exception('Invalid date specified; must be a DateTime or Zend_Date object');
     }
     $dateString *= 1000;
     // Make the conversion and remove milliseconds.
     $this->_stream->writeDouble($dateString);
     // Flash does not respect timezone but requires it.
     $this->_stream->writeInt(0);
     return $this;
 }
    /**
     * 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 (is_array($value)) {
            $date = new Date($value, $this->_options['locale']);
            return $date->toString($this->_options['date_format']);
        } else if ($this->_options['precision'] === 0) {
            return Format::toInteger($value, $this->_options);
        } else if ($this->_options['precision'] === null) {
            return Format::toFloat($value, $this->_options);
        }

        return Format::toNumber($value, $this->_options);
    }
Exemple #4
0
 /**
  * Get posts matching the arguments
  *
  * If no date or url is given, most recent date will be used
  *
  * @param  string    $tag Optional filtering by tag
  * @param  Zend_Date $dt  Optional filtering by date
  * @param  string    $url Optional filtering by url
  * @throws Zend_Service_Delicious_Exception
  * @return Zend_Service_Delicious_PostList
  */
 public function getPosts($tag = null, Date $dt = null, $url = null)
 {
     $parms = array();
     if ($tag) {
         $parms['tag'] = $tag;
     }
     if ($url) {
         $parms['url'] = $url;
     }
     if ($dt) {
         $parms['dt'] = $dt->toString('Y-m-d\\TH:i:s\\Z', 'php');
     }
     $response = $this->makeRequest(self::PATH_POSTS_GET, $parms);
     return $this->_parseXmlPostList($response);
 }
Exemple #5
0
 /**
  * @ZF-8650
  */
 public function testFractionalPrecision()
 {
     $date = new Date();
     $date->set('012345', Date::MILLISECOND);
     $this->assertEquals(3, $date->getFractionalPrecision());
     $this->assertEquals('345', $date->toString('S'));
     $date->setFractionalPrecision(6);
     $this->assertEquals(6, $date->getFractionalPrecision());
     $this->assertEquals('345000', $date->toString('S'));
     $date->add(200, Date::MILLISECOND);
     $this->assertEquals(6, $date->getFractionalPrecision());
     $this->assertEquals('345200', $date->toString('S'));
 }