/** * @since 1.8 * * {@inheritDoc} */ public function dataItemFromDBKeys($dbkeys) { if (is_string($dbkeys)) { return DITime::doUnserialize($dbkeys); } throw new DataItemHandlerException('Failed to create data item from DB keys.'); }
public function testSerializeFormatForTimeValue() { $property = \SMW\DIProperty::newFromUserLabel('Foo'); $property->setPropertyTypeId('_dat'); $printRequestFactory = new \SMW\Query\PrintRequestFactory(); $serialization = QueryResultSerializer::getSerialization(\SMWDITime::doUnserialize('2/1393/1/1'), $printRequestFactory->newPropertyPrintRequest($property)); $expected = array('timestamp' => '-18208281600', 'raw' => '2/1393/1/1'); $this->assertEquals($expected, $serialization); }
public function testFormatWithLocalizedMonthReplacement() { // F - A full textual representation of a month, such as January or March $formatOption = 'F Y/m/d H:i:s'; $language = $this->getMockBuilder('\\Language')->disableOriginalConstructor()->getMock(); $language->expects($this->once())->method('getMonthName')->with($this->equalTo('12'))->will($this->returnValue('Foo')); $instance = new IntlTimeFormatter(DITime::doUnserialize('1/2000/12/12/1/1/20.200'), $language); $this->assertEquals('Foo 2000/12/12 01:01:20', $instance->format($formatOption)); }
public function testTryToDeserializeOnInvalidCountOfElementsThrowsException() { $this->setExpectedException('\\SMW\\DataItemException'); DITime::doUnserialize('1'); }
private function getUpperLimit($dataItem) { $prec = $dataItem->getPrecision(); $dateTime = new DateTime(); $dateTime->setDate($dataItem->getYear(), $dataItem->getMonth(), $dataItem->getDay()); $dateTime->setTime($dataItem->getHour(), $dataItem->getMinute(), $dataItem->getSecond()); if ($dateTime === false) { return $this->addError('Cannot compute interval for ' . $dataItem->getSerialization()); } if ($prec === DITime::PREC_Y) { $dateTime->add(new DateInterval('P1Y')); } elseif ($prec === DITime::PREC_YM) { $dateTime->add(new DateInterval('P1M')); } elseif ($prec === DITime::PREC_YMD) { $dateTime->add(new DateInterval('P1D')); } elseif ($prec === DITime::PREC_YMDT) { if ($dataItem->getSecond() > 0) { $dateTime->add(new DateInterval('PT1S')); } elseif ($dataItem->getMinute() > 0) { $dateTime->add(new DateInterval('PT1M')); } elseif ($dataItem->getHour() > 0) { $dateTime->add(new DateInterval('PT1H')); } else { $dateTime->add(new DateInterval('PT24H')); } } return DITime::doUnserialize($dataItem->getCalendarModel() . '/' . $dateTime->format('Y/m/d/H/i/s')); }
/** * @see SMWDataItemHandler::dataItemFromDBKeys() * @since 1.8 * @param array|string $dbkeys expecting string here * * @return SMWDataItem */ public function dataItemFromDBKeys($dbkeys) { if (is_string($dbkeys)) { return SMWDITime::doUnserialize($dbkeys); } else { throw new SMWDataItemException('Failed to create data item from DB keys.'); } }
/** * Method to create a dataitem from an array of DB keys. * * @since 1.8 * @param $dbkeys array of mixed * * @return SMWDataItem */ public function dataItemFromDBKeys($dbkeys) { return SMWDITime::doUnserialize($dbkeys[0]); }