當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DateUtil::addMonths方法代碼示例

本文整理匯總了PHP中DateUtil::addMonths方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateUtil::addMonths方法的具體用法?PHP DateUtil::addMonths怎麽用?PHP DateUtil::addMonths使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DateUtil的用法示例。


在下文中一共展示了DateUtil::addMonths方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: entryFrom

 /**
  * Parse raw listing entry.
  *
  * @param   string raw a single line
  * @param   peer.ftp.FtpConnection connection
  * @param   string base default "/"
  * @param   util.Date ref default NULL
  * @return  peer.ftp.FtpEntry
  */
 public function entryFrom($raw, FtpConnection $conn = NULL, $base = '/', Date $ref = NULL)
 {
     sscanf($raw, '%s %d %s %s %d %s %d %[^ ] %[^$]', $permissions, $numlinks, $user, $group, $size, $month, $day, $date, $filename);
     // Only qualify filenames if they appear unqualified in the listing
     if ('/' !== $filename[0]) {
         $filename = $base . $filename;
     }
     // Create a directory or an entry
     if ('d' === $permissions[0]) {
         $e = new FtpDir($filename, $conn);
     } else {
         $e = new FtpFile($filename, $conn);
     }
     // If the entry contains a timestamp, the year is omitted, "Apr 4 20:16"
     // instead of "Apr 4 2009". This compact format is used when the file
     // time is within six months* from the current date, in either direction!
     //
     // *] #define SIXMONTHS       ((365 / 2) * 86400) := 15724800
     //    See http://svn.freebsd.org/base/projects/releng_7_xen/bin/ls/print.c
     if (strstr($date, ':')) {
         $ref || ($ref = Date::now());
         $d = new Date($month . ' ' . $day . ' ' . $ref->getYear() . ' ' . $date);
         if ($d->getTime() - $ref->getTime() > 15724800) {
             $d = DateUtil::addMonths($d, -12);
         }
     } else {
         $d = new Date($month . ' ' . $day . ' ' . $date);
     }
     try {
         $e->setPermissions(substr($permissions, 1));
         $e->setNumlinks($numlinks);
         $e->setUser($user);
         $e->setGroup($group);
         $e->setSize($size);
         $e->setDate($d);
     } catch (IllegalArgumentException $e) {
         throw new FormatException('Cannot parse "' . $raw . '": ' . $e->getMessage());
     }
     return $e;
 }
開發者ID:melogamepay,項目名稱:xp-framework,代碼行數:49,代碼來源:DefaultFtpListParser.class.php

示例2: onList

 /**
  * LIST: This command causes a list of file names and file details 
  * to be sent from the FTP site to the client.
  *
  * @param   peer.Socket socket
  * @param   string params
  */
 public function onList($socket, $params)
 {
     if (!($dataSocket = $this->openDatasock($socket))) {
         return;
     }
     // Split options from arguments
     if (substr($params, 0, 1) === '-') {
         list($options, $params) = explode(' ', substr($params, 1), 2);
         $this->cat && $this->cat->debug('+++ Options:', $options);
     } else {
         $options = '';
     }
     if (!($entry = $this->storage->lookup($socket->hashCode(), $params))) {
         $this->answer($socket, 550, $params . ': No such file or directory');
         $dataSocket->close();
         delete($dataSocket);
         $this->cat && $this->cat->debug($socket, $this->datasock[$socket->hashCode()]);
         return;
     }
     // Invoke interceptor
     if (!$this->checkInterceptors($socket, $entry, 'onRead')) {
         $dataSocket->close();
         return;
     }
     $this->answer($socket, 150, sprintf('Opening %s mode data connection for filelist', $this->sessions[$socket->hashCode()]->typeName()));
     // If a collection was specified, list its elements, otherwise,
     // list the single element
     if ($entry instanceof StorageCollection && !strstr($options, 'd')) {
         $elements = $entry->elements();
     } else {
         $elements = array($entry);
     }
     $before6Months = DateUtil::addMonths(Date::now(), -6)->getTime();
     for ($i = 0, $s = sizeof($elements); $i < $s; $i++) {
         $buf = sprintf('%s  %2d %s  %s  %8d %s %s', $this->permissionString($elements[$i]->getPermissions()), $elements[$i]->numLinks(), $elements[$i]->getOwner(), $elements[$i]->getGroup(), $elements[$i]->getSize(), date($elements[$i]->getModifiedStamp() < $before6Months ? 'M d  Y' : 'M d H:i', $elements[$i]->getModifiedStamp()), $elements[$i]->getName());
         $this->cat && $this->cat->debug('    ', $buf);
         $dataSocket->write($buf . $this->eol($this->sessions[$socket->hashCode()]->getType()));
     }
     $dataSocket->close();
     $this->answer($socket, 226, 'Transfer complete');
 }
開發者ID:melogamepay,項目名稱:xp-framework,代碼行數:48,代碼來源:FtpProtocol.class.php

示例3: testNonLeapYear

 public function testNonLeapYear()
 {
     $date = Date::create(1999, 2, 1, 0, 0, 0, new TimeZone('Europe/Berlin'));
     $this->assertEquals(Date::create(1999, 3, 1, 0, 0, 0, new TimeZone('Europe/Berlin')), DateUtil::addMonths($date, 1));
     $this->assertEquals(Date::create(1999, 3, 3, 0, 0, 0, new TimeZone('Europe/Berlin')), DateUtil::addDays($date, 30));
 }
開發者ID:Gamepay,項目名稱:xp-framework,代碼行數:6,代碼來源:DateUtilTest.class.php


注:本文中的DateUtil::addMonths方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。