php Zend-Date-Date类(方法)实例源码

下面列出了php Zend-Date-Date 类(方法)源码代码实例,从而了解它的用法。

作者:alab100110    项目:zf   
public function testSetWhenUsesZendDateObject()
 {
     $entry = new Writer\Deleted();
     $entry->setWhen(new Date\Date('1234567890', Date\Date::TIMESTAMP));
     $myDate = new Date\Date('1234567890', Date\Date::TIMESTAMP);
     $this->assertTrue($myDate->equals($entry->getWhen()));
 }

作者:briko    项目:zend_fee   
/**
  * Save subscription to RDMBS
  *
  * @param array $data
  * @return bool
  */
 public function setSubscription(array $data)
 {
     if (!isset($data['id'])) {
         throw new PubSubHubbub\Exception('ID must be set before attempting a save');
     }
     $result = $this->_db->select(array('id' => $data['id']));
     if ($result && 0 < count($result)) {
         $data['created_time'] = $result->current()->created_time;
         $now = new Date\Date();
         if (array_key_exists('lease_seconds', $data) && $data['lease_seconds']) {
             $data['expiration_time'] = $now->add($data['lease_seconds'], Date\Date::SECOND)->get('yyyy-MM-dd HH:mm:ss');
         }
         $this->_db->update($data, array('id' => $data['id']));
         return false;
     }
     $this->_db->insert($data);
     return true;
 }

作者:bradley-hol    项目:zf   
/**
  * Save subscription to RDMBS
  *
  * @param array $data
  * @return bool
  */
 public function setSubscription(array $data)
 {
     if (!isset($data['id'])) {
         throw new PubSubHubbub\Exception('ID must be set before attempting a save');
     }
     $result = $this->_db->find($data['id']);
     if ($result) {
         $data['created_time'] = $result->current()->created_time;
         $now = new Date\Date();
         if ($data['lease_seconds']) {
             $data['expiration_time'] = $now->add($data['lease_seconds'], Date\Date::SECOND)->get('yyyy-MM-dd HH:mm:ss');
         }
         $this->_db->update($data, $this->_db->getAdapter()->quoteInto('id = ?', $data['id']));
         return false;
     }
     $this->_db->insert($data);
     return true;
 }

作者:niallmccrudde    项目:zf   
public function teardown()
 {
     Date\Date::setOptions($this->_options);
 }

作者:bradley-hol    项目:zf   
/**
  * 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);
 }

作者:rexma    项目:zf   
/**
  * Decorator to format return value of list methods
  *
  * @param array $result
  * @return string
  */
 public static function listDecorator($result)
 {
     $ret = '';
     $date = new Date();
     if (count($result) > 0) {
         foreach ($result as $record) {
             $date->set($record['createTime']);
             $createTimeFormatted = $date->get(Date::RFC_1123);
             $date->set($record['modifyTime']);
             $modifyTimeFormatted = $date->get(Date::RFC_1123);
             $ret .= sprintf('         Filename  : %s%s', $record['filename'], PHP_EOL);
             $ret .= sprintf('         File Size : %d b%s', $record['fileSize'], PHP_EOL);
             $ret .= sprintf('     Creation Time : %d (%s)%s', $record['createTime'], $createTimeFormatted, PHP_EOL);
             $ret .= sprintf('Last Modified Time : %d (%s)%s', $record['modifyTime'], $modifyTimeFormatted, PHP_EOL);
             $ret .= PHP_EOL;
         }
     }
     unset($date);
     return $ret;
 }

作者:alab100110    项目:zf   
<?php

require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';
use Zend\Date\Date;
use Zend\Service\LiveDocx\Helper;
use Zend\Service\LiveDocx\MailMerge;
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
/*
 * ALTERNATIVE: Specify username and password in constructor
 */
/*
$mailMerge = new MailMerge(
    array (
        'username' => DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME,
        'password' => DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD
    )
);
*/
$mailMerge->setLocalTemplate('template.doc');
$mailMerge->assign('customer_number', sprintf("#%'10s", rand(0, 1000000000)))->assign('invoice_number', sprintf("#%'10s", rand(0, 1000000000)))->assign('account_number', sprintf("#%'10s", rand(0, 1000000000)));
$billData = array('phone' => '+22 (0)333 444 555', 'date' => Date::now()->toString(Date::DATE_LONG), 'name' => 'James Henry Brown', 'service_phone' => '+22 (0)333 444 559', 'service_fax' => '+22 (0)333 444 558', 'month' => sprintf('%s %s', Date::now()->toString(Date::MONTH_NAME), Date::now()->toString(Date::YEAR)), 'monthly_fee' => '15.00', 'total_net' => '19.60', 'tax' => '19.00', 'tax_value' => '3.72', 'total' => '23.32');
$mailMerge->assign($billData);
$billConnections = array(array('connection_number' => '+11 (0)222 333 441', 'connection_duration' => '00:01:01', 'fee' => '1.15'), array('connection_number' => '+11 (0)222 333 442', 'connection_duration' => '00:01:02', 'fee' => '1.15'), array('connection_number' => '+11 (0)222 333 443', 'connection_duration' => '00:01:03', 'fee' => '1.15'), array('connection_number' => '+11 (0)222 333 444', 'connection_duration' => '00:01:04', 'fee' => '1.15'));
$mailMerge->assign('connection', $billConnections);
$mailMerge->createDocument();
$document = $mailMerge->retrieveDocument('pdf');
unset($mailMerge);
file_put_contents('document.pdf', $document);

作者:narix    项目:zf   
public function testSetLastBuildDateUsesZendDateObject()
 {
     $writer = new Writer\Feed();
     $writer->setLastBuildDate(new Date\Date('1234567890', Date\Date::TIMESTAMP));
     $myDate = new Date\Date('1234567890', Date\Date::TIMESTAMP);
     $this->assertTrue($myDate->equals($writer->getLastBuildDate()));
 }

作者:nsenkevic    项目:zf   
/**
  * Check if the given date fits the given format
  *
  * @param  string $value  Date to check
  * @return boolean False when date does not fit the format
  */
 private function _checkFormat($value)
 {
     try {
         $parsed = \Zend\Locale\Format::getDate($value, array('date_format' => $this->_format, 'format_type' => 'iso', 'fix_date' => false));
         if (isset($parsed['year']) and (strpos(strtoupper($this->_format), 'YY') !== false and strpos(strtoupper($this->_format), 'YYYY') === false)) {
             $parsed['year'] = ZendDate\Date::getFullYear($parsed['year']);
         }
     } catch (\Exception $e) {
         // Date can not be parsed
         return false;
     }
     if ((strpos($this->_format, 'Y') !== false or strpos($this->_format, 'y') !== false) and !isset($parsed['year'])) {
         // Year expected but not found
         return false;
     }
     if (strpos($this->_format, 'M') !== false and !isset($parsed['month'])) {
         // Month expected but not found
         return false;
     }
     if (strpos($this->_format, 'd') !== false and !isset($parsed['day'])) {
         // Day expected but not found
         return false;
     }
     if ((strpos($this->_format, 'H') !== false or strpos($this->_format, 'h') !== false) and !isset($parsed['hour'])) {
         // Hour expected but not found
         return false;
     }
     if (strpos($this->_format, 'm') !== false and !isset($parsed['minute'])) {
         // Minute expected but not found
         return false;
     }
     if (strpos($this->_format, 's') !== false and !isset($parsed['second'])) {
         // Second expected  but not found
         return false;
     }
     // Date fits the format
     return true;
 }

作者:bradley-hol    项目:zf   
/**
  * ZF-6457
  */
 public function testArrayVerification()
 {
     $date = new Date\Date();
     $array = $date->toArray();
     $this->assertTrue($this->_validator->isValid($array), "array expected to be valid");
 }

作者:bradley-hol    项目:zf   
/**
  * 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;
 }

作者:alab100110    项目:zf   
$tempDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(rand(1, 10000) . __FILE__);
if (is_dir($tempDirectory)) {
    recursiveRemoveDirectory($tempDirectory);
}
$logger->log(sprintf('Making temporary directory %s.', $tempDirectory), Logger::INFO);
mkdir($tempDirectory);
// -----------------------------------------------------------------------------
// Generate temporary documents
$tempFilenames = array();
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
$mailMerge->setLocalTemplate('template.docx');
for ($iteration = 1; $iteration <= $iterations; $iteration++) {
    $tempFilename = sprintf('%s%s%010s.pdf', $tempDirectory, DIRECTORY_SEPARATOR, $iteration);
    $tempFilenames[] = $tempFilename;
    $mailMerge->assign('software', randomString())->assign('licensee', randomString())->assign('company', randomString())->assign('date', Date::now()->toString(Date::DATE_LONG))->assign('time', Date::now()->toString(Date::TIME_LONG))->assign('city', randomString())->assign('country', randomString());
    $mailMerge->createDocument();
    file_put_contents($tempFilename, $mailMerge->retrieveDocument('pdf'));
    $logger->log(sprintf('Generating temporary document %s.', $tempFilename), Logger::INFO);
}
unset($mailMerge);
// -----------------------------------------------------------------------------
// Concatenate temporary documents and write output document
$outputFilename = __DIR__ . DIRECTORY_SEPARATOR . 'document-concat.pdf';
$logger->log('Concatenating temporary documents...', Logger::INFO);
if (true === concatenatePdfFilenames($tempFilenames, $outputFilename, $processor)) {
    $logger->log(sprintf('...DONE. Saved output document as %s.', basename($outputFilename)), Logger::INFO);
} else {
    $logger->log(sprintf('...ERROR.'), Logger::ERR);
}
// -----------------------------------------------------------------------------

作者:stunt    项目:zf   
<?php

require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';
use Zend\Date\Date;
use Zend\Service\LiveDocx\MailMerge;
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
$mailMerge->setLocalTemplate('template.docx');
$mailMerge->setFieldValue('software', 'Magic Graphical Compression Suite v1.9')->setFieldValue('licensee', 'Henry Döner-Meyer')->setFieldValue('company', 'Megasoft Co-operation')->setFieldValue('date', Date::now()->toString(Date::DATE_LONG))->setFieldValue('time', Date::now()->toString(Date::TIME_LONG))->setFieldValue('city', 'Bremen')->setFieldValue('country', 'Germany');
$mailMerge->createDocument();
// Get all metafiles
$metaFiles = $mailMerge->getAllMetafiles();
// Get just metafiles in specified range
//$metaFiles = $mailMerge->getMetafiles(1, 2);    // fromPage, toPage
foreach ($metaFiles as $pageNumber => $metaFileData) {
    $filename = sprintf('document-page-%d.wmf', $pageNumber);
    file_put_contents($filename, $metaFileData);
}
unset($mailMerge);

作者:nresn    项目:AriadneSandbo   
/**
     * 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);
    }

作者:briko    项目:zend_fee   
/**
  * Get the entry's date of modification
  *
  * @return string
  */
 public function getDateModified()
 {
     if (array_key_exists('datemodified', $this->_data)) {
         return $this->_data['datemodified'];
     }
     $dateModified = null;
     $date = null;
     if ($this->getType() !== Reader\Reader::TYPE_RSS_10 && $this->getType() !== Reader\Reader::TYPE_RSS_090) {
         $dateModified = $this->_xpath->evaluate('string(' . $this->_xpathQueryRss . '/pubDate)');
         if ($dateModified) {
             $dateModifiedParsed = strtotime($dateModified);
             if ($dateModifiedParsed) {
                 $date = new Date\Date($dateModifiedParsed);
             } else {
                 $dateStandards = array(Date\Date::RSS, Date\Date::RFC_822, Date\Date::RFC_2822, Date\Date::DATES);
                 $date = new Date\Date();
                 foreach ($dateStandards as $standard) {
                     try {
                         $date->set($dateModified, $standard);
                         break;
                     } catch (Date\Exception $e) {
                         if ($standard == Date\Date::DATES) {
                             require_once 'Zend/Feed/Exception.php';
                             throw new Exception('Could not load date due to unrecognised' . ' format (should follow RFC 822 or 2822):' . $e->getMessage(), 0, $e);
                         }
                     }
                 }
             }
         }
     }
     if (!$date) {
         $date = $this->getExtension('DublinCore')->getDate();
     }
     if (!$date) {
         $date = $this->getExtension('Atom')->getDateModified();
     }
     if (!$date) {
         $date = null;
     }
     $this->_data['datemodified'] = $date;
     return $this->_data['datemodified'];
 }

作者:heiglandrea    项目:zf   
/**
  * Get modification date (Unencoded Text)
  * @group ZFR002
  */
 public function testGetsDateModifiedFromAtom10()
 {
     $entry = Reader\Reader::importString(file_get_contents($this->_feedSamplePath . '/datemodified/atom10.xml'));
     $edate = new Date\Date();
     $edate->set('2009-03-07T08:03:50Z', Date\Date::ISO_8601);
     $this->assertTrue($edate->equals($entry->getDateModified()));
 }

作者:heiglandrea    项目:zf   
public function testRespondsToValidConfirmationWithBodyContainingHubChallenge()
 {
     $this->_tableGateway->expects($this->any())->method('find')->with($this->equalTo('verifytokenkey'))->will($this->returnValue($this->_rowset));
     $t = new Date\Date();
     $rowdata = array('id' => 'verifytokenkey', 'verify_token' => hash('sha256', 'cba'), 'created_time' => $t->get(Date\Date::TIMESTAMP), 'lease_seconds' => 10000);
     $row = new \Zend\Db\Table\Row(array('data' => $rowdata));
     $this->_rowset->expects($this->any())->method('current')->will($this->returnValue($row));
     // require for the count call on the rowset in Model/Subscription
     $this->_rowset->expects($this->any())->method('count')->will($this->returnValue(1));
     $this->_tableGateway->expects($this->once())->method('update')->with($this->equalTo(array('id' => 'verifytokenkey', 'verify_token' => hash('sha256', 'cba'), 'created_time' => $t->get(Date\Date::TIMESTAMP), 'lease_seconds' => 1234567, 'subscription_state' => 'verified', 'expiration_time' => $t->add(1234567, Date\Date::SECOND)->get('yyyy-MM-dd HH:mm:ss'))), $this->equalTo('id = \'verifytokenkey\''));
     $this->_adapter->expects($this->once())->method('quoteInto')->with($this->equalTo('id = ?'), $this->equalTo('verifytokenkey'))->will($this->returnValue('id = \'verifytokenkey\''));
     $this->_callback->handle($this->_get);
     $this->assertTrue($this->_callback->getHttpResponse()->getBody() == 'abc');
 }

作者:stunt    项目:zf   
/**
  * Convert LiveDocx service return value from list methods to consistent PHP array
  *
  * @param  array $list
  * @return array
  * @since  LiveDocx 1.0 
  */
 protected function _backendListArrayToMultiAssocArray($list)
 {
     $this->logIn();
     $ret = array();
     if (isset($list->ArrayOfString)) {
         foreach ($list->ArrayOfString as $a) {
             if (is_array($a)) {
                 // 1 template only
                 $o = new \StdClass();
                 $o->string = $a;
             } else {
                 // 2 or more templates
                 $o = $a;
             }
             unset($a);
             if (isset($o->string)) {
                 $date1 = new Date($o->string[3], Date::RFC_1123);
                 $date2 = new Date($o->string[1], Date::RFC_1123);
                 $ret[] = array('filename' => $o->string[0], 'fileSize' => (int) $o->string[2], 'createTime' => (int) $date1->get(Date::TIMESTAMP), 'modifyTime' => (int) $date2->get(Date::TIMESTAMP));
             }
         }
     }
     return $ret;
 }

作者:rexma    项目:zf   
/**
  *
  *
  * @return Date\Date|null
  */
 public function getDate()
 {
     if (array_key_exists('date', $this->_data)) {
         return $this->_data['date'];
     }
     $d = null;
     $date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)');
     if (!$date) {
         $date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)');
     }
     if ($date) {
         $d = new Date\Date();
         $d->set($date, Date\Date::ISO_8601);
     }
     $this->_data['date'] = $d;
     return $this->_data['date'];
 }

作者:navti    项目:xerxes-pazpar   
/**
  * 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;
 }


问题


面经


文章

微信
公众号

扫码关注公众号