本文整理汇总了PHP中Timestamp::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Timestamp::create方法的具体用法?PHP Timestamp::create怎么用?PHP Timestamp::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timestamp
的用法示例。
在下文中一共展示了Timestamp::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHstore
/**
* Install hstore
* /usr/share/postgresql/contrib # cat hstore.sql | psql -U pgsql -d onphp
**/
public function testHstore()
{
foreach (DBTestPool::me()->getPool() as $connector => $db) {
DBPool::me()->setDefault($db);
$properties = array('age' => '23', 'weight' => 80, 'comment' => null);
$user = TestUser::create()->setCity($moscow = TestCity::create()->setName('Moscow'))->setCredentials(Credentials::create()->setNickname('fake')->setPassword(sha1('passwd')))->setLastLogin(Timestamp::create(time()))->setRegistered(Timestamp::create(time())->modify('-1 day'))->setProperties(Hstore::make($properties));
$moscow = TestCity::dao()->add($moscow);
$user = TestUser::dao()->add($user);
Cache::me()->clean();
TestUser::dao()->dropIdentityMap();
$user = TestUser::dao()->getById('1');
$this->assertInstanceOf('Hstore', $user->getProperties());
$this->assertEquals($properties, $user->getProperties()->getList());
$form = TestUser::proto()->makeForm();
$form->get('properties')->setFormMapping(array(Primitive::string('age'), Primitive::integer('weight'), Primitive::string('comment')));
$form->import(array('id' => $user->getId()));
$this->assertNotNull($form->getValue('id'));
$object = $user;
FormUtils::object2form($object, $form);
$this->assertInstanceOf('Hstore', $form->getValue('properties'));
$this->assertEquals(array_filter($properties), $form->getValue('properties')->getList());
$subform = $form->get('properties')->getInnerForm();
$this->assertEquals($subform->getValue('age'), '23');
$this->assertEquals($subform->getValue('weight'), 80);
$this->assertNull($subform->getValue('comment'));
$user = new TestUser();
FormUtils::form2object($form, $user, false);
$this->assertEquals($user->getProperties()->getList(), array_filter($properties));
}
}
示例2: testStartHour
public function testStartHour()
{
$stamp = Timestamp::create('2010-03-25 14:15:10');
$this->assertNotEquals($stamp->toStamp(), $stamp->getHourStartStamp());
$this->assertTrue(Timestamp::create($stamp->getHourStartStamp()) instanceof Timestamp);
$this->assertEquals(Timestamp::create($stamp->getHourStartStamp())->toString(), '2010-03-25 14:00:00');
}
示例3: testDayDifference
public function testDayDifference()
{
$today = Date::makeToday();
$this->dayDifferenceTest($today, $today, 0);
$timestamp = Timestamp::makeNow();
$this->dayDifferenceTest($timestamp, $timestamp, 0);
$left = Date::create('2008-01-12');
$right = Date::create('2008-01-13');
$this->dayDifferenceTest($left, $right, 1);
$left = Date::create('2008-01-12');
$right = Date::create('2009-01-13');
$this->dayDifferenceTest($left, $right, 367);
$left = Date::create('2008-01-12');
$right = Date::create('2008-01-11');
$this->dayDifferenceTest($left, $right, -1);
$left = Timestamp::create('2008-01-12 01:23:00');
$right = Timestamp::create('2008-01-13 13:01:17');
$this->dayDifferenceTest($left, $right, 1);
// change time from winter to summer
$left = Timestamp::create('2008-03-29 02:00:00');
$right = Timestamp::create('2008-03-30 02:00:00');
$this->dayDifferenceTest($left, $right, 1);
$left = Timestamp::create('2008-03-29 03:00:00');
$right = Timestamp::create('2008-03-30 03:00:00');
$this->dayDifferenceTest($left, $right, 1);
// unsolved giv's case
// $left = Timestamp::create('2008-10-25 03:00:00');
// $right = Timestamp::create('2008-10-26 02:59:00');
// $this->dayDifferenceTest($left, $right, 0);
return $this;
}
示例4: truncate
/**
* @return Timestamp
*
* Emulates PostgreSQL's date_trunc() function
*
**/
public function truncate(Date $time, $ceil = false)
{
$time = $time->toTimestamp();
$function = $ceil ? 'ceil' : 'floor';
if ($this->seconds) {
if ($this->seconds < 1) {
return $time->spawn();
}
$truncated = (int) ($function($time->toStamp() / $this->seconds) * $this->seconds);
return Timestamp::create($truncated);
} elseif ($this->days) {
$epochStartTruncated = Date::create('1970-01-05');
$truncatedDate = Date::create($time->toDate());
if ($ceil && $truncatedDate->toStamp() < $time->toStamp()) {
$truncatedDate->modify('+1 day');
}
$difference = Date::dayDifference($epochStartTruncated, $truncatedDate);
$truncated = (int) ($function($difference / $this->days) * $this->days);
return Timestamp::create($epochStartTruncated->spawn($truncated . ' days')->toStamp());
} elseif ($this->months) {
$monthsCount = $time->getYear() * 12 + ($time->getMonth() - 1);
if ($ceil && $time->getDay() - 1 + $time->getHour() + $time->getMinute() + $time->getSecond() > 0) {
$monthsCount += 0.1;
}
// delta
$truncated = (int) ($function($monthsCount / $this->months) * $this->months);
$months = $truncated % 12;
$years = ($truncated - $months) / 12;
Assert::isEqual($years, (int) $years);
$years = (int) $years;
$months = $months + 1;
return Timestamp::create("{$years}-{$months}-01 00:00:00");
}
Assert::isUnreachable();
}
示例5: testCount
public function testCount()
{
foreach (DBTestPool::me()->getPool() as $db) {
DBPool::me()->setDefault($db);
$this->getDBCreator()->fillDB();
$count = TestUser::dao()->getTotalCount();
$this->assertGreaterThan(1, $count);
$city = TestCity::create()->setId(1);
$newUser = TestUser::create()->setCity($city)->setCredentials(Credentials::create()->setNickname('newuser')->setPassword(sha1('newuser')))->setLastLogin(Timestamp::create(time()))->setRegistered(Timestamp::create(time()));
TestUser::dao()->add($newUser);
$newCount = TestUser::dao()->getTotalCount();
$this->assertEquals($count + 1, $newCount);
}
}
示例6: makeItems
public function makeItems(SimpleXMLElement $xmlFeed)
{
$result = array();
if (isset($xmlFeed->channel->item)) {
foreach ($xmlFeed->channel->item as $item) {
$feedItem = FeedItem::create((string) $item->title)->setContent(FeedItemContent::create()->setBody((string) $item->description))->setPublished(Timestamp::create(strtotime((string) $item->pubDate)))->setLink((string) $item->link);
if (isset($item->guid)) {
$feedItem->setId($item->guid);
}
if (isset($item->category)) {
$feedItem->setCategory((string) $item->category);
}
$result[] = $feedItem;
}
}
return $result;
}
示例7: makeItems
public function makeItems(SimpleXMLElement $xmlFeed)
{
$result = array();
foreach ($xmlFeed->entry as $entry) {
$feedItem = FeedItem::create((string) $entry->title);
if (isset($entry->content)) {
$feedItem->setContent($this->makeFeedItemContent($entry->content));
}
if (isset($entry->summary)) {
$feedItem->setSummary($this->makeFeedItemContent($entry->summary));
}
if (isset($entry->id)) {
$feedItem->setId($entry->id);
}
$result[] = $feedItem->setPublished(Timestamp::create(strtotime((string) $entry->updated)))->setLink((string) $entry->link);
}
return $result;
}
示例8: makeItems
public function makeItems(SimpleXMLElement $xmlFeed)
{
$xmlFeed->registerXPathNamespace(YandexRssFeedFormat::YANDEX_NAMESPACE_PREFIX, YandexRssFeedFormat::YANDEX_NAMESPACE_URI);
$fullTextList = $xmlFeed->xpath('//' . YandexRssFeedFormat::YANDEX_NAMESPACE_PREFIX . ':full-text');
$result = array();
$i = 0;
if (isset($xmlFeed->channel->item)) {
foreach ($xmlFeed->channel->item as $item) {
$feedItem = YandexRssFeedItem::create((string) $item->title)->setContent(FeedItemContent::create()->setBody((string) $item->description))->setPublished(Timestamp::create(strtotime((string) $item->pubDate)))->setFullText((string) $fullTextList[$i++])->setLink((string) $item->link);
if (isset($item->guid)) {
$feedItem->setId($item->guid);
}
if (isset($item->category)) {
$feedItem->setCategory((string) $item->category);
}
$result[] = $feedItem;
}
}
return $result;
}
示例9: receive
/**
* @return Message
**/
public function receive($uTimeout = null)
{
if (!$this->queue) {
throw new WrongStateException('you must set the queue first');
}
if ($uTimeout && $this->getStream()->isEof()) {
usleep($uTimeout);
}
$string = $this->getStream()->readString();
if (!$string && $this->getStream()->isEof()) {
return null;
}
$this->getQueue()->setOffset($this->getStream()->getOffset());
$string = rtrim($string, PHP_EOL);
$chunks = preg_split("/\t/", $string, 2);
$time = isset($chunks[0]) ? $chunks[0] : null;
$text = isset($chunks[1]) ? $chunks[1] : null;
Assert::isNotNull($time);
$result = TextMessage::create(Timestamp::create($time))->setText($text);
return $result;
}
示例10: testCountMonthsNotOverlapped
public function testCountMonthsNotOverlapped()
{
$unit = IntervalUnit::create('month');
$this->assertEquals(4, $result = $unit->countInRange(TimestampRange::create($start = Timestamp::create('2008-12-31 23:59:58'), $end = Timestamp::create('2009-05-28 03:00:00')), false));
$this->assertLessThanOrEqual($end->toStamp(), $start->spawn($result . ' ' . $unit->getName())->toStamp());
}
示例11: spawnUser
/**
* @return TestUser
*/
private function spawnUser($options = array())
{
$options += array('id' => '77', 'credentials' => Credentials::create(), 'lastLogin' => Timestamp::create('2011-12-31'), 'registered' => Timestamp::create('2011-12-30'), 'strangeTime' => Time::create('01:23:45'), 'city' => null, 'firstOptional' => null, 'secondOptional' => null, 'url' => HttpUrl::create()->parse('https://www.github.com'), 'properties' => Hstore::make(array('a' => 'apple', 'b' => 'bananas')), 'ip' => IpAddress::create('127.0.0.1'));
return $this->spawnObject(TestUser::create(), $options);
}
示例12: alignToSecondsDataProvider
public static function alignToSecondsDataProvider()
{
return array(array(Timestamp::create('2009-01-01 10:00:42'), '2009-01-01 10:00:42'), array(Timestamp::create('2009-01-01 10:00:41'), '2009-01-01 10:00:00'), array(Timestamp::create('2009-01-01 10:01:34'), '2009-01-01 10:01:24'), array(Timestamp::create('2009-01-01 10:10:01'), '2009-01-01 10:09:48'));
}
示例13: alignToSeconds
/**
* @return Timestamp
**/
public static function alignToSeconds(Timestamp $stamp, $seconds)
{
$rawStamp = $stamp->toStamp();
$align = floor($rawStamp / $seconds);
return Timestamp::create($align * $seconds);
}
示例14: testSleeping
public function testSleeping()
{
$stamp = Timestamp::makeNow();
$serializedStamp = serialize($stamp);
$unserializedStamp = unserialize($serializedStamp);
$this->assertEquals($stamp->getDay(), $unserializedStamp->getDay());
$this->assertEquals($stamp->getMonth(), $unserializedStamp->getMonth());
$this->assertEquals($stamp->getYear(), $unserializedStamp->getYear());
$this->assertEquals($stamp->getMinute(), $unserializedStamp->getMinute());
$this->assertEquals($stamp->getSecond(), $unserializedStamp->getSecond());
$stamp = Timestamp::create('2039-01-05 12:14:05 Europe/Moscow');
$serializedStamp = serialize($stamp);
$unserializedStamp = unserialize($serializedStamp);
$this->assertEquals($stamp->getDay(), $unserializedStamp->getDay());
$this->assertEquals($stamp->getMonth(), $unserializedStamp->getMonth());
$this->assertEquals($stamp->getYear(), $unserializedStamp->getYear());
$this->assertEquals($stamp->getMinute(), $unserializedStamp->getMinute());
$this->assertEquals($stamp->getSecond(), $unserializedStamp->getSecond());
$stamp = Timestamp::create('1899-12-31 16:07:45 Europe/London');
$serializedStamp = serialize($stamp);
$unserializedStamp = unserialize($serializedStamp);
$this->assertEquals($stamp->getDay(), $unserializedStamp->getDay());
$this->assertEquals($stamp->getMonth(), $unserializedStamp->getMonth());
$this->assertEquals($stamp->getYear(), $unserializedStamp->getYear());
$this->assertEquals($stamp->getMinute(), $unserializedStamp->getMinute());
$this->assertEquals($stamp->getSecond(), $unserializedStamp->getSecond());
}
示例15: toTimestamp
/**
* @return Timestamp
**/
public function toTimestamp()
{
return Timestamp::create($this->toStamp());
}