/**
  * 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
0
 /**
  * @param string|\DateInterval $spec
  */
 public function __construct($spec)
 {
     if ($spec instanceof \DateInterval) {
         $spec = $this->format2iso($spec);
     }
     parent::__construct($spec);
 }
Пример #3
0
 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * @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
0
 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);
 }
 public function __construct($interval_spec)
 {
     parent::__construct($interval_spec);
     $this->calculateTotals();
 }
Пример #9
0
 /**
  * Unserialization interface
  * @return void
  */
 public function unserialize($data)
 {
     parent::__construct($data);
 }
Пример #10
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * @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
0
 /**
  * @param int $value
  */
 public function __construct($value)
 {
     parent::__construct($value . 's');
 }
 /**
  *
  * @param string $interval_spec
  * @param int    $ms            milliseconds
  */
 public function __construct($interval_spec, $ms = 0)
 {
     parent::__construct($interval_spec);
     $this->ms = (int) $ms;
 }