本文整理汇总了PHP中Datetime::modify方法的典型用法代码示例。如果您正苦于以下问题:PHP Datetime::modify方法的具体用法?PHP Datetime::modify怎么用?PHP Datetime::modify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datetime
的用法示例。
在下文中一共展示了Datetime::modify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
/**
* Lists all Emission entities.
*/
public function indexAction()
{
$breadcrumbs = $this->get("white_october_breadcrumbs");
$breadcrumbs->addItem('Les émissions');
$breadcrumbs->addItem('Grille des programmes');
$format = $this->get('request')->get('_format');
$timestampDay = 60 * 60 * 24;
$timestampWeek = $timestampDay * 7;
if (!empty($_GET['date'])) {
$start = new \Datetime($_GET['date']);
if ($start->format('W') != 1) {
$start->setISODate($start->format('Y'), $start->format('W'), 1);
}
} elseif (!empty($_GET['week'])) {
$start = new \Datetime();
$start->setISODate($start->format('Y'), $_GET['week'], 1);
}
if (empty($start)) {
$start = new \Datetime('now');
$start->setTime(0, 0);
}
$weekNumber = $start->format('W');
// find programs on current week
$dayNumber = $start->format('w');
if ($dayNumber === 0) {
$start->modify('-6 days');
} elseif ($dayNumber > 1) {
$start->modify('-' . ($dayNumber - 1) . ' days');
}
$stop = clone $start;
$stop->modify('+7 days');
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery("SELECT p FROM ProgramBundle:Program p WHERE p.time_stop < :stop AND p.time_start >= :start AND p.time_start < p.time_stop ORDER BY p.time_start ASC, p.time_stop DESC")->setParameters(array('start' => $start, 'stop' => $stop));
$results = $query->getResult();
$entities = array();
for ($i = 0; $i < 7; $i++) {
$day = clone $start;
$day->modify("+{$i} days");
$entities[] = array('date' => $day, 'tot' => array('label' => 'Tôt', 'desc' => 'Avant 7h00', 'entities' => array()), 'am' => array('label' => 'Matinée', 'desc' => '7h00 - 12h00', 'entities' => array()), 'pm' => array('label' => 'Après-midi', 'desc' => '12h00 - 18h00', 'entities' => array()), 'soir' => array('label' => 'Soirée', 'desc' => '18h00 - 21h00', 'entities' => array()), 'nuit' => array('label' => 'Nuit', 'desc' => 'Après 21h00', 'entities' => array()));
}
foreach ($results as $result) {
$weekDay = $result->getTimeStart()->format('N') - 1;
if ($result->getTimeStart()->format('H:i:s') < '07:00:00') {
$entities[$weekDay]['tot']['entities'][] = $result;
} elseif ($result->getTimeStart()->format('H:i:s') < '12:00:00') {
$entities[$weekDay]['am']['entities'][] = $result;
} elseif ($result->getTimeStart()->format('H:i:s') < '18:00:00') {
$entities[$weekDay]['pm']['entities'][] = $result;
} elseif ($result->getTimeStart()->format('H:i:s') < '21:00:00') {
$entities[$weekDay]['soir']['entities'][] = $result;
} else {
$entities[$weekDay]['nuit']['entities'][] = $result;
}
}
return $this->render(sprintf('ProgramBundle:Program:index.%s.twig', $format), array('entities' => $entities, 'count' => count($results), 'weekNumber' => $weekNumber, 'start' => $start, 'stop' => $stop));
}
示例2: setUp
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);
}
示例3: addInvoiceFromTickets
public function addInvoiceFromTickets($clientId, $tickets, $month)
{
if (!$clientId) {
return array('success' => false, 'message' => 'Le code client est inconnu sur Dolibarr', 'id' => null);
}
$now = new \Datetime();
$date31 = new \Datetime($month->format('Y-m') . '-01');
$date31->modify('+1 month');
$date31->modify('-1 day');
$invoice = new Invoice();
$invoice->setCustomerCode($clientId);
$invoice->setAuthorId(1);
$invoice->setDate($date31);
$invoice->setDateDue($date31);
$invoice->setDateCreated($now);
$invoice->setType(0);
usort($tickets, array($this, 'sortTicket'));
foreach ($tickets as $ticket) {
$description = '';
if (strpos($ticket['entity']['name'], 'MARE NOSTRUM >') || strpos($ticket['entity']['name'], 'MALURA')) {
$description = $ticket['entity']['name'] . '<br/>';
}
$invoice_line = new InvoiceLine($invoice);
$invoice_line->setType(1);
$invoice_line->setDescription('<em>' . $ticket['solvedate']->format('d-m-Y') . '</em> : ' . $description . $ticket['name'] . '<br/>' . $ticket['content']);
$invoice_line->setTva($this->tva * 100);
$invoice_line->setQuantity(number_format($this->formatActionTime($ticket['actiontime']) / 60 / 60, 2));
$invoice_line->setUnitPrice($this->unit_price);
$invoice_line->setDateStart($ticket['date']);
$invoice_line->setDateEnd($ticket['solvedate']);
$invoice_line->calculTotals();
}
$result = $this->dolibarr_invoice_connector->addInvoice($invoice);
if ($result['result']->result_code == 'OK') {
return array('success' => true, 'message' => $result['ref'], 'id' => $result['id']);
} else {
return array('success' => false, 'message' => $result['result']->result_label, 'id' => null);
}
}
示例4: programAction
/**
* @Route("/program/{date}.{_format}", defaults={"date": "now", "_format": "html"}, name="oktothek_tv_program_for_date")
* @Template
*/
public function programAction(Request $request, $date = "now")
{
$start = new \Datetime($date);
$start->setTime(8, 0);
$end = new \Datetime($date);
$end->modify('+1 day');
$end->setTime(8, 0);
if ($request->getMethod() != "GET") {
$start = new \Datetime($request['start']);
$end = new \Datetime($request['end']);
}
$shows = $this->get('oktothek_tv')->getShows($start, $end);
return ['shows' => $shows, 'datetime' => $start, 'date' => $start];
}
示例5: createLock
/**
* {@inheritdoc}
*/
protected function createLock()
{
try {
$ttl = null;
if (isset($this->options['ttl']) && $this->options['ttl'] !== 0) {
$now = new \Datetime('now');
$ttl = $this->options['ttl'];
$ttl = $now->modify(sprintf('+%s seconds', $ttl))->format('Y-m-d H:i:s');
}
$status = $this->queryDriver->insertQuery($ttl);
} catch (\Exception $e) {
$status = false;
}
return $status;
}
示例6: verifyToken
/**
* 验证 Token 并使其登录
* @author zhengqian.zhu@dajiayao.cc
*/
protected function verifyToken($tokenStr)
{
// TODO: Redis 缓存 Token
// 判断 Token 有效性
$token = App::where('access_token', '=', $tokenStr)->where('expire_at', '>', date("Y-m-d H:i:s"))->first();
if (!$token) {
return false;
}
// 延长 Token 的有效期
$today = new \Datetime();
$modifier = '+2 hours';
$token->expire_at = $today->modify($modifier);
$token->save();
return $token->app_id;
}
示例7: setUp
public function setUp()
{
parent::setUp();
$date = new Datetime();
$this->dmax = $date->format("Y-m-d H:i:s");
$date->modify('-6 month');
$this->dmin = $date->format("Y-m-d H:i:s");
$databoxes = self::$DI['app']['phraseanet.appbox']->get_databoxes();
$this->ret = [];
foreach ($databoxes as $databox) {
$colls = $databox->get_collections();
$rett = [];
foreach ($colls as $coll) {
$rett[$coll->get_coll_id()] = $coll->get_coll_id();
}
$this->ret[$databox->get_sbas_id()] = implode(',', $rett);
}
}
示例8: getTicketforMonth
public function getTicketforMonth($month, $etat = null)
{
$start_date = new \Datetime($month->format('Y-m' . '-01'));
$end_date = new \Datetime($month->format('Y-m' . '-01'));
$start_date->modify('-6 month');
$end_date->modify('+1 month');
$tickets = $this->ticket_connector->getTicketsFromGLPI($start_date, $end_date, null, null, 'entities_id', 99999, 'facturable', $etat);
$return_tickets = array();
for ($i = 0; $i < count($tickets); $i++) {
if ($tickets[$i]["solvedate"]->format('m') == $month->format('m')) {
$tickets[$i]['entity'] = $this->entity_service->getEntity($tickets[$i]['entities_id']);
$tickets[$i]['id_client_dolibar'] = $this->dolibarr_service->getClientIdFromCodeClient($tickets[$i]['entity']['comment']);
$tickets[$i]['user'] = $this->user_service->getUser($tickets[$i]['users']['assign'][0]['id']);
$return_tickets[] = $tickets[$i];
}
}
usort($return_tickets, array($this, "sortTickets"));
return $return_tickets;
}
示例9: historyAction
public function historyAction($year = '', $month = '')
{
if ($year == '') {
$year = date('Y');
}
if ($month == '') {
$month = date('F');
}
$month_date = new \Datetime($month . ' ' . $year);
$d3_days = '[';
$days_number = cal_days_in_month(CAL_GREGORIAN, $month_date->format('m'), $year);
$start_date = $month_date->modify('first day of this month')->format('Y-m-d');
for ($i = 0; $i < $days_number; $i++) {
$date = strtotime(date("Y-m-d", strtotime($start_date)) . " {$i} day");
$d3_days .= '"' . date('l jS', $date) . '",';
}
$d3_days .= '];';
$template_vars = array('month_name' => $month, 'd3_days' => $d3_days, 'year_number' => $year, 'month_number' => $month);
return $this->render('PowerGridBundle:Default:history.html.twig', $template_vars);
}
示例10: login
public function login($u_id)
{
$user = User::find($u_id);
if (empty($user)) {
throw new Exception("没有找到用户", 3005);
}
if ($user->u_status != 1) {
throw new Exception("您的账号不可用, 请联系客服", 3005);
}
$re = [];
$re['token'] = $user->u_token;
$now = new Datetime();
$now->modify('+ 30 days');
$re['expire'] = $now->format('Y-m-d H:i:s');
$re['id'] = $user->u_id;
$re['name'] = $user->u_name = $this->u_nickname;
$re['nickname'] = $user->u_nickname = $this->u_nickname;
$re['invite_code'] = $user->u_invite_code;
$re['head_img'] = $user->u_head_img = $this->u_head_img;
$re['biograph'] = $user->u_biograph;
$school = DicSchool::find($user->u_school_id);
if (empty($school)) {
$re['city'] = null;
$re['school'] = null;
} else {
$re['city'] = DicCity::where('c_id', '=', $school->t_city)->where('c_province_id', '=', $school->t_province)->first()->showInList();
$re['school'] = $school->showInList();
}
$user->save();
$re['gender'] = $user->u_sex;
$user->load('booths');
$booths = null;
if (!empty($user->booths)) {
foreach ($user->booths as $key => $booth) {
$booths[] = $booth->showInLogin();
}
}
$re['boohts'] = $booths;
return $re;
}
示例11: importVacations
/**
* Hierbei handelt es sich um eine Funktion, die über die URL nicht aufgerufen werden kann.
* Stattdessen wird sie vom AutoController aufgerufen, wenn die Ferien automatisch importiert werden sollen
* Dabei werden Daten, die bereits als Specialdate markiert sind, übersprungen.
*
* @author aloeser
* @return void
*/
public function importVacations()
{
try {
$importyear = date('Y') + 1;
$sourceURL = 'http://www.schulferien.org/iCal/Ferien/icals/Ferien_Berlin_' . $importyear . '.ics';
$icalreader = new ICal($sourceURL);
$events = $icalreader->events();
if ($events == array()) {
//Die angegebene Datei existiert nicht
throw new Exception();
}
$tmpSpecialdates = $this->Specialdate->find('all', array('recursive' => -1, 'conditions' => array('Specialdate.date LIKE ' => $importyear . '-__-__')));
$specialdates = array();
foreach ($tmpSpecialdates as $tmpSpecialdate) {
array_push($specialdates, $tmpSpecialdate['Specialdate']['date']);
}
foreach ($events as $event) {
$timeBegin = $this->icalToUnixtime($event['DTSTART']);
$timeEnd = $this->icalToUnixtime($event['DTEND']);
$datetime = new Datetime(date('Y-m-d', $timeBegin));
for ($i = $timeBegin; $i <= $timeEnd; $i += DAY) {
$dateString = $datetime->format('Y-m-d');
if (!in_array($dateString, $specialdates)) {
//Datum existiert noch nicht
if (!($datetime->format('N') >= 6)) {
//Kein Wochenende -> Specialdate eintragen, um das Datum zu deaktivieren
$this->Specialdate->create();
$this->Specialdate->save(array('Specialdate' => array('date' => $dateString)));
}
} else {
//Datum existiert bereits
}
$datetime->modify("+1 day");
}
}
AutoController::saveLog('Ferienimport', 0, 'SpecialdatesController', 'importVacations');
} catch (Exception $e) {
AutoController::saveLog('Ferienimport', 3, 'SpecialdatesController', 'importVacations');
}
}
示例12: verificarFeriado
function verificarFeriado($dataHora)
{
try {
$mongo = new MongoClient('mongodb://edipo:edipo@localhost:27017');
$db = $mongo->twitterdb;
$collection = $db->createCollection("data");
$dados = $collection->find();
foreach ($dados as $document) {
$data = date("d-m-Y", strtotime(str_replace("/", "-", $document["data"])));
$diaSem = date("N", strtotime(str_replace("/", "-", $document["data"])));
// Inicializa a data inicial e final
$dataIni = $data;
$dataFim = $data;
// semana comeca na segunda, quarta � dia 3. A semana comeca no dia 1
if ($diaSem < 3) {
// Feriado no inicio da semana, considera feriadao do dia do feriado at� dia 1
$qtdeDias = $diaSem + 1;
$d = new Datetime($data);
$d->modify("-" . $qtdeDias . " days");
$dataIni = date("d-m-Y", strtotime($d->format('d-m-Y')));
} else {
if ($diaSem > 3) {
// Feriado no Fim da semana, condidera feriado do dia 7 at� o dia do feriado
$qtdeDias = 7 - $diaSem;
$d = new Datetime($data);
$d->modify("+" . $qtdeDias . " days");
$dataFim = date("d-m-Y", strtotime($d->format("d-m-Y")));
}
}
if (strtotime($dataHora) >= strtotime($dataIni) && strtotime($dataHora) <= strtotime($dataFim)) {
return "sim";
}
}
return "nao";
} catch (Exception $e) {
echo '<h3>N�o foi possivel conectar no banco de dados.</h3>';
return "nao";
}
}
示例13: setUp
public function setUp()
{
parent::setUp();
$this->xml = '<?xml version="1.0" encoding="UTF-8"?>
<record record_id="299">
<description>
<report ok="1">hello</report>
</description>
</record>';
$date = new Datetime();
$this->dmax = $date->format("Y-m-d H:i:s");
$date->modify('-6 month');
$this->dmin = $date->format("Y-m-d H:i:s");
$databoxes = self::$DI['app']['phraseanet.appbox']->get_databoxes();
$this->ret = [];
foreach ($databoxes as $databox) {
$colls = $databox->get_collections();
$rett = [];
foreach ($colls as $coll) {
$rett[$coll->get_coll_id()] = $coll->get_coll_id();
}
$this->ret[$databox->get_sbas_id()] = implode(',', $rett);
}
}
示例14: isValid
public function isValid($value, $required)
{
if ($required && empty($value) || !isset($this->fieldId)) {
return false;
}
$max_range = $this->params->get('maxrange');
$min_range = $this->params->get('minrange');
$value = JFactory::getDate(strtotime($value))->toUnix();
$max_ok = true;
$min_ok = true;
//$ret = true;
if ($max_range) {
if (strtotime($max_range)) {
$max_range = JFactory::getDate(strtotime($max_range))->toUnix();
$max_ok = $value < $max_range;
} elseif (is_numeric($max_range) && intval($max_range) > 0) {
//consider as age format
$datetime = new Datetime();
$datetime->modify('-' . $max_range . ' year');
$max_range = $datetime->format('U');
//revert the age comparation
$max_ok = $value > $max_range;
} else {
$max_range = 0;
}
}
if ($min_range) {
if (strtotime($min_range)) {
$min_range = JFactory::getDate(strtotime($min_range))->toUnix();
$min_ok = $value > $min_range;
} elseif (is_numeric($min_range) && intval($min_range) > 0) {
//consider as age format
$datetime = new Datetime();
$datetime->modify('-' . $min_range . ' year');
$min_range = $datetime->format('U');
//revert the age comparation
$min_ok = $value < $min_range;
} else {
$min_range = 0;
}
}
return $max_ok && $min_ok ? true : false;
//return $ret;
}
示例15: hookbackOfficeTop
public function hookbackOfficeTop($no_cron = true)
{
if (Tools::strtolower(Tools::getValue('controller')) == 'adminorders' && Configuration::get('SHOPPING_FLUX_ORDERS') != '' && in_array('curl', get_loaded_extensions()) || $no_cron == false) {
$ordersXML = $this->_callWebService('GetOrders');
if (count($ordersXML->Response->Orders) == 0) {
return;
}
foreach ($ordersXML->Response->Orders->Order as $order) {
try {
$orderExists = Db::getInstance()->getRow('SELECT m.id_message FROM ' . _DB_PREFIX_ . 'message m
WHERE m.message LIKE "%' . pSQL($order->IdOrder) . '%"');
if (isset($orderExists['id_message'])) {
$this->_validOrders((string) $order->IdOrder, (string) $order->Marketplace);
continue;
}
$mail = (string) $order->BillingAddress->Email;
$email = empty($mail) ? pSQL($order->IdOrder . '@' . $order->Marketplace . '.sf') : pSQL($mail);
$id_customer = $this->_getCustomer($email, (string) $order->BillingAddress->LastName, (string) $order->BillingAddress->FirstName);
//avoid update of old orders by the same merchant with different addresses
$id_address_billing = $this->_getAddress($order->BillingAddress, $id_customer, 'Billing-' . (string) $order->IdOrder);
$id_address_shipping = $this->_getAddress($order->ShippingAddress, $id_customer, 'Shipping-' . (string) $order->IdOrder);
$products_available = $this->_checkProducts($order->Products);
$current_customer = new Customer((int) $id_customer);
$last_cart = new Cart($current_customer->getLastCart());
$add = true;
if ($last_cart->id) {
$date_cart = date_create($last_cart->date_add);
$date = new Datetime();
$date->modify('-5 min');
if ($date < $date_cart) {
$add = false;
}
}
if ($products_available && $id_address_shipping && $id_address_billing && $id_customer && $add) {
$cart = $this->_getCart($id_customer, $id_address_billing, $id_address_shipping, $order->Products, (string) $order->Currency, (string) $order->ShippingMethod);
if ($cart) {
//compatibylity with socolissmo
$this->context->cart = $cart;
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => 'do-not-send@alerts-shopping-flux.com'), 'UPDATE', '`id_customer` = ' . (int) $id_customer);
$customerClear = new Customer();
if (method_exists($customerClear, 'clearCache')) {
$customerClear->clearCache(true);
}
$payment = $this->_validateOrder($cart, $order->Marketplace);
$id_order = $payment->currentOrder;
//we valid there
$this->_validOrders((string) $order->IdOrder, (string) $order->Marketplace, $id_order);
$reference_order = $payment->currentOrderReference;
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'customer', array('email' => pSQL($email)), 'UPDATE', '`id_customer` = ' . (int) $id_customer);
Db::getInstance()->autoExecute(_DB_PREFIX_ . 'message', array('id_order' => $id_order, 'message' => 'Numéro de commande ' . pSQL($order->Marketplace) . ' :' . pSQL($order->IdOrder), 'date_add' => date('Y-m-d H:i:s')), 'INSERT');
$this->_updatePrices($id_order, $order, $reference_order);
}
}
$cartClear = new Cart();
if (method_exists($cartClear, 'clearCache')) {
$cartClear->clearCache(true);
}
$addressClear = new Address();
if (method_exists($addressClear, 'clearCache')) {
$addressClear->clearCache(true);
}
$customerClear = new Customer();
if (method_exists($customerClear, 'clearCache')) {
$customerClear->clearCache(true);
}
} catch (PrestaShopException $pe) {
$this->_validOrders((string) $order->IdOrder, (string) $order->Marketplace, false, $pe->getMessage());
}
}
}
}