private function sync_orders($woo_id, $url, $start_at, $batch_size = 100) { echo "Syncing with {$url}.\n"; $mongo_orders = $this->mongo_db->selectCollection('orders'); $t = new DateTime("@{$start_at}"); $start_at_t = $t->format(DateTime::RFC3339); $start_at_t = mb_substr($start_at_t, 0, mb_strlen($start_at_t) - 6) . 'Z'; $pages = $at_page = 1; while ($at_page <= $pages) { $result = $this->wcc->orders->get(null, array('filter[updated_at_min]' => $start_at_t, 'filter[limit]' => $batch_size, 'filter[offset]' => $at_page * $batch_size)); if (isset($result['http']['response']['headers']['X-WC-TotalPages'])) { $pages = (int) $result['http']['response']['headers']['X-WC-TotalPages']; } if (isset($result['orders'])) { foreach ($result['orders'] as $order) { $created_at = new DateTime($order['created_at']); $updated_at = new Datetime($order['updated_at']); $completed_at = new DateTime($order['completed_at']); $order['shoplab_user_id'] = $woo_id; $order['created_at_ts'] = $created_at->getTimestamp(); $order['updated_at_ts'] = $updated_at->getTimestamp(); $order['completed_at_ts'] = $completed_at->getTimestamp(); $mongo_orders->update(array('shoplab_user_id' => $order['shoplab_user_id'], 'order_number' => $order['order_number']), $order, array('upsert' => true)); } } if (0 < $pages) { echo "Fetched page {$at_page} (batch size {$batch_size}) of {$pages}.\n"; } else { echo "Nothing more to fetch.\n"; } $at_page++; } }
/** * Transform un objet DateTime en timestamp * @param Datetime|null $datetime * @return array */ public function transform($datetime) { if (!$datetime instanceof \DateTime) { return null; } return $datetime->format("U"); }
/** * Save or update a visitor. */ public function registerVisistor($ipAdress, $pageName) { $isAdmin = $this->securityContext->isGranted(Constants::ROLE_ADMIN); if ($isAdmin) { $dateNow = new \Datetime(); $currentPage = $this->getPageByName($pageName); $totalVisitsPage = $this->getPageByName(Constants::TOTAL_PAGE_NAME); // On cherche le visiteur dans la BDD via son adresse $visitor = $this->findVisitorByIpAddress($ipAdress); if ($visitor !== null) { // Si le visiteur est d�j� connu et sa derni�re connection date de plus // de 5 minutes on consid�re que c'est une nouvelle visite $seconds = $dateNow->getTimestamp() - $visitor->getLastConnection()->getTimestamp(); if ($seconds > 5 * 60) { // new visit $totalVisitsPage->incrementVisits(); $currentPage->incrementVisits(); } // On met simplement � jour sa date de derni�re connection $visitor->setLastConnection($dateNow); } else { // nouveau visiteur $totalVisitsPage->incrementVisits(); $currentPage->incrementVisits(); // On enregistre le visiteur $visitor = $this->createVisitor($ipAdress); } if (!$visitor->hasAlreadyVisitedPage($currentPage)) { $visitor->addPage($currentPage); } } // save or update all entities $this->em->flush(); return $this; }
/** * @Route("/admin/page/template/enregistrer", name = "enregistrer_template" , defaults={} ) * @Template * @I18nDoctrine */ public function EnregistrementAction(Request $request) { $code = $request->request->get('code'); $template = $request->request->get('template'); if ($template == "" || $template == NULL) { die("impossible"); } $dir = $this->dir_theme . $this->container->getParameter('front_theme') . "/"; $file = $template; if (file_exists($dir . $file)) { $now = new \Datetime(); $backup_dir = $dir . $now->format("Y-m-d"); if (!is_dir($backup_dir)) { mkdir($backup_dir); } if (!copy($dir . $file, $backup_dir . "/" . $now->format("H:i:s") . "_" . $file)) { die("Copy impossible"); } $monfichier = fopen($dir . $file, 'w'); fseek($monfichier, 0); fputs($monfichier, $code); fclose($monfichier); } return new Response('ok'); }
/** * @param string|null $format * * @return \Datetime */ public function getUpdatedAt($format = null) { if ($format) { return $this->updatedAt->format($format); } return $this->updatedAt; }
/** * {@inheritdoc} */ public function loadSnapshots(SiteInterface $site) { $now = new \Datetime(); $query = $this->getEntityManager()->createQuery(sprintf(' SELECT s,p FROM %s s INNER JOIN s.page p WHERE s.enabled = 1 AND s.site = %d AND s.publicationDateStart <= \'%s\' AND ( s.publicationDateEnd IS NULL OR s.publicationDateEnd >= \'%s\' ) ORDER BY s.position ASC ', $this->class, $site->getId(), $now->format('Y-m-d H:i:s'), $now->format('Y-m-d H:i:s'))); $query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_INNER_JOIN, true); $query->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'); $query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, $site->getLocale()); $snapshots = array(); foreach ($query->execute() as $snap) { $snapshots[$snap->getPage()->getId()] = $snap; } $this->snapshots = $snapshots; }
/** * Generate an OPML file to export the feeds. * * @copyright Heavily based on a function from FreshRSS. */ function opml_export($feeds) { $tags = array(); foreach ($feeds as $key => $feed) { if (empty($feed['tags'])) { $tags['untagged'][] = $key; continue; } foreach ($feed['tags'] as $tag) { $tags[$tag][] = $key; } } $now = new Datetime(); $txt = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL; $txt .= '<opml version="2.0">' . PHP_EOL; $txt .= "\t" . '<head>' . PHP_EOL; $txt .= "\t\t" . '<title>Export of Freeder feeds</title>' . PHP_EOL; $txt .= "\t\t" . '<dateCreated>' . $now->format(DateTime::RFC822) . '</dateCreated>' . PHP_EOL; $txt .= "\t" . '</head>' . PHP_EOL; $txt .= "\t" . '<body>' . PHP_EOL; foreach ($tags as $tag => $id_feeds) { $txt .= "\t\t" . '<outline text="' . $tag . '">' . PHP_EOL; foreach ($id_feeds as $id_feed) { $website = multiarray_search('rel', 'alternate', $feeds[$id_feed]['links'], ''); if (!empty($website)) { $website = 'htmlUrl="' . htmlspecialchars($website['href'], ENT_COMPAT, 'UTF-8') . '"'; } $txt .= "\t\t\t" . '<outline text="' . htmlspecialchars($feeds[$id_feed]['title'], ENT_COMPAT, 'UTF-8') . '" type="rss" xmlUrl="' . htmlspecialchars($feeds[$id_feed]['url'], ENT_COMPAT, 'UTF-8') . '" ' . $website . ' description="' . htmlspecialchars($feeds[$id_feed]['description'], ENT_COMPAT, 'UTF-8') . '" />' . PHP_EOL; } $txt .= "\t\t" . '</outline>' . PHP_EOL; } $txt .= "\t" . '</body>' . PHP_EOL; $txt .= '</opml>'; return $txt; }
private function isGeekTime(\Datetime $dateTime) { if ($dateTime->format('H:i') == '13:37') { return true; } return false; }
public function diffDias($data) { $date = new \Datetime(null); $hoje = $date->getTimestamp() + $date->getOffset(); $diff = strtotime($data) - $hoje; return floor($diff / (24 * 60 * 60)); }
public function actionExportar() { // get your HTML raw content without any layouts or scripts if (isset($_COOKIE['pcbuilder_cart'])) { $total = 0; $pcbuilder_cart = unserialize($_COOKIE['pcbuilder_cart']); if (count($pcbuilder_cart) > 0) { $pcbuilder_cart = Yii::$app->PCBuilder->array_sort($pcbuilder_cart, 'categoria', 'SORT_ASC'); foreach ($pcbuilder_cart as $i => $peca) { $modelPeca = Pecas::findOne($peca['peca']); $pecas[] = ['id' => $modelPeca['id'], 'cookieID' => $i, 'nome' => $modelPeca['nome'], 'loja' => $modelPeca['loja'], 'link_externo' => $modelPeca['link_externo'], 'preco' => $modelPeca['preco'][0]['preco']]; $total = $total + $modelPeca['preco'][0]['preco']; } } } else { echo "Nada para salvar!"; exit; } if (count($pecas) > 0) { $content = $this->renderPartial('_pdf', ['pecas' => $pecas, 'total' => $total]); $date = new \Datetime(null); $hoje = $date->getTimestamp() + $date->getOffset(); // setup kartik\mpdf\Pdf component $pdf = new Pdf(['mode' => Pdf::MODE_BLANK, 'format' => Pdf::FORMAT_A4, 'orientation' => Pdf::ORIENT_PORTRAIT, 'destination' => Pdf::DEST_DOWNLOAD, 'content' => $content, 'filename' => 'PC Builder - Lista de Peças - ' . date("d.m.Y H.i.s", $hoje) . '.pdf', 'options' => ['title' => 'PC Builder - Lista de Peças - ' . date("d/m/Y H:i:s", $hoje), 'defaultheaderline' => 0, 'setAutoTopMargin' => 'stretch'], 'methods' => ['SetHeader' => ['' . '<table width="100%">' . '<tr>' . '<td width="75%"><a target="_blank" href="http://www.brunodeoliveira.com"><img width="100px" src="imgs/logo.png"></a></td>' . '<td width="25%" valign="bottom" style="text-align: right">Salvo em<br /><small>' . date("d/m/Y H:i:s") . '</small></td>' . '<tr/>' . '</table>' . ''], 'SetFooter' => ['Obrigado por utilizar o PC Builder - Desenvolvido por Bruno de Oliveira - Página {PAGENO}']]]); return $pdf->render(); } }
public function getByDate(\Datetime $date1, \Datetime $date2) { $queryBuilder = $this->createQueryBuilder('a'); $queryBuilder->where('a.date BETWEEN :date1 AND :date2')->setParameter('date1', $date1->format('Y-m-d'))->setParameter('date2', $date2->format('Y-m-d')); $query = $queryBuilder->getQuery(); return $query->getResult(); }
public function toDateTime() { $dateTime = new \Datetime(); $dateTime->setDate($this->year, $this->month, $this->day); $dateTime->setTime(0, 0, 0); return $dateTime; }
/** * Rendering decorator * * @param \Datetime $context * @return string */ public function render($context) { if (!$context instanceof \Datetime) { return $context; } return $context->format($this->options['format']); }
/** * Helpfer function relativeDate() */ function relativeDate($date, $args = array()) { // default for $args $defaults = array('lang' => count(site()->languages()) >= 1 ? site()->language()->code() : c::get('relativedate.lang', 'en'), 'length' => c::get('relativedate.length', 2), 'threshold' => c::get('relativedate.threshold', false), 'fuzzy' => c::get('relativedate.fuzzy', true), 'format' => c::get('relativedate.format', 'd.m.Y')); $args = array_merge($defaults, $args); // check if $date is a timestamp if (RelativeDate::isTimestamp($date)) { $date = date(DATE_ATOM, $date); } // only convert to relative if time difference no exceeds threshold if ($args['threshold'] === false or abs(strtotime($date) - time()) <= $args['threshold']) { try { $relative = new RelativeDate($date, $args); $result = $relative->get($args['length']); } catch (Exception $e) { $result = $date; } } else { $result = $date; } // if we had no change to date due to any bug or exceeding threshold if ($result === $date) { $date = new Datetime($date); $result = $date->format($args['format']); } return $result; }
public function setUp() { parent::setUp(); $date = new Datetime(); $dmax = $date->format("Y-m-d H:i:s"); $date->modify('-6 month'); $dmin = $date->format("Y-m-d H:i:s"); $databoxes = self::$DI['app']->getDataboxes(); $ret = []; foreach ($databoxes as $databox) { $colls = $databox->get_collections(); $rett = []; foreach ($colls as $coll) { $rett[$coll->get_coll_id()] = $coll->get_coll_id(); } $ret[$databox->get_sbas_id()] = implode(',', $rett); } foreach ($ret as $sbasid => $collections) { $report = new module_report_connexion(self::$DI['app'], $dmin, $dmax, $sbasid, $collections); if (!$this->report instanceof module_report) { $this->report = $report; } elseif ($report->getTotal() > $this->report->getTotal()) { $this->report = $report; } } $this->report->setFilter([['f' => 'user', 'o' => '=', 'v' => 'admin'], ['f' => 'ddate', 'o' => 'LIKE', 'v' => '*'], ['f' => '1', 'o' => 'OR', 'v' => '1']]); $this->report->setUser_id(self::$DI['user']->getId()); $this->report->setOrder('user', 'ASC'); $this->filter = new module_report_sqlfilter(self::$DI['app'], $this->report); }
/** * {@inheritdoc} * * @return string */ public function reverseTransform($value) { if (empty($value)) { return null; } $datetime = new \Datetime($value->format($this->format)); return $datetime->format($this->format); }
public function __construct($type, $batchId, $options) { $this->type = $type; $this->batchId = $batchId; $this->options = $options; $now = new \Datetime(); $this->createdTimestamp = $now->format('c'); }
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(); }
/** * @param \Datetime $date * @param \Datetime $date2 * @return array */ public function getByDate(\Datetime $date, \Datetime $date2) { $from = new \DateTime($date->format("Y-m-d") . " 00:00:00"); $to = new \DateTime($date2->format("Y-m-d") . " 23:59:59"); $qb = $this->createQueryBuilder(); $qb->select('c')->from('AppBundle:Event', 'c')->Where('c.date BETWEEN :from AND :to')->setParameter('from', $from)->setParameter('to', $to); $result = $qb->getQuery()->getResult(); return $result; }
/** * Retorna Date formatado * * @param string|null $date * @return string|Plugin\Formatar */ public function porExtenso($date) { $this->setData($date); $meses = array(1 => "Janeiro", 2 => "Fevereiro", 3 => "Março", 4 => "Abril", 5 => "Maio", 6 => "Junho", 7 => "Julho", 8 => "Agosto", 9 => "Setembro", 10 => "Outubro", 11 => "Novembro", 12 => "Dezembro"); if (!$this->data instanceof \DateTime) { return 'data inválida!'; } return $this->data->format('d') . ' de ' . $meses[$this->data->format('n')] . ' de ' . $this->data->format('Y'); }
/** * Get Nb Order BY Month * */ public function getNbOrderByMonth($user, $dateBegin = null) { if (!$dateBegin) { $dateBegin = new \Datetime('now'); } $query = $this->getEntityManager()->createQuery("\n SELECT COUNT(o) AS nb, DATE_FORMAT(:dateBegin, '%Y-%m') AS d\n FROM StoreBackendBundle:Order o\n WHERE o.jeweler = :user\n AND MONTH(o.dateCreated) = :month\n AND YEAR(o.dateCreated) = :year\n ")->setParameter('user', $user)->setParameter('dateBegin', $dateBegin->format('Y-m-d'))->setParameter('month', $dateBegin->format('m'))->setParameter('year', $dateBegin->format('Y')); //exit(var_dump($query->getSingleResult())); return $query->getSingleResult(); }
public function index() { $user = \Auth::user(); $times = $user->times; $today = new \Datetime("today"); $factory = new \CalendR\Calendar(); $month = $factory->getMonth($today->format('Y'), $today->format('m')); return view('dashboard.index', ['user' => $user, 'times' => $times, 'today' => $today, 'factory' => $factory, 'month' => $month]); }
/** * Normalizes DateTime object * * @param null|\Datetime $utcDatetime * * @return null|string */ protected function normalizeDateTime($utcDatetime) { if (!$utcDatetime instanceof \DateTime) { return; } $datetime = new \DateTime(); $datetime->setTimestamp($utcDatetime->getTimestamp()); return $datetime->format('Y-m-d g:i:s A'); }
protected function writeMetaMarkdown($dir, \Datetime $dt, $slug, $title, $tag) { $meta = array('---', 'layout: post', sprintf('title: "%s"', $title), sprintf('date: %s', $dt->format('Y-m-d H:i')), 'comments: false', sprintf('categories: [%s]', implode(', ', array_map(function ($t) { return sprintf("'%s'", $t); }, $tag))), '---'); $filename = sprintf("%s-%s.markdown", $dt->format('Y-m-d'), $slug); $path = $dir . "/" . $filename; file_put_contents($path, implode("\n", $meta) . "\n"); return $filename; }
/** * formatDate * Format a datetime to a readable date according to the locale * @param \Datetime $date */ public function formatDate(\Datetime $date) { $locale = $this->container->getParameter('locale'); $format = "%A, %#d %B %Y"; // windows does not support %e so we put %#d if (substr($locale, 0, 2) === "fr") { $format = str_replace(',', '', $format); } return strftime($format, $date->getTimestamp()); }
public function fetchOverdueOpenReminders() { $em = $this->getEntityManager(); $today = new \Datetime(); $query = $em->createQuery('SELECT d FROM AppBundle:Document d WHERE d.reminderDueDate < :now AND d.reminderStatus = :status ORDER BY d.reminderDueDate ASC')->setParameter("now", $today->format('Y-m-d'))->setParameter("status", "offen"); return $query->getResult(); }
public function createProductReport(YousticeShopProduct $product, $code) { $data = $product->toArray(); $now = new Datetime(); $request_data = array('orderNumber' => $code, 'itemDescription' => $data['description'], 'itemName' => $data['name'], 'itemCurrency' => $data['currency'], 'itemPrice' => $data['price'], 'itemCode' => $data['id'], 'deliveryDate' => $data['deliveryDate'], 'orderDate' => $data['orderDate'] ? $data['orderDate'] : $now->format(Datetime::ISO8601), 'shopType' => $this->shop_software_type, 'image' => $data['image'], 'other' => $data['other']); $url = $this->generateUrl('services/Api/addTransaction'); $this->post($url, $request_data); $response = $this->responseToArray(); return $response['redirect_link']; }
public function insert($fileData) { $now = new Datetime('now'); $data = array('name' => $fileData['file_name'], 'info' => serialize($fileData), 'upload_at' => $now->format('Y-m-d H:i:s')); if (isset($fileData['label'])) { $data['label'] = $fileData['label']; } $this->add($data); return $this->lastInsertId; }
public function Items() { $this->Pages = Versioned::get_by_stage('SiteTree', 'Live'); $newPages = new DataObjectSet(); foreach ($this->Pages as $page) { // Only include pages from this host if (parse_url($page->AbsoluteLink(), PHP_URL_HOST) == $_SERVER['HTTP_HOST']) { // If the page has been set to 0 priority, we set a flag so it won't be included if (isset($page->Priority) && $page->Priority <= 0) { $page->Include = false; } else { $page->Include = true; } // The one field that isn't easy to deal with in the template is // Change frequency, so we set that here. $properties = $page->toMap(); $created = new Datetime($properties['Created']); $now = new Datetime(); $versions = $properties['Version']; $timediff = $now->format('U') - $created->format('U'); // Check how many revisions have been made over the lifetime of the // Page for a rough estimate of it's changing frequency. $period = $timediff / ($versions + 1); if ($period > 60 * 60 * 24 * 365) { // > 1 year $page->ChangeFreq = 'yearly'; } else { if ($period > 60 * 60 * 24 * 30) { // > ~1 month $page->ChangeFreq = 'monthly'; } else { if ($period > 60 * 60 * 24 * 7) { // > 1 week $page->ChangeFreq = 'weekly'; } else { if ($period > 60 * 60 * 24) { // > 1 day $page->ChangeFreq = 'daily'; } else { if ($period > 60 * 60) { // > 1 hour $page->ChangeFreq = 'hourly'; } else { // < 1 hour $page->ChangeFreq = 'always'; } } } } } $newPages->push($page); } } return $newPages; }
/** * @covers WindowsAzure\MediaServices\Models\TaskHistoricalEvent::getTimeStamp * @covers WindowsAzure\MediaServices\Models\TaskHistoricalEvent::__construct */ public function testGetTimeStamp() { // Setup $options = array('TimeStamp' => '2013-11-27'); $time = new \Datetime($options['TimeStamp']); $histEvent = TaskHistoricalEvent::createFromOptions($options); // Test $result = $histEvent->getTimeStamp(); // Assert $this->assertEquals($time->getTimestamp(), $result->getTimestamp()); }