当前位置: 首页>>代码示例>>PHP>>正文


PHP Datetime::sub方法代码示例

本文整理汇总了PHP中Datetime::sub方法的典型用法代码示例。如果您正苦于以下问题:PHP Datetime::sub方法的具体用法?PHP Datetime::sub怎么用?PHP Datetime::sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Datetime的用法示例。


在下文中一共展示了Datetime::sub方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: findToPurge

 public function findToPurge($days)
 {
     $qb = $this->createQueryBuilder('a');
     $dateBascule = new \Datetime();
     $dateBascule->sub(new \DateInterval('P' . $days . 'D'));
     $qb->where('a.date < :dateBascule')->setParameter('dateBascule', date_format($dateBascule, 'Y-m-d'))->andWhere('a.nbApplications > 0');
     return $qb->getQuery()->getResult();
 }
开发者ID:rthreis,项目名称:GST,代码行数:8,代码来源:AdvertRepository.php

示例2: testCasoEmQuePrazoEstaVencido

 public function testCasoEmQuePrazoEstaVencido()
 {
     $dt = new \Datetime();
     $prazo = $dt->sub(\DateInterval::createFromDateString("4 months"));
     //"2015-05-30";
     $this->assertInstanceOf("DateTime", $prazo);
     $this->assertTrue(is_object($prazo));
     $this->assertTrue(is_string($prazo->format("Y-m-d")));
     $this->assertTrue($this->dt->isValid($prazo->format("Y-m-d")));
     $prazo2 = $prazo->format("y-m-d h:i:s");
     $this->assertTrue($this->dt->isValid($prazo2));
 }
开发者ID:diego3,项目名称:myframework-core,代码行数:12,代码来源:DateTest.php

示例3: purge

 public function purge($days)
 {
     $date = new \Datetime();
     $date->sub(new \DateInterval("P.{$days}.D"));
     $advert = $this->em->getRepository("OCPlatformBundle:Advert");
     $listAdverts = $advert->getAdvertsUpdatedBefore($date);
     foreach ($listAdverts as $advert) {
         $this->em->remove($advert);
     }
     $this->em->flush();
     return count($listAdverts);
 }
开发者ID:gabrielvv,项目名称:plateforme-symfony,代码行数:12,代码来源:AdvertPurger.php

示例4: clickRecentByLink

 public function clickRecentByLink($link)
 {
     $qb = $this->_em->createQueryBuilder();
     $date = new \Datetime(date('d-m-Y'));
     $date->sub(new \DateInterval('P14D'));
     $qb->select('c')->from('MainSiteBundle:Click', 'c')->where('c.date > :start AND c.link = :link')->setParameter('start', $date)->setParameter('link', $link)->orderBy('c.date', 'asc');
     return $qb->getQuery()->getResult();
 }
开发者ID:tboulogne,项目名称:Smalink,代码行数:8,代码来源:ClickRepository.php

示例5: date_sub

 /**
  * Method to emulate MySQL DATE_SUB() function.
  *
  * This function substracts the time value of $interval expression from $date.
  * $interval is a single quoted strings rewritten by SQLiteQueryDriver::rewrite_query().
  * It is calculated in the private function deriveInterval().
  *
  * @param string $date representing the start date.
  * @param string $interval representing the expression of the time to substract.
  * @return string date formated as '0000-00-00 00:00:00'.
  */
 public function date_sub($date, $interval)
 {
     $interval = $this->deriveInterval($interval);
     switch (strtolower($date)) {
         case "curdate()":
             $objDate = new Datetime($this->curdate());
             $objDate->sub(new DateInterval($interval));
             $returnval = $objDate->format("Y-m-d");
             break;
         case "now()":
             $objDate = new Datetime($this->now());
             $objDate->sub(new DateInterval($interval));
             $returnval = $objDate->format("Y-m-d H:i:s");
             break;
         default:
             $objDate = new Datetime($date);
             $objDate->sub(new DateInterval($interval));
             $returnval = $objDate->format("Y-m-d H:i:s");
     }
     return $returnval;
 }
开发者ID:pthiep,项目名称:pthiepwordpress,代码行数:32,代码来源:functions.php

示例6: confDateTime

 function confDateTime($day, $month, $year, $hour, $minute)
 {
     $link = Link::get_link('domoleaf');
     if (empty($day)) {
         $day = '';
     }
     if (empty($month)) {
         $month = '';
     }
     if (empty($year)) {
         $year = '';
     }
     if (empty($hour)) {
         $hour = 0;
     }
     if (empty($minute)) {
         $minute = 0;
     }
     $time_diff = $this->profileTime();
     $datetime = new Datetime($year . '-' . $month . '-' . $day . 'T' . $hour . ':' . $minute . ':00');
     if ($time_diff > 0) {
         $diff_time = $time_diff;
         $datetime->sub(new DateInterval('PT' . $diff_time . 'S'));
     } else {
         $diff_time = abs($time_diff);
         $datetime->add(new DateInterval('PT' . $diff_time . 'S'));
     }
     $new_date = $datetime->format('Y-m-d H:i:s');
     $send_date = explode(' ', $new_date);
     $socket = new Socket();
     $socket->send('modif_date', $send_date);
 }
开发者ID:bonion,项目名称:Domoleaf,代码行数:32,代码来源:Admin.class.php

示例7: fromVObject

 /**
  * Updates this Calendar2 object with data from the given VEVENT
  *
  * The returned object must be save()d before it is persistent.
  * This also means that additional changes can be made before any database calls are made.
  *
  * @param Sabre_VObject_Component $vevent The vevent component
  *
  * @throws Exception If the provided component is not a vevent
  *
  * @return void
  */
 public function fromVObject(Sabre_VObject_Component $vevent)
 {
     if (strtolower($vevent->name) !== 'vevent') {
         throw new Exception("Invalid type of vobject_component passed to Calendar2_Models_Calendar2::fromVobject ({$vevent->name})");
     }
     // Workarounds for missing features. We currently don't support locale-time (we just assume it's the user's
     // usual timzeone) or date values without time (we just assume 0800 - 2000 there).
     if (!is_null($vevent->dtstart['VALUE']) && $vevent->dtstart['VALUE']->value === 'DATE') {
         // No T means it's only a date. iCalendar dicates that dtend must be a date, too.
         $vevent->dtstart->value .= 'T080000';
         unset($vevent->dtstart['VALUE']);
         // Caldav end dates are not inclusive
         $end = new Datetime($vevent->dtend->value);
         $end->sub(new DateInterval('P1D'));
         $vevent->dtend->value = $end->format('Ymd') . 'T200000';
         unset($vevent->dtend['VALUE']);
     }
     $utc = new DateTimezone('UTC');
     $timezone = null;
     if ('Z' === substr($vevent->dtstart->value, -1)) {
         $timezone = $utc;
     } else {
         if (!is_null($vevent->dtstart['tzid'])) {
             $timezone = new DateTimeZone($vevent->dtstart['tzid']->value);
         } else {
             $timezone = Phprojekt_User_User::getUserDateTimeZone();
         }
     }
     // 0-1
     // handled:
     //  last-mod, description, dtstart, location, summary, uid
     // not handled
     //  class, created, geo, organizer, priority, dtstamp, seq, status, transp, url, recurid
     //
     // none or one of these two
     //  dtend, duration (only assumes dtend case for now)
     //
     // 0 - n
     // TODO: Check how we can handle these. Maybe just concat them?
     // handling: (only one is handled atm, though)
     //  comment, rrule
     // not handling:
     //  attach, attendee, categories, contact, exdate, exrule, rstatus, related, resources, rdate, x-prop
     $mappable = array(array('veventkey' => 'SUMMARY', 'ourkey' => 'summary', 'default' => '_'), array('veventkey' => 'LOCATION', 'ourkey' => 'location', 'default' => ''), array('veventkey' => 'DESCRIPTION', 'ourkey' => 'description', 'default' => ''), array('veventkey' => 'COMMENT', 'ourkey' => 'comments'), array('veventkey' => 'UID', 'ourkey' => 'uid'), array('veventkey' => 'LAST-MODIFIED', 'ourkey' => 'lastModified'), array('veventkey' => 'RRULE', 'ourkey' => 'rrule', 'default' => ''));
     foreach ($mappable as $m) {
         if (isset($vevent->{$m}['veventkey'])) {
             $this->{$m}['ourkey'] = $vevent->{$m}['veventkey'];
         } else {
             if (array_key_exists('default', $m)) {
                 $this->{$m}['ourkey'] = $m['default'];
             }
         }
     }
     $start = new Datetime($vevent->dtstart->value, $timezone);
     $start->setTimezone($utc);
     $this->start = Phprojekt_Converter_Time::utcToUser($start->format('Y-m-d H:i:s'));
     if ($vevent->dtend) {
         $end = new Datetime($vevent->dtend->value, $timezone);
     } else {
         if ($vevent->duration) {
             $duration = new DateInterval($vevent->duration->value);
             $end = clone $start;
             $end->add($duration);
         }
     }
     $end->setTimezone($utc);
     $this->end = Phprojekt_Converter_Time::utcToUser($end->format('Y-m-d H:i:s'));
 }
开发者ID:RainyBlueSky,项目名称:PHProjekt,代码行数:80,代码来源:Calendar2.php

示例8: post

 public function post($interval = 600)
 {
     $memcache = new Memcache();
     $memcache->connect('localhost', 11211) or die("Could not connect");
     echo "memcache activated\n";
     echo "collect past = {$interval} seconds\n";
     $time = new Datetime();
     $time->sub(new DateInterval('PT' . $interval . 'S'));
     echo 'time=' . $time->format('Y-m-d H:i:s');
     echo "\n";
     echo 'time=' . $time->getTimestamp();
     echo "\n";
     $key_pattern = "/\\A\\d\\d\\d\\d-\\d+.\\d+\\z/";
     $posts = array();
     $lists_key = array();
     $allSlabs = $memcache->getExtendedStats('slabs');
     foreach ($allSlabs as $server => $slabs) {
         foreach ($slabs as $slabId => $slabMeta) {
             if (!is_numeric($slabId)) {
                 continue;
             }
             $cdump = $memcache->getExtendedStats('cachedump', (int) $slabId, 0);
             //echo count($cdump);
             foreach ($cdump as $keys => $arrVal) {
                 if (!is_array($arrVal)) {
                     continue;
                 }
                 //echo count($arrVal);
                 foreach ($arrVal as $k => $v) {
                     //						echo $k .' - '.date('H:i d.m.Y',$v[1]).' , ';
                     $res = preg_match($key_pattern, $k);
                     if (!$res) {
                         continue;
                     }
                     $obj = $memcache->get($k);
                     if (!$obj) {
                         continue;
                     }
                     echo $k . ' : ';
                     $key_time = substr($k, 5);
                     if ((double) $key_time >= (double) $time->getTimestamp()) {
                         echo "not yet\n";
                         continue;
                     }
                     $lists_key[] = $k;
                     $posts[] = (array) $obj;
                     echo 'collect : ';
                     echo "\n";
                 }
             }
         }
     }
     echo count($posts) . ' collected';
     echo "\n";
     if (count($posts)) {
         echo "batch insert : ";
         $res = $this->db->insert_batch('post', $posts);
     }
     if (!$res) {
         echo " FAILED\n";
     } else {
         echo " SECCESS\n";
         echo "Delete Key im memcache : ";
         foreach ($lists_key as $lk) {
             $memcache->delete($lk) or die("Could not delete : {$k}\n");
         }
         echo "SUCCESS\n";
     }
     $memcache->close();
     echo "memcache closed\n";
 }
开发者ID:nytonkla,项目名称:stupidspider,代码行数:71,代码来源:collector.php

示例9: getenv

$db = $conn->selectDB(array_reverse(explode('/', getenv('MONGOLAB_URI')))[0]);
//check if users populated
$users = $db->users->find();
if (!$users->hasNext()) {
    $db->users->batchInsert([['name' => 'Lue49'], ['name' => 'Rubye89'], ['name' => 'Bert.Howe99'], ['name' => 'Carley.Pollich'], ['name' => 'Arlie.Lockman'], ['name' => 'Dino.Williamson63'], ['name' => 'Jaycee34'], ['name' => 'Leopoldo.Rutherford12'], ['name' => 'Adelbert.Flatley'], ['name' => 'Jorge.Collier'], ['name' => 'Dee.Schowalter18']]);
    $users = $db->users->find();
}
$users = iterator_to_array($users);
//find last metric date
$mostRecent = $db->metrics->find()->sort(['_id.date' => -1])->limit(1);
if ($mostRecent->hasNext()) {
    $date = $mostRecent->next()['_id']['date']->toDateTime();
    $date->add(new DateInterval('P1D'));
} else {
    $date = new Datetime('now UTC');
    $date->sub(new DateInterval('P30DT5H'));
    $date->setTime(0, 0, 0);
}
echo "Creating metrics starting at {$date->format("Y-m-d")}\n";
//insert metrics
$methods = ['GET' => 90, 'POST' => 30, 'PUT' => 50, 'DELETE' => 20];
$paths = ['/api/posts' => 30, '/api/posts/{id}' => 90, '/api/posts/{id}/comments' => 80, '/api/posts/{id}/comments/{commentId}' => 50, 'rest/reportError' => 2];
$responseCodes = [200 => 90, 304 => 40, 401 => 10, 500 => 5];
$today = new Datetime('now UTC');
$metrics = [];
while ($date < $today) {
    foreach ($users as $user) {
        if (rand(0, 100) > 60) {
            continue;
        }
        foreach ($methods as $m => $mp) {
开发者ID:fearfullymade,项目名称:ro-dash,代码行数:31,代码来源:fillDatabase.php

示例10: linkInfoAction

 /**
  * @Secure(roles="ROLE_USER")
  */
 public function linkInfoAction($id)
 {
     $linkRepo = $this->getDoctrine()->getManager()->getRepository('MainSiteBundle:Link');
     $clickRepo = $this->getDoctrine()->getManager()->getRepository('MainSiteBundle:Click');
     // Lien
     $link = $linkRepo->find($id);
     /* Stats resumée */
     $listeLiensComplete = $linkRepo->findBy(array('author' => $this->container->get('security.context')->getToken()->getUser()));
     $nbLien = count($listeLiensComplete);
     $listeClicksComplete = $clickRepo->findBy(array('link' => $listeLiensComplete));
     $nbClick = count($listeClicksComplete);
     // Graphe Click / Date
     $annee = date('Y');
     $listClick = $clickRepo->clickRecentByLink($link);
     $date_array = array();
     $datetmp = new \Datetime(date('d-m-Y'));
     $datetmp->sub(new \DateInterval('P14D'));
     if (end($listClick)) {
         $endDate = end($listClick)->getDate();
     } else {
         $endDate = new \Datetime('now');
     }
     foreach ($listClick as $key => $click) {
         // detection de la plus ancienne date de click
         if ($datetmp > $click->getDate()) {
             $datetmp = $click->getDate();
         }
     }
     foreach ($listClick as $key => $click) {
         // detection de la plus recente date de click
         if ($endDate < $click->getDate()) {
             $endDate = $click->getDate();
         }
     }
     $endDate->add(new \DateInterval('P1D'));
     while ($datetmp->format('Y-m-d') != $endDate->format('Y-m-d')) {
         $date_array[$datetmp->format('Y-m-d')]['date'] = $datetmp->format('Y-m-d');
         $date_array[$datetmp->format('Y-m-d')]['click'] = 0;
         $datetmp->add(new \DateInterval('P1D'));
     }
     $endDate->sub(new \DateInterval('P1D'));
     foreach ($listClick as $key => $click) {
         if (isset($date_array[$click->getDate()->format('Y-m-d')])) {
             $date_array[$click->getDate()->format('Y-m-d')]['click'] = $date_array[$click->getDate()->format('Y-m-d')]['click'] + 1;
         }
     }
     // Graphe Click / Référant
     $listeRef = $clickRepo->findDistRefByLink($id, 7);
     // Graphe Click / Référant
     $listeCountry = $clickRepo->findDistCountryByLink($id, 7);
     return $this->render('MainSiteBundle:Default:statsLink.html.twig', array('lien' => $link, 'clickList' => $date_array, 'refList' => $listeRef, 'countryList' => $listeCountry));
 }
开发者ID:tboulogne,项目名称:Smalink,代码行数:55,代码来源:DefaultController.php


注:本文中的Datetime::sub方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。