コード例 #1
0
 public function testOutputInverted()
 {
     $interval = new DateInterval('PT2H5M');
     $interval->invert = true;
     $this->assertEquals('PT-2H-5M', $interval->__toString());
 }
コード例 #2
0
 /**
  * Converts PHP variable not identical to null into native format
  *
  * Note: a passed string will be returned as-is without any attempts to parse it.
  * PostgreSQL's interval parser accepts a lot more possible formats than this
  * class can handle.
  *
  * @param string|number|\DateInterval $value
  * @return string
  * @throws TypeConversionException
  */
 protected function outputNotNull($value)
 {
     if (is_string($value)) {
         return $value;
     } elseif (is_int($value)) {
         return sprintf('%d seconds', $value);
     } elseif (is_float($value)) {
         return rtrim(sprintf('%.6f', $value), '.0') . ' seconds';
     } elseif ($value instanceof \DateInterval) {
         return DateInterval::formatAsISO8601($value);
     }
     throw TypeConversionException::unexpectedValue($this, 'output', 'a string, a number or an instance of DateInterval', $value);
 }