本文整理汇总了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);
}
}
示例2: __construct
/**
* @param string|\DateInterval $spec
*/
public function __construct($spec)
{
if ($spec instanceof \DateInterval) {
$spec = $this->format2iso($spec);
}
parent::__construct($spec);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
示例8: __construct
public function __construct($interval_spec)
{
parent::__construct($interval_spec);
$this->calculateTotals();
}
示例9: unserialize
/**
* Unserialization interface
* @return void
*/
public function unserialize($data)
{
parent::__construct($data);
}
示例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);
}
示例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);
}
示例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);
}
示例13: __construct
/**
* @param int $value
*/
public function __construct($value)
{
parent::__construct($value . 's');
}
示例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;
}