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


PHP DateInterval::__construct方法代碼示例

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


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

示例1: __construct

 /**
  * Creates a TicketEvolution_DateInterval from a DateInterval instance.
  * Makes it easy to pass in a standard PHP DateInterval to create an TicketEvolution_DateInterval
  *
  * NOTE: Even if the $dateInterval you pass in has the 'days' property set
  *       it will be set to boolean false. Apparently you cannot extend
  *       DateInterval and still use the 'days' property. This also means
  *       that you cannot use format('%a') as it will return '(unknown)'
  *
  * @param DateInterval The DateInterval to create from
  * @return Onyx_DateInterval
  */
 public function __construct($dateInterval)
 {
     if ($dateInterval instanceof DateInterval) {
         $period = 'P';
         $time = 'T';
         if ($dateInterval->y > 0) {
             $period .= $dateInterval->y . 'Y';
         }
         if ($dateInterval->m > 0) {
             $period .= $dateInterval->m . 'M';
         }
         if ($dateInterval->d > 0) {
             $period .= $dateInterval->d . 'D';
         }
         if ($dateInterval->h > 0) {
             $time .= $dateInterval->h . 'H';
         }
         if ($dateInterval->i > 0) {
             $time .= $dateInterval->i . 'M';
         }
         if ($dateInterval->s > 0) {
             $time .= $dateInterval->s . 'S';
         }
         if ($time != 'T') {
             $period .= $time;
         }
         parent::__construct($period);
         $this->invert = $dateInterval->invert;
         //$this->days = $dateInterval->days;
     } else {
         parent::__construct($dateInterval);
     }
 }
開發者ID:4ticketdeals,項目名稱:ticketevolution-php,代碼行數:45,代碼來源:DateInterval.php

示例2: __construct

 /**
  * @param string|\DateInterval $spec
  */
 public function __construct($spec)
 {
     if ($spec instanceof \DateInterval) {
         $spec = $this->format2iso($spec);
     }
     parent::__construct($spec);
 }
開發者ID:alexeyshockov,項目名稱:clock,代碼行數:10,代碼來源:Interval.php

示例3: __construct

 public function __construct($time_spec)
 {
     var_dump($this->foo);
     $this->foo = 3;
     var_dump($this->foo);
     var_dump($this->{2});
     parent::__construct($time_spec);
 }
開發者ID:badlamer,項目名稱:hhvm,代碼行數:8,代碼來源:bug62500.php

示例4: __construct

 /**
  * DateIntervalFractions constructor.
  *
  * This class exists because of a bug in PHP. PHP cannot handle a valid ISO 8601 duration.
  * The milliseconds delimited by comma/period are ignored and cause the \DateInterval to crash.
  *
  * Extracting these milliseconds out patches DateInterval to work.
  *
  * @url https://bugs.php.net/bug.php?id=53831
  * @param string $interval_spec
  */
 public function __construct($interval_spec)
 {
     $this->milliseconds = 0;
     $matches = array();
     preg_match_all("#([0-9]*[.,]?[0-9]*)[S]#", $interval_spec, $matches);
     foreach ($matches[0] as $result) {
         $original = $result;
         list($seconds, $milliseconds) = explode(".", substr($result, 0, -1));
         $this->milliseconds = $milliseconds / pow(10, strlen($milliseconds) - 3);
         $interval_spec = str_replace($original, $seconds . "S", $interval_spec);
     }
     parent::__construct($interval_spec);
 }
開發者ID:GMSteuart,項目名稱:PandaLove,代碼行數:24,代碼來源:DateIntervalFractions.php

示例5: __construct

 /**
  * Initialize class
  * 
  * @param string|DateInterval $interval_spec
  */
 public function __construct($interval_spec)
 {
     if ($interval_spec instanceof \DateInterval) {
         $this->y = $interval_spec->y;
         $this->m = $interval_spec->m;
         $this->d = $interval_spec->d;
         $this->h = $interval_spec->h;
         $this->i = $interval_spec->i;
         $this->s = $interval_spec->s;
         $this->invert = $interval_spec->invert;
         $this->days = self::isQuirkMode() && $interval_spec->days == -99999 ? false : $interval_spec->days;
     } else {
         parent::__construct($interval_spec);
     }
 }
開發者ID:sporkcode,項目名稱:spork,代碼行數:20,代碼來源:DateInterval.php

示例6: __construct

 /**
  * @param string $interval_spec
  */
 public function __construct($interval_spec)
 {
     $u = 0;
     if (preg_match('/\\.([0-9]{1,6})/', $interval_spec, $matches)) {
         $u = intval(str_pad(array_pop($matches), 6, 0, STR_PAD_RIGHT));
         $interval_spec = str_replace(array_shift($matches), '', $interval_spec);
     }
     $invert = false;
     if (preg_match('/^-{1}/', $interval_spec, $matches)) {
         $invert = true;
         $interval_spec = str_replace(array_shift($matches), '', $interval_spec);
     }
     parent::__construct($interval_spec);
     $this->u = $u;
     $this->invert = $invert;
     return $this;
 }
開發者ID:alexpts,項目名稱:dtms,代碼行數:20,代碼來源:DateInterval.php

示例7: __construct

 public function __construct($recurrences = 1, $periodDesignator = self::Y)
 {
     $this->_periodDesignator = $periodDesignator;
     switch ($periodDesignator) {
         case self::Y:
             break;
         case self::M:
             break;
         case self::W:
             break;
         case self::D:
             break;
         default:
             throw new \InvalidArgumentException("Only 'Y', 'M', 'W' and 'D' periond designators allowed.");
             break;
     }
     parent::__construct('P' . $recurrences . $periodDesignator);
 }
開發者ID:dansilovsky,項目名稱:calendar,代碼行數:18,代碼來源:CalendarInterval.php

示例8: __construct

 public function __construct($interval_spec)
 {
     parent::__construct($interval_spec);
     $this->calculateTotals();
 }
開發者ID:robertfalconer,項目名稱:Rhubarb,代碼行數:5,代碼來源:RhubarbDateInterval.php

示例9: unserialize

 /**
  * Unserialization interface
  * @return void
  */
 public function unserialize($data)
 {
     parent::__construct($data);
 }
開發者ID:squareproton,項目名稱:bond,代碼行數:8,代碼來源:DateInterval.php

示例10: __construct

 /**
  * Custom construct with support microseconds
  * @param string $interval_spec
  */
 public function __construct($interval_spec)
 {
     if (!preg_match(static::$interval_spec_regex, $interval_spec, $parts)) {
         throw new \UnexpectedValueException(sprintf("%s::%s: Unknown or bad format (%s)", get_called_class(), '__construct', $interval_spec));
     }
     if (isset($parts['s'])) {
         $preciseSeconds = floatval($parts['s']);
         $microseconds = static::secondsToMicroseconds(fmod($preciseSeconds, 1.0));
         $seconds = floor($preciseSeconds);
         $this->u = $microseconds;
         $parts['s'] = $seconds;
     }
     $legacy_spec = static::getLegacySpec($parts);
     parent::__construct($legacy_spec);
 }
開發者ID:oat-sa,項目名稱:tao-core,代碼行數:19,代碼來源:DateIntervalMS.php

示例11: __construct

 /**
  * Constructor.
  *
  * @param string|PHPDateInterval|PHPDateInterval|null $dateIntervalSpec [optional] A date interval specification, a
  *     relative date and time string, a DateInterval or PHPDateInterval instance, or null to use a zero
  *     specification.
  * @param bool $inverted [optional] Defines whether the date interval specification is inverted or not, this
  *     parameter is ignored if a DateInterval or PHPDateInterval instance is given for the $dateIntervalSpec
  *     parameter.
  *
  * @throws Exception Throws an exception on failure.
  */
 public function __construct($dateIntervalSpec, $inverted = false)
 {
     // Try to parse the date interval specification
     if (($spec = DateIntervalSpecUtils::parse($dateIntervalSpec, null)) === null) {
         throw new Exception('Invalid date interval specification (\'' . $dateIntervalSpec . '\' was given)');
     }
     // Copy the inverted state from DateInterval objects
     if ($dateIntervalSpec instanceof parent) {
         $inverted = $dateIntervalSpec->invert;
     }
     // Construct the parent object, and set whether the date interval is inverted
     parent::__construct($spec);
     $this->setInverted($inverted);
 }
開發者ID:timvisee,項目名稱:MohicanenPieGuesser,代碼行數:26,代碼來源:DateInterval.php

示例12: __construct

 /**
  * @param string $intervalSpec Like {@see __construct) but seconds can have
  *  a decimal separator to indicate microseconds. E.g.: PT8.01234S
  */
 public function __construct($intervalSpec)
 {
     // Check input for validity and extract the date/time parts.
     if (!\preg_match(static::$intervalSpecRegex, $intervalSpec, $parts)) {
         throw new UnexpectedValueException(sprintf("%s::%s: Unknown or bad format (%s)", get_called_class(), '__construct', $intervalSpec));
     }
     // Get microseconds from spec.
     if (isset($parts['s'])) {
         $preciseSeconds = floatval($parts['s']);
         $microseconds = static::secondsToMicroseconds(fmod($preciseSeconds, 1.0));
         $seconds = floor($preciseSeconds);
         $this->u = $microseconds;
         $parts['s'] = $seconds;
     }
     // Rebuild the interval spec without microseconds.
     $legacySpec = static::getLegacySpec($parts);
     // Let parent do the rest of the parsing.
     parent::__construct($legacySpec);
 }
開發者ID:bvarent,項目名稱:datetimems,代碼行數:23,代碼來源:DateIntervalMS.php

示例13: __construct

 /**
  * @param int $value
  */
 public function __construct($value)
 {
     parent::__construct($value . 's');
 }
開發者ID:stocked-io,項目名稱:stocked,代碼行數:7,代碼來源:DateInterval.php

示例14: __construct

 /**
  *
  * @param string $interval_spec
  * @param int    $ms            milliseconds
  */
 public function __construct($interval_spec, $ms = 0)
 {
     parent::__construct($interval_spec);
     $this->ms = (int) $ms;
 }
開發者ID:csanquer,項目名稱:fakery-generator,代碼行數:10,代碼來源:DateIntervalExtended.php


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