本文整理匯總了PHP中DateTime::sub方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateTime::sub方法的具體用法?PHP DateTime::sub怎麽用?PHP DateTime::sub使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DateTime
的用法示例。
在下文中一共展示了DateTime::sub方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: foreach
public function topページ_初期表示(\AcceptanceTester $I)
{
$I->wantTo('EF0101-UC01-T01 TOPページ 初期表示');
$I->amOnPage('/');
// カテゴリ選択ボックス(キーワード検索用)、キーワード検索入力欄、蟲眼鏡ボタンが表示されている
$I->see('全ての商品', '#search #category_id');
$I->see('', '#search #name');
$I->see('', '#search .bt_search');
// カテゴリ名(カテゴリ検索用)が表示されている
$categories = Fixtures::get('categories');
foreach ($categories as $category) {
$I->see($category->getName(), '#search #category_id option');
}
//管理側のコンテンツ管理(新著情報管理)に設定されている情報が、順位順に表示されている
$today = new DateTime();
$minus1 = $today->sub(new DateInterval('P1D'));
$minus2 = $today->sub(new DateInterval('P2D'));
$I->haveInDatabase('dtb_news', array('news_id' => rand(999, 9999), 'news_date' => $minus1->format('Y-m-d 00:00:00'), 'news_title' => 'タイトル1', 'news_comment' => 'コメント1', 'creator_id' => 1, 'rank' => 2, 'create_date' => $today->format('Y-m-d 00:00:00'), 'update_date' => $today->format('Y-m-d 00:00:00')));
$I->haveInDatabase('dtb_news', array('news_id' => rand(999, 9999), 'news_date' => $minus2->format('Y-m-d 00:00:00'), 'news_title' => 'タイトル2', 'news_comment' => 'コメント2', 'creator_id' => 1, 'rank' => 3, 'create_date' => $today->format('Y-m-d 00:00:00'), 'update_date' => $today->format('Y-m-d 00:00:00')));
$I->reloadPage();
$news = Fixtures::get('news');
$newsset = array();
$newsset[] = array('date' => $news[0]->getDate(), 'title' => $news[0]->getTitle(), 'comment' => $news[0]->getComment());
$newsset[] = array('date' => $minus1->format('Y-m-d 00:00:00'), 'title' => 'タイトル1', 'comment' => 'コメント1');
$newsset[] = array('date' => $minus2->format('Y-m-d 00:00:00'), 'title' => 'タイトル2', 'comment' => 'コメント2');
foreach ($newsset as $key => $news) {
$I->see($news['title'], '#news_area .newslist dl:nth-child(' . (count($newsset) - $key) . ') .news_title');
}
}
示例2: getExRatesTable
/**
* Get the ExRatesTable instance
*
* @param \DateTime $pubDate Optional rates table publication date
*
* @return ExRatesTable
*
* @throws \Exception
*/
public function getExRatesTable(\DateTime $pubDate = null)
{
$this->setSoughtPubDate($pubDate);
$i = 0;
do {
// Limit the number of times the loop repeats
if ($i === self::MAX_ONE_TIME_API_REQ) {
throw new \Exception('Max requests to api limit has been reached');
}
// If user doesn't want a specific date, try to get the rates from the last working day
if (!$pubDate) {
$this->soughtPubDate = $this->soughtPubDate->sub(new \DateInterval('P1D'));
}
// Try to find the file in cache, otherwise download it
if ($this->cachePath && ($cachedXml = $this->getCachedXml())) {
$rawContent = $cachedXml;
} else {
$rawContent = $this->downloadXml();
}
// If a specific date is sought then break, otherwise continue
if ($pubDate) {
break;
}
$i++;
} while (!$rawContent);
if (!$rawContent) {
throw new \Exception('Exchange rates file not found');
}
return $this->ratesTableFactory->getInstance($rawContent);
}
示例3: _setup_events
/**
* This just setsup some events in the db for running certain tests that query getting events back.
* @since 4.6.x
*/
protected function _setup_events()
{
//setup some dates we'll use for testing with.
$timezone = new DateTimeZone('America/Toronto');
$upcoming_start_date = new DateTime("now +2hours", $timezone);
$past_start_date = new DateTime("now -2days", $timezone);
$current_end_date = new DateTime("now +2days", $timezone);
$current = new DateTime("now", $timezone);
$formats = array('Y-d-m', 'h:i a');
$full_format = implode(' ', $formats);
//setup some datetimes to attach to events.
$datetimes = array('expired_datetime' => $this->factory->datetime->create(array('DTT_EVT_start' => $past_start_date->format($full_format), 'DTT_EVT_end' => $past_start_date->format($full_format), 'timezone' => 'America/Toronto', 'formats' => $formats)), 'upcoming_datetime' => $this->factory->datetime->create(array('DTT_EVT_start' => $upcoming_start_date->format($full_format), 'DTT_EVT_end' => $upcoming_start_date->format($full_format), 'timezone' => 'America/Toronto', 'formats' => $formats)), 'active_datetime' => $this->factory->datetime->create(array('DTT_EVT_start' => $current->sub(new DateInterval("PT2H"))->format($full_format), 'DTT_EVT_end' => $current_end_date->add(new DateInterval("PT2H"))->format($full_format), 'timezone' => 'America/Toronto', 'formats' => $formats)), 'sold_out_datetime' => $this->factory->datetime->create(array('DTT_EVT_start' => $upcoming_start_date->format($full_format), 'DTT_EVT_end' => $upcoming_start_date->format($full_format), 'DTT_reg_limit' => 10, 'DTT_sold' => 10, 'timezone' => 'America/Toronto', 'formats' => $formats)), 'inactive_datetime' => $this->factory->datetime->create(array('DTT_EVT_start' => $current->sub(new DateInterval("PT2H"))->format($full_format), 'DTT_EVT_end' => $current_end_date->add(new DateInterval("PT2H"))->format($full_format), 'timezone' => 'America/Toronto', 'formats' => $formats)));
//setup some events
$events = $this->factory->event->create_many('4');
//add datetimes to the events.
$events[0]->_add_relation_to($datetimes['expired_datetime'], 'Datetime');
$events[0]->save();
$events[1]->_add_relation_to($datetimes['upcoming_datetime'], 'Datetime');
$events[1]->save();
$events[2]->_add_relation_to($datetimes['active_datetime'], 'Datetime');
$events[2]->save();
$events[3]->_add_relation_to($datetimes['sold_out_datetime'], 'Datetime');
$events[3]->save();
foreach ($events as $event) {
$event->set('status', 'publish');
$event->save();
}
//one more event that is just going to be inactive
$final_event = $this->factory->event->create();
$final_event->_add_relation_to($datetimes['inactive_datetime'], 'Datetime');
$final_event->save();
}
示例4: start
/**
* @param BusContextInterface $busContext
*
* @throws UnexpectedValueException
*/
public function start(BusContextInterface $busContext)
{
if ($this->daysToKeepDeduplicationData === null) {
$this->daysToKeepDeduplicationData = 7;
} elseif (!ctype_digit((string) $this->daysToKeepDeduplicationData)) {
throw new UnexpectedValueException("Invalid value value used for days to keep deduplication data. Please ensure it is a positive integer.");
}
$this->outboxPersister->removeEntriesOlderThan($this->now->sub(new \DateInterval("P{$this->daysToKeepDeduplicationData}D")));
}
示例5: calculaFeriadosMoveis
private function calculaFeriadosMoveis($ano)
{
$pascoa = new DateTime();
$pascoa->setTimestamp(easter_date($ano));
$this->feriados['pascoa'] = $pascoa->format('d/m');
$this->feriados['terca_carnaval'] = $pascoa->sub(new DateInterval('P47D'))->format('d/m');
$this->feriados['quarta_cinzas'] = $pascoa->sub(new DateInterval('P46D'))->format('d/m');
$this->feriados['sexta_santa'] = $pascoa->sub(new DateInterval('P2D'))->format('d/m');
$this->feriados['corpus_christi'] = $pascoa->sub(new DateInterval('P60D'))->format('d/m');
}
示例6: onPlainFilter_creation_date
public function onPlainFilter_creation_date($filterName, $filterValue, $criteria)
{
$curDate = new DateTime();
if ($filterValue === 'today') {
$condition = 'created_ts >= "' . $curDate->format('Y-m-d') . '"';
} elseif ($filterValue === 'week') {
$condition = 'created_ts >= "' . $curDate->sub(new DateInterval('P1W'))->format('Y-m-d') . '"';
} elseif ($filterValue === 'month') {
$condition = 'created_ts >= "' . $curDate->sub(new DateInterval('P1M'))->format('Y-m-d') . '"';
} else {
return;
}
$criteria->mergeWith(array('condition' => $condition));
}
示例7: testGetAuditsWithDateFilters
/**
* @param array $audit
*
* @depends testGetAudits
*/
public function testGetAuditsWithDateFilters($audit)
{
$loggedAt = new \DateTime('now', new \DateTimeZone('UTC'));
$loggedAt->setTimestamp(strtotime($audit['loggedAt']));
$loggedGTEFilter = '?loggedAt>=' . $loggedAt->format(\DateTime::ISO8601);
$loggedGTFilter = '?loggedAt>' . $loggedAt->sub(new \DateInterval('PT1H'))->format(\DateTime::ISO8601);
$loggedLTFilter = '?loggedAt<' . $loggedAt->sub(new \DateInterval('P1D'))->format(\DateTime::ISO8601);
$this->client->request('GET', $this->getUrl('oro_api_get_audits') . $loggedGTEFilter);
$this->assertCount(1, $this->getJsonResponseContent($this->client->getResponse(), 200));
$this->client->request('GET', $this->getUrl('oro_api_get_audits') . $loggedGTFilter);
$this->assertCount(1, $this->getJsonResponseContent($this->client->getResponse(), 200));
$this->client->request('GET', $this->getUrl('oro_api_get_audits') . $loggedLTFilter);
$this->assertEmpty($this->getJsonResponseContent($this->client->getResponse(), 200));
}
示例8: followingRunFor
/**
* @Given /^following run for "([^"]+)":$/
*/
public function followingRunFor($name, TableNode $table)
{
$app = $this->getApplication();
$project = $app['project_list']->get($name);
$methods = array('created_at' => function (RunUnit $unit, $val) {
$int = new \DateInterval($val);
$now = new \DateTime();
$unit->setCreatedAt($now->sub($int));
}, 'started_at' => function (RunUnit $unit, $val) {
$int = new \DateInterval($val);
$now = new \DateTime();
$unit->setStartedAt($now->sub($int));
}, 'finished_at' => function (RunUnit $unit, $val) {
$int = new \DateInterval($val);
$now = new \DateTime();
if (!$unit->getStartedAt()) {
$unit->setStartedAt($now->sub($int));
}
$unit->setFinishedAt($now->sub($int));
}, 'feature' => function (RunUnit $unit, $val) {
$unit->setFeature($val);
}, 'return_code' => function (RunUnit $unit, $val) {
$unit->setReturnCode($val);
});
$headers = $table->getRow(0);
foreach ($headers as $col) {
if (!isset($methods[$col])) {
throw new \RuntimeException(sprintf('No handler for column "%s".', $col));
}
}
$run = new Run();
$run->setProjectName($name);
$units = $run->getUnits();
foreach ($table->getRows() as $i => $row) {
if ($i == 0) {
continue;
}
$unit = new RunUnit();
foreach ($headers as $i => $header) {
$value = $row[$i];
if ($value === '@null') {
continue;
}
$methods[$header]($unit, $row[$i]);
}
$units->add($unit);
}
$app['run_storage']->saveRun($run);
}
示例9: getEndDate
public function getEndDate(int $months, string $dateFormat = 'Y-m-d') : string
{
$date = new DateTime($this->format('Y-m-d'));
$date->add(new DateInterval("P" . $months . "M"));
$date->sub(new DateInterval("P1D"));
return $date->format($dateFormat);
}
示例10: prepareDateInterval
/**
* Subtract given interval from current date time
*
* @param string $intervalString
*
* @return \DateTime
*/
protected function prepareDateInterval($intervalString = null)
{
$date = new \DateTime('now', new \DateTimeZone('UTC'));
$intervalString = $intervalString ?: $this->getContainer()->getParameter('oro_batch.cleanup_interval');
$date->sub(\DateInterval::createFromDateString($intervalString));
return $date;
}
示例11: save
public function save()
{
$data = $this->getData();
unset($data['name']);
if ($id = $this->getData('id')) {
$data['id'] = $id;
}
if ($new = \Arr::get($data, 'since_new', null)) {
if ($id) {
$_date = new \DateTime($new);
$_date->sub(new \DateInterval('P1D'));
$close = ['id' => $id];
$close['till'] = $_date->format('Y-m-d');
$this->model('ManagerTimeSheet')->upsert($close);
$id = 0;
$data['since'] = $new;
unset($data['id']);
}
}
unset($data['since_new']);
unset($data['till']);
if (empty($data['id'])) {
if (isset($data['id'])) {
unset($data['id']);
}
}
$_id = $this->model('ManagerTimeSheet')->upsert($data);
$id = $id ? $id : $_id;
return $this->model('ManagerTimeSheet')->getById($id);
}
示例12: hasTooManyFailedAttempts
/**
* Checks if there are not too many login attempts using specified username in the specified number of seconds until now.
* @param string $username
* @param integer $count_limit number of login attempts
* @param integer $time_limit number of seconds
* @return boolean
*/
public static function hasTooManyFailedAttempts($username, $count_limit = 5, $time_limit = 1800)
{
$since = new DateTime();
$since->sub(new DateInterval("PT{$time_limit}S"));
$subquery = Yii::$app->db->createCommand()->select('is_successful')->from(self::tableName())->where('username = :username AND performed_on > :since')->order('performed_on DESC')->limit($count_limit)->getText();
return $count_limit <= (int) Yii::$app->db->createCommand()->select('COUNT(NOT is_successful OR NULL)')->from("({$subquery}) AS t")->queryScalar([':username' => $username, ':since' => $since->format('Y-m-d H:i:s')]);
}
示例13: getOldPending
public function getOldPending()
{
$date = new \DateTime();
$i = new \DateInterval('PT30M');
$date->sub($i);
return $this->createQueryBuilder('b')->where('b.created_at < :time')->andWhere('b.status = :status')->setParameter('time', $date)->setParameter('status', \Club\BookingBundle\Entity\Booking::PENDING)->getQuery()->getResult();
}
示例14: get_graph_url
public function get_graph_url($name, $num_days = 40)
{
global $g_db;
$select = $g_db->select()->from('stats', array('date', 'value'))->where('name = ?', $name)->order(array('date DESC'))->limit($num_days + 5);
$values = array();
$rows = $g_db->fetchAll($select);
foreach ($rows as $row) {
$values[$row['date']] = $row['value'];
}
$dates = array();
$labels = array();
$date = new DateTime();
$one_day = new DateInterval("P1D");
for ($i = 0; $i < $num_days; $i++) {
$dates[] = $date->format('Y-m-d');
if ($i % 5 == 0) {
$labels[] = $date->format('d/m');
}
$date->sub($one_day);
}
$labels = array_reverse($labels);
$max_value = max(array_values($values));
$max_value += floor(0.1 * $max_value);
$data = "";
for ($i = 0; $i < $num_days; $i++) {
$value = $values[$dates[$num_days - $i - 1]];
$data .= is_null($value) ? "_" : self::encode_number_e($value, $max_value);
}
return "http://chart.apis.google.com/chart" . "?chxl=1:|" . implode("|", $labels) . "&chxr=0,0,{$max_value}" . "&chxt=y,x" . "&chs=460x150" . "&cht=lc" . "&chco=3D7930" . "&chd=e:{$data}" . "&chg=7.15,-1,1,0" . "&chm=B,C5D4B5BB,0,0,0";
}
示例15: load
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$userManager = $this->container->get('oro_user.manager');
$admin = $userManager->findUserByEmail(LoadAdminUserData::DEFAULT_ADMIN_EMAIL);
$organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
foreach ($this->orderData as $data) {
$entity = new Order();
$entity->setOwner($admin);
$entity->setOrganization($organization);
$created = new \DateTime('now', new \DateTimeZone('UTC'));
$entity->setCreatedAt($created->sub(new \DateInterval($data['createdSub'])));
$updated = new \DateTime('now', new \DateTimeZone('UTC'));
$entity->setUpdatedAt($updated->sub(new \DateInterval($data['updatedSub'])));
$data['channel'] = $this->getReference('integration');
$data['dataChannel'] = $this->getReference('default_channel');
$data['cart'] = $this->getReference('cart');
$data['store'] = $this->getReference('store');
$data['customer'] = $this->getReference('customer');
$this->setEntityPropertyValues($entity, $data, ['reference', 'createdSub', 'updatedSub']);
$this->setReference($data['reference'], $entity);
$manager->persist($entity);
}
$manager->remove($this->getReference('order'));
$manager->flush();
}