public function __invoke()
 {
     $currentDate = new \DateTime();
     $now = new \DateTime();
     $now->setTimeStamp($now->getTimestamp() - 3 * 3600 * 1000);
     $adjustedDate = '';
     $weeks = 3;
     $hours = $now->format('G');
     if (hours == 0) {
         $hours = 24;
     }
     if ($currentDate != $adjustedDate) {
         $dayToCheck = 1;
     } else {
         $dayToCheck = 0;
     }
     $dateRangeToCheck = $this->getDateInThePast($dayToCheck);
     $dateRangeToEnd = $this->getDateInThePast($dayToCheck + 1);
     $dateRangeToStart = $this->getDateInThePast($dayToCheck + 1 + $weeks * 7);
     $dayFormatted = self::$DAYS[$now->format('w')];
     $fields = 'HourOfDay,DayOfWeek,Clicks,Impressions,Cost';
     // Create report query.
     $todayReportQuery = "\n            SELECT {$fields}\n            FROM ACCOUNT_PERFORMANCE_REPORT\n            WHERE Status IN [ENABLED]\n            DURING {$dateRangeToCheck}, {$dateRangeToCheck}";
     $pastReportQuery = "\n            SELECT {$fields}\n            FROM ACCOUNT_PERFORMANCE_REPORT\n            WHERE Status IN [ENABLED]\n            AND DayOfWeek={$dayFormatted}\n            DURING {$dateRangeToStart}, {$dateRangeToEnd}";
     $todayStats = $this->accumulateRows($today, $hours, 1);
     $pastStats = $this->accumulateRows($past, $hours, $weeks);
 }
Exemplo n.º 2
0
 public function testValidSendbankPayment()
 {
     $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
     $templating = $this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface');
     $templating->expects($this->once())->method('renderResponse')->will($this->returnCallback(array($this, 'callbackValidsendbank')));
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $date = new \DateTime();
     $date->setTimeStamp(strtotime('30/11/1981'));
     $date->setTimezone(new \DateTimeZone('Europe/Paris'));
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $order = new OgonePaymentTest_Order();
     $order->setCreatedAt($date);
     $order->setId(2);
     $order->setReference('FR');
     $currency = new Currency();
     $currency->setLabel('EUR');
     $order->setCurrency($currency);
     $order->setCustomer($customer);
     $order->setLocale('es');
     $payment = new OgonePayment($router, $logger, $templating, true);
     $payment->setCode('ogone_1');
     $payment->setOptions(array('url_return_ok' => '', 'url_return_ko' => '', 'url_callback' => '', 'template' => '', 'form_url' => '', 'sha_key' => '', 'sha-out_key' => '', 'pspid' => '', 'home_url' => '', 'catalog_url' => ''));
     $response = $payment->sendbank($order);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
 }
Exemplo n.º 3
0
 /**
  * useless test ....
  *
  * @return void
  */
 public function testPassPayment()
 {
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $router->expects($this->exactly(2))->method('generate')->will($this->returnValue('http://foo.bar/ok-url'));
     $client = $this->getMock('Buzz\\Client\\ClientInterface');
     $browser = new Browser($client);
     $payment = new PassPayment($router, $browser);
     $payment->setCode('free_1');
     $basket = $this->getMock('Sonata\\Component\\Basket\\Basket');
     $product = $this->getMock('Sonata\\Component\\Product\\ProductInterface');
     $transaction = $this->getMock('Sonata\\Component\\Payment\\TransactionInterface');
     $transaction->expects($this->exactly(2))->method('get')->will($this->returnCallback(array($this, 'callback')));
     $transaction->expects($this->once())->method('setTransactionId');
     $date = new \DateTime();
     $date->setTimeStamp(strtotime('30/11/1981'));
     $date->setTimezone(new \DateTimeZone('Europe/Paris'));
     $order = new PassPaymentTest_Order();
     $order->setCreatedAt($date);
     $this->assertEquals('free_1', $payment->getCode(), 'Pass Payment return the correct code');
     $this->assertTrue($payment->isAddableProduct($basket, $product));
     $this->assertTrue($payment->isBasketValid($basket));
     $this->assertTrue($payment->isRequestValid($transaction));
     $this->assertFalse($payment->isCallbackValid($transaction));
     $this->assertFalse($payment->sendConfirmationReceipt($transaction));
     $transaction->expects($this->any())->method('getOrder')->will($this->returnValue($order));
     $this->assertTrue($payment->isCallbackValid($transaction));
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $payment->handleError($transaction));
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $payment->sendConfirmationReceipt($transaction));
     $response = $payment->sendbank($order);
     $this->assertTrue($response->headers->has('Location'));
     $this->assertEquals('http://foo.bar/ok-url', $response->headers->get('Location'));
     $this->assertFalse($response->isCacheable());
     $this->assertEquals($payment->getOrderReference($transaction), '0001231');
     $payment->applyTransactionId($transaction);
 }
 /**
  * @param Message $message
  *
  * @return mixed
  */
 public function newEmail(Message $message)
 {
     $date = new \DateTime();
     $date->setTimeStamp($message->getDate());
     echo 'Subject : ' . $message->getSubject() . "\n";
     echo 'Uid     : ' . $message->getUid() . "\n";
     echo 'Date    : ' . $date->format('Y/m/d H:i:s') . "\n";
 }
Exemplo n.º 5
0
 /**
  * @return \Sonata\Component\Order\OrderInterface
  */
 public function getOrder()
 {
     $date = new \DateTime();
     $date->setTimeStamp(strtotime('30/11/1981'));
     $date->setTimezone(new \DateTimeZone('Europe/Paris'));
     $order = new DebugPaymentTest_Order();
     $order->setCreatedAt($date);
     return $order;
 }
Exemplo n.º 6
0
 /**
  * 
  * @param \DateTime|string $lastUpdate
  */
 public function setLastUpdate($lastUpdate)
 {
     if ($lastUpdate instanceof \DateTime) {
         $this->lastUpdate = $lastUpdate;
     } else {
         if (is_string($lastUpdate)) {
             $this->lastUpdate = new \DateTime($lastUpdate);
         } else {
             if (is_integer($lastUpdate)) {
                 $this->lastUpdate = new \DateTime();
                 $this->lastUpdate->setTimeStamp($lastUpdate);
             }
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Create a random date $before and $after around $base, which defaults to
  * 'now'. $before and $after are taken to be relative date strings.
  *
  * $base can be string, integer or \DateTime, if given.
  *
  * @param string $before a relative date
  * @param string $after a relative date
  * @param mixed $base the base date to randomize around
  * @return \DateTime
  * @throws \InvalidArgumentException
  */
 public static function random($before = '- 1 week', $after = '+ 1 week', $base = null)
 {
     if ($base === null) {
         $baseDateTime = new \DateTime();
     } elseif (is_integer($base)) {
         $baseDateTime = new \DateTime();
         $baseDateTime->setTimeStamp($base);
     } elseif (is_string($base)) {
         $baseDateTime = new \DateTime($base);
     } elseif ($base instanceof \DateTime) {
         $baseDateTime = $base;
     } else {
         throw new \InvalidArgumentException('$base was neither NULL, integer, string, DateTime nor NULL. Duh!', 1251365710);
     }
     $startTimeStamp = strtotime($before, $baseDateTime->getTimeStamp());
     $endTimeStamp = strtotime($after, $baseDateTime->getTimeStamp());
     $result = new \DateTime();
     $result->setTimeStamp(rand($startTimeStamp, $endTimeStamp));
     return $result;
 }
Exemplo n.º 8
0
 public function testSendbank()
 {
     $date = new \DateTime();
     $date->setTimeStamp(strtotime('30/11/1981'));
     $date->setTimezone(new \DateTimeZone('Europe/Paris'));
     $order = new CheckPaymentTest_Order();
     $order->setCreatedAt($date);
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $router->expects($this->exactly(2))->method('generate')->will($this->returnValue('http://foo.bar/ok-url'));
     $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
     $client = $this->getMock('Buzz\\Client\\ClientInterface');
     $client->expects($this->once())->method('send')->will($this->returnCallback(function ($request, $response) {
         $response->setContent('ok');
     }));
     $browser = new Browser($client);
     $payment = new CheckPayment($router, $logger, $browser);
     $response = $payment->sendbank($order);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertEquals(302, $response->getStatusCode());
     $this->assertEquals('http://foo.bar/ok-url', $response->headers->get('Location'));
     $this->assertFalse($response->isCacheable());
 }
Exemplo n.º 9
0
 /**
  * Check for new messages in each program and email the administrator
  *
  * @param AdminCronController $cron
  */
 public static function runCron(AdminCronController $cron)
 {
     $threads = $cron->getEntityManager()->getRepository('\\Jazzee\\Entity\\Thread')->findAll();
     if (time() - (int) $cron->getVar('applicantsMessagesApplicantsLastRun') > self::MIN_INTERVAL_APPLICANTS) {
         $lastRun = new DateTime();
         $lastRun->setTimeStamp((int) $cron->getVar('applicantsMessagesApplicantsLastRun'));
         $cron->setVar('applicantsMessagesApplicantsLastRun', time());
         $applicants = array();
         foreach ($threads as $thread) {
             if ($thread->hasUnreadMessage(\Jazzee\Entity\Message::PROGRAM)) {
                 $createdAt = $thread->getLastUnreadMessage(\Jazzee\Entity\Message::PROGRAM)->getCreatedAt();
                 $diff = $createdAt->diff(new DateTime('now'));
                 //if created since our last run or it is a multiplier fo 7 days old in te hour it was crated
                 //don't send messages to applicants who have logged in since the message was created
                 if (($createdAt > $lastRun or $diff->days > 5 and $diff->days % 7 == 0 and $diff->h == 0) and $thread->getApplicant()->getLastLogin() < $createdAt) {
                     if (!array_key_exists($thread->getApplicant()->getId(), $applicants)) {
                         $applicants[$thread->getApplicant()->getId()] = array('applicant' => $thread->getApplicant(), 'count' => 0);
                     }
                     $applicants[$thread->getApplicant()->getId()]['count']++;
                 }
             }
         }
         foreach ($applicants as $arr) {
             try {
                 $message = $cron->newMailMessage();
                 $message->AddAddress($arr['applicant']->getEmail(), $arr['applicant']->getFullName());
                 $message->Subject = 'New Message from ' . $arr['applicant']->getApplication()->getCycle()->getName() . ' ' . $arr['applicant']->getApplication()->getProgram()->getName();
                 $body = 'You have ' . $arr['count'] . ' unread message(s) from the ' . $arr['applicant']->getApplication()->getCycle()->getName() . ' ' . $arr['applicant']->getApplication()->getProgram()->getName() . ' program.' . "\nYou can review your message(s) by logging into the application at: " . $cron->absoluteApplyPath('apply/' . $arr['applicant']->getApplication()->getProgram()->getShortName() . '/' . $arr['applicant']->getApplication()->getCycle()->getName() . '/applicant/login');
                 $body .= "\nOnce you have logged into the application choose support in the upper right hand corner of the screen.";
                 $message->Body = $body;
                 $message->Send();
             } catch (phpmailerException $e) {
                 $cron->log("Attempting to send message reminder to applicant #{$arr['applicant']->getId()} resulted in a mail exception: " . $e->getMessage());
             }
         }
         if ($count = count($applicants)) {
             $cron->log("Sent {$count} reminder messages to applicants.");
         }
     }
     if (time() - (int) $cron->getVar('applicantsMessagesProgramsLastRun') > self::MIN_INTERVAL_PROGRAMS) {
         $lastRun = new DateTime();
         $lastRun->setTimeStamp((int) $cron->getVar('applicantsMessagesProgramsLastRun'));
         $cron->setVar('applicantsMessagesProgramsLastRun', time());
         $applications = array();
         foreach ($threads as $thread) {
             if ($thread->hasUnreadMessage(\Jazzee\Entity\Message::APPLICANT)) {
                 if (!array_key_exists($thread->getApplicant()->getApplication()->getId(), $applications)) {
                     $applications[$thread->getApplicant()->getApplication()->getId()] = array('application' => $thread->getApplicant()->getApplication(), 'count' => 0);
                 }
                 $applications[$thread->getApplicant()->getApplication()->getId()]['count']++;
             }
         }
         foreach ($applications as $arr) {
             try {
                 $message = $cron->newMailMessage();
                 $message->AddAddress($arr['application']->getContactEmail(), $arr['application']->getContactName());
                 $message->Subject = 'New Applicant Messages for ' . $arr['application']->getCycle()->getName() . ' ' . $arr['application']->getProgram()->getName();
                 $body = 'There are ' . $arr['count'] . ' unread messages for the ' . $arr['application']->getCycle()->getName() . ' ' . $arr['application']->getProgram()->getName() . ' program.' . "\nYou can review them at: " . $cron->absolutePath('applicants/messages');
                 $message->Body = $body;
                 $message->Send();
             } catch (phpmailerException $e) {
                 $cron->log("Attempting to send message reminder to {$arr['application']->getCycle()->getName()} {$arr['application']->getProgram()->getName()} resulted in a mail exception: " . $e->getMessage());
             }
         }
         if ($count = count($applications)) {
             $cron->log("Sent {$count} reminder messages to programs.");
         }
     }
 }
 protected function setUp()
 {
     mkdir('results');
     $date = new \DateTime();
     $date->setTimeStamp(time());
     $date->format('Y-m-d');
     $serializablePage1 = new SerializableSerpPage('google', 'baz', 'http://www.google.com', 1, $date, array(array('url' => 'http://www.google.com', 'snippet' => 'baz', 'title' => 'foo'), array('url' => 'http://www.google.com', 'snippet' => 'baz', 'title' => 'foo')));
     $serializablePage2 = new SerializableSerpPage('ask', 'foobaz', 'http://www.ask.com', 1, $date, array(array('url' => 'http://www.ask.com', 'snippet' => 'foobaz', 'title' => 'baz'), array('url' => 'http://www.ask.com', 'snippet' => 'bazfoo', 'title' => 'foo')));
     $serializablePage3 = new SerializableSerpPage('bing', 'baz', 'http://www.bing.com', 5, $date, array(array('url' => 'http://www.bing.com', 'snippet' => 'bazfoo', 'title' => 'foobaz'), array('url' => 'http://www.bing.com', 'snippet' => 'foobazbaz', 'title' => 'bazfoo')));
     $serializablePage4 = new SerializableSerpPage('yahoo', 'baz', 'http://www.yahoo.com', 3, $date, array(array('url' => 'http://www.yahoo.com', 'snippet' => 'boom', 'title' => 'baz'), array('url' => 'http://www.yahoo.com', 'snippet' => 'bazfo', 'title' => 'foobad')));
     $serializablePages = array($serializablePage1, $serializablePage2, $serializablePage3, $serializablePage4);
     $this->serializablePages = $serializablePages;
 }
 protected function setUp()
 {
     $date = new \DateTime();
     $date->setTimeStamp(time());
     $this->date = $date;
 }
Exemplo n.º 12
0
 /**
  * @return integer get local time zone offset from GMT
  */
 public function getGMTDiff($ts = false)
 {
     $dt = new DateTime();
     if ($ts) {
         $dt->setTimeStamp($ts);
     } else {
         $dt->setDate(1970, 1, 2);
     }
     return (int) $dt->format('Z');
 }
Exemplo n.º 13
0
<!-- Countdown timer - The Timer calculates the time until the release date of the movie -->

<?php 
date_default_timezone_set('Pacific/Auckland');
// Time until release
$rDay = 1;
$rMonth = 8;
$rYear = 2014;
$rHour = 16;
$rMinute = 0;
$rSecond = 0;
$releaseDate = new DateTime();
$releaseDate->setTimeStamp(mktime($rHour, $rMinute, $rSecond, $rMonth, $rDay, $rYear));
$currentTime = new DateTime();
$currentTime->setTimeStamp(time());
$timeDifference = $releaseDate->diff($currentTime);
$timeUntilRelease = $timeDifference->format('%d/%m %h:%i:%s') . "<br/>";
?>

<header>
	<div class="header__background background--blue">
		<div class="container header__content">

			<div class="col-md-3">
				<a href="index.php"><img src="assets/media/Title.png" alt="LIFE Title" class="header__title"></a>
			</div>

			<div class="col-md-4">

				<?php 
require_once 'includes/nav.php';
Exemplo n.º 14
0
 public function testValidSendbankPayment()
 {
     $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
     $templating = $this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface');
     $templating->expects($this->once())->method('renderResponse')->will($this->returnCallback(array($this, 'callbackValidsendbank')));
     $generator = $this->getMock('Sonata\\Component\\Payment\\Scellius\\ScelliusTransactionGeneratorInterface');
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $date = new \DateTime();
     $date->setTimeStamp(strtotime('30/11/1981'));
     $date->setTimezone(new \DateTimeZone('Europe/Paris'));
     $customer = $this->getMock('Sonata\\Component\\Customer\\CustomerInterface');
     $customer->expects($this->once())->method('getId')->will($this->returnValue(42));
     $customer->expects($this->once())->method('getEmail')->will($this->returnValue('*****@*****.**'));
     $order = new ScelliusPaymentTest_Order();
     $order->setCreatedAt($date);
     $order->setId(2);
     $order->setReference('FR');
     $currency = new Currency();
     $currency->setLabel('EUR');
     $order->setCurrency($currency);
     $order->setCustomer($customer);
     $order->setLocale('es');
     $payment = new ScelliusPayment($router, $logger, $templating, $generator, true);
     $payment->setCode('free_1');
     $payment->setOptions(array('base_folder' => __DIR__, 'request_command' => 'cat request_ok.txt && echo '));
     $response = $payment->sendbank($order);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
 }
 public function addRemoteWorkspaceExpDate(Order $order)
 {
     $sws = $order->getSharedWorkspace();
     $user = $sws->getOwner();
     $monthDuration = $order->getPriceSolution()->getMonthDuration();
     $product = $order->getProduct();
     $details = $product->getDetails();
     $workspace = $this->getWorkspaceData($sws);
     $expDate = \DateTime::createFromFormat(\DateTime::ATOM, $workspace['endDate']);
     $now = new \DateTime();
     if ($now->getTimeStamp() > $expDate->getTimeStamp()) {
         $expDate = $now;
     }
     $interval = new \DateInterval("P{$monthDuration}M");
     $expDate->add($interval);
     $workspaceType = new WorkspaceType();
     $workspaceType->enableApi();
     $form = $this->formFactory->create($workspaceType);
     $payload = $this->apiManager->formEncode($workspace, $form, $workspaceType);
     $payload['workspace_form[endDate]'] = $expDate->format('d-m-Y');
     $url = 'api/workspaces/' . $sws->getRemoteId() . '/users/' . $user->getUsername() . '.json';
     $serverOutput = $this->apiManager->url($this->targetFriend, $url, $payload, 'PUT');
     $workspace = json_decode($serverOutput, true);
     //add date here
     if ($workspace === null || isset($workspace['errors'])) {
         $this->handleError($sws, $serverOutput, $url);
     }
     if (array_key_exists('id', $workspace)) {
         $updatedDate = new \DateTime();
         $updatedDate->setTimeStamp($expDate->getTimeStamp());
         $sws->setExpDate($updatedDate);
         $this->om->persist($sws);
         $this->om->flush();
         return $sws;
     }
     $this->handleError($sws, $serverOutput, $url);
 }
Exemplo n.º 16
0
 public static function run()
 {
     try {
         //Create timestamps of start and end of week
         $fromTimeStamp = strtotime('monday last week ' . GlobalConfig::PHP_TIME_ZONE);
         $toTimeStamp = strtotime('monday this week ' . GlobalConfig::PHP_TIME_ZONE);
         //Get all gransactions for this week
         $transactions = MoneyTransactionDB::getTransactionsBetween($fromTimeStamp, $toTimeStamp);
         //Get total amount of money in the system right now
         $totalBalanceAfter = MoneyTransactionDB::getTotalBalance();
         //Get total amount of money added and removed during this week.
         $incrMoneyFromRealMoney = 0;
         $incrMoneyFromPrize = 0;
         $decrMoneyWithoutDiscount = 0;
         $decrMoneyWithDiscount = 0;
         foreach ($transactions as $transaction) {
             if ($transaction->isFromPrize()) {
                 $incrMoneyFromPrize += $transaction->getIncrMoney();
             } else {
                 $incrMoneyFromRealMoney += $transaction->getIncrMoney();
             }
             $decrMoneyWithoutDiscount += $transaction->getDecrMoney();
             $decrMoneyWithDiscount += $transaction->getDecrMoneyWithDiscount();
         }
         //Get total amount of money in the system before this week
         $totalBalanceBefore = $totalBalanceAfter - $incrMoneyFromRealMoney - $incrMoneyFromPrize + $decrMoneyWithDiscount;
         //Create from and to time strings
         $fromTime = new DateTime();
         $fromTime->setTimeZone(new DateTimeZone(GlobalConfig::PHP_TIME_ZONE));
         $fromTime->setTimeStamp($fromTimeStamp);
         $fromTime->setTimeZone(new DateTimeZone(GlobalConfig::PHP_TIME_ZONE));
         $fromDateString = $fromTime->format('d/m/y');
         $fromTimeString = $fromTime->format('d/m/y H:i:s');
         $toTime = new DateTime();
         $toTime->setTimeZone(new DateTimeZone(GlobalConfig::PHP_TIME_ZONE));
         $toTime->setTimeStamp($toTimeStamp);
         //Subtract 1 second to display the correct date.
         $toTime = date_sub($toTime, new DateInterval('PT1S'));
         $toDateString = $toTime->format('d/m/y');
         $toTimeString = $toTime->format('d/m/y H:i:s');
         //Create array with date to show in the email
         $emailExtras['common']['fromDate'] = $fromDateString;
         $emailExtras['common']['toDate'] = $toDateString;
         $emailExtras['common']['fromTime'] = $fromTimeString;
         $emailExtras['common']['toTime'] = $toTimeString;
         $emailExtras['common']['totalBalanceBefore'] = $totalBalanceBefore / 100;
         $emailExtras['common']['incrMoneyFromRealMoney'] = $incrMoneyFromRealMoney / 100;
         $emailExtras['common']['incrMoneyFromPrize'] = $incrMoneyFromPrize / 100;
         $emailExtras['common']['decrMoneyWithoutDiscount'] = $decrMoneyWithoutDiscount / 100;
         $emailExtras['common']['decrMoneyWithDiscount'] = $decrMoneyWithDiscount / 100;
         $emailExtras['common']['totalBalanceAfter'] = $totalBalanceAfter / 100;
         //Create fake users to send email to addresses
         $users = array();
         foreach (BalandeSummaryEmailSenderConfig::EMAIL_ADDRESSES as $emailAddress) {
             $user = new User();
             $user->email = $emailAddress;
             array_push($users, $user);
         }
         //Send email
         Email::sendEmails('MoneyOverview.html', 'Saldo lidkaarten ' . $fromDateString . ' - ' . $toDateString, '*****@*****.**', $users, $emailExtras);
     } catch (Exception $ex) {
         var_dump($ex);
     }
 }
 public function isSpecialMass($mass_dt)
 {
     $dow = date_format($mass_dt, 'w');
     if (0 == $dow) {
         return "Sunday";
     } else {
         $yr = date_format($mass_dt, 'Y');
         $dtEaster = new DateTime();
         $dtEaster->setTimeStamp(easter_date($yr));
         $dtSacredHeart = clone $dtEaster;
         $dtSacredHeart->add(new DateInterval("P68D"));
         $feast_days = array("Jan 01" => "Mary, Mother of God", "Jan 06" => "Epiphany", "Mar 19" => "St Joseph", "Mar 25" => "Annunciation", date_format($dtSacredHeart, 'M d') => "Sacred Heart of Jesus", "Jun 24" => "Nativity of John the Baptist", "Jun 29" => "Sts Peter & Paul", "Aug 15" => "Assumption", "Nov 01" => "All Saints", "Dec 08" => "Immaculate Conception", "Dec 25" => "Christmas");
         $dm = date_format($mass_dt, 'M d');
         if (array_key_exists($dm, $feast_days)) {
             return $feast_days[$dm];
         }
     }
     return false;
 }
Exemplo n.º 18
0
/**
 * Calculate the difference between two timestamps and take into account only working hours.
 *
 * @param int $timestamp1 ELGG timestamp 1
 * @param int $timestamp2 ELGG timestamp 2
 * 
 * @return int difference between timestamps (hours)
 */
function questions_time_diff($beginTS, $endTS)
{
    $settingBeginHour = elgg_get_plugin_setting("workflow_workingtimes_begin_hour", "questions");
    $settingBeginMinute = elgg_get_plugin_setting("workflow_workingtimes_begin_minute", "questions");
    $settingEndHour = elgg_get_plugin_setting("workflow_workingtimes_end_hour", "questions");
    $settingEndMinute = elgg_get_plugin_setting("workflow_workingtimes_end_minute", "questions");
    $workingDays = unserialize(elgg_get_plugin_setting("workflow_workingtimes_days", "questions"));
    if ($beginTS == 0 | $endTS == 0 | $beginTS >= $endTS) {
        return 0;
    }
    if (isset($settingBeginHour) && isset($settingBeginMinute)) {
        $workBeginTime = new DateTime($settingBeginHour . ":" . $settingBeginMinute);
    } else {
        $workBeginTime = new DateTime("09:00");
    }
    if (isset($settingEndHour) && isset($settingEndMinute)) {
        $workEndTime = new DateTime($settingEndHour . ":" . $settingEndMinute);
    } else {
        $workEndTime = new DateTime("17:00");
    }
    if (!is_array($workingDays)) {
        $workingDays = array(1, 2, 3, 4, 5);
    }
    $begin = new DateTime();
    $begin->setTimeStamp($beginTS);
    $end = new DateTime();
    $end->setTimeStamp($endTS);
    // on the same day
    if ($begin->format("Ymd") == $end->format("Ymd")) {
        // return zero if this day is not a working day
        if (!in_array($begin->format("N"), $workingDays)) {
            return 0;
        }
        // format as times
        $beginTime = new DateTime($begin->format("H:i:s"));
        $endTime = new DateTime($end->format("H:i:s"));
        if ($beginTime < $workBeginTime) {
            $lowerBound = $workBeginTime;
        } else {
            if ($beginTime > $workEndTime) {
                $lowerBound = $workEndTime;
            } else {
                $lowerBound = $beginTime;
            }
        }
        if ($endTime > $workEndTime) {
            $upperBound = $workEndTime;
        } else {
            if ($endTime < $workBeginTime) {
                $upperBound = $workBeginTime;
            } else {
                $upperBound = $endTime;
            }
        }
        $diff = $lowerBound->diff($upperBound);
        return $diff->h * 3600 + $diff->i * 60 + $diff->s;
    } else {
        // not on the same day
        $totalTime = 0;
        // calculate the working time on the first day
        if (in_array($begin->format('N'), $workingDays)) {
            $beginTime = new DateTime($begin->format("H:i:s"));
            if ($beginTime < $workBeginTime) {
                $lowerBound = $workBeginTime;
            } elseif ($beginTime > $workBeginTime && $beginTime < $workEndTime) {
                $lowerBound = $beginTime;
            } else {
                $lowerBound = $workEndTime;
            }
            $upperBound = $workEndTime;
            $diff = $lowerBound->diff($upperBound);
            $totalTime = $totalTime + $diff->h * 3600 + $diff->i * 60 + $diff->s;
        }
        // calculate the working time on the last day
        if (in_array($end->format('N'), $workingDays)) {
            $endTime = new DateTime($end->format("H:i:s"));
            $lowerBound = $workBeginTime;
            if ($endTime < $workBeginTime) {
                $upperBound = $workBeginTime;
            } elseif ($endTime > $workBeginTime && $endTime < $workEndTime) {
                $upperBound = $endTime;
            } else {
                $upperBound = $workEndTime;
            }
            $diff = $lowerBound->diff($upperBound);
            $totalTime = $totalTime + $diff->h * 3600 + $diff->i * 60 + $diff->s;
        }
        // set to beginning of the next day
        $begin->modify('midnight +1 day');
        // set to last midnight
        $end->modify('midnight');
        $diff = $workBeginTime->diff($workEndTime);
        $secondsPerDay = $diff->h * 3600 + $diff->i * 60 + $diff->s;
        // calculate the workingtime on the days inbetween
        $period = new DatePeriod($begin, new DateInterval('P1D'), $end);
        foreach ($period as $day) {
            if (in_array($day->format('N'), $workingDays)) {
                $totalTime = $totalTime + $secondsPerDay;
            }
        }
        return $totalTime;
    }
}
Exemplo n.º 19
0
 public function getDateWithFormat($label, $format = "d/m/Y")
 {
     $date = $this->get($label) / 1000;
     //int
     $dateObject = new \DateTime();
     $dateObject->setTimeStamp($date);
     $string = $dateObject->format($format);
     $this->log_debug("{$label}: {$string}");
     return $string;
 }
Exemplo n.º 20
0
 /**
  * Scrape a single keyword. This will yield as many SerializableSerpPage
  * objects as there are to scrape. Those objects will be stored in the
  * fetched array queue, ready to be serialized.
  * It is also possible to empty the keywords array by setting $toRemove to
  * true, set a specific $timezone and turn throttling off by setting $throttling
  * to false.
  * @param  string  $keyword
  * @param  int     $pagesToScrape
  * @param  bool    $toRemove
  * @param  string  $timezone
  * @param  bool    $throttling
  * @return bool
  */
 public function scrape($keyword, $pagesToScrape = self::DEFAULT_PAGES_TO_SCRAPE, $toRemove = false, $timezone = self::DEFAULT_TIMEZONE, $throttling = true)
 {
     // allow scrapeAll() to reuse scrape()
     if (is_string($keyword)) {
         $keyword = array($keyword);
     }
     // perform validations
     if (!SerpScraperHelper::validScrapeArgs($keyword, $pagesToScrape, $toRemove, $timezone, $throttling, $this->keywords)) {
         return false;
     }
     // map keywords to array of urls ready to scrape
     $urlsToScrape = $this->mapKeywordsToUrls($pagesToScrape, $keyword);
     // check for legal operation only if throttling
     if ($throttling && !$this->allowedScrapeOperation($pagesToScrape, $urlsToScrape)) {
         return false;
     }
     // avoid DateTime() annoying notices
     date_default_timezone_set($timezone);
     // loop over the keywords to scrape
     for ($i = 0; $i < count($keyword); $i++) {
         // get the current keyword
         $key = $keyword[$i];
         // scrape $pagesToScrape pages for each keyword
         for ($j = 0; $j < $pagesToScrape; $j++) {
             $pageUrl = $urlsToScrape[$key][$j];
             $fetched = $this->fetchPage($key, $pageUrl);
             $entries = $this->makeEntries($fetched);
             $engine = strtolower(self::runTimeClassName());
             $pageNumber = $j + 1;
             $age = new \DateTime();
             $age->setTimeStamp(time());
             // construct a SerializableSerpPage and store it
             $serializablePage = new SerializableSerpPage($engine, $key, $pageUrl, $pageNumber, $age, $entries);
             array_push($this->fetched, $serializablePage);
             // delay inbetween requests
             usleep(self::DEFAULT_REQUEST_DELAY);
         }
         // remove the key from the queue if specified
         if ($toRemove) {
             $this->removeKeyword($key);
         }
     }
     return true;
 }
Exemplo n.º 21
0
 /**
  * Create a timestamp string from the given unix timestamp
  *
  * @param int $timestamp Unix timestamp
  *
  * @return string Formatted string
  */
 public static function formatTimestamp($timestamp)
 {
     $date = new DateTime('', new DateTimeZone('UTC'));
     $date->setTimeStamp($timestamp);
     return $date->format('Y-m-d') . 'T' . $date->format('H:i:s') . 'Z';
 }
<?php

$currentDate = new DateTime();
$currentDate->setTimeStamp(time());
echo $currentDate->format('U = Y-m-d H:i:s') . "\n";
$movie_sessions = array('Monday' => array('6:30pm'), 'Tuesday' => array('4:00pm', '5:40am'), 'Wednesday' => array('6:45pm', '7:40am'), 'Thursday' => array('8:30pm', '9:40am'), 'Friday' => array('10:30pm'), 'Saturday' => array('12:30pm', '1:40am'), 'Sunday' => array('2:30pm', '3:40am'));
$nextFiveDays = array();
$nextFiveDays = array();
$currentDayName = $currentDate->format('l');
// Set both pointers to the start of the array;
reset($nextFiveDays);
reset($movie_sessions);
// Movie moive times point to current day
while (key($movie_sessions) != $currentDayName) {
    next($movie_sessions);
}
for ($i = 0; $i < 5; $i++) {
    if ($movieItem['key'] == "Sunday") {
        reset($movie_sessions);
    }
    $movieItem = each($movie_sessions);
    $nextFiveDays[$movieItem['key']] = $movieItem['value'];
}
?>

<main>
	<section class="home_main content__container background--beige">
		<div class="container">
			
			<!-- Page Title -->
			<div class="row">
Exemplo n.º 23
0
 public function getFree($search = '', $from = 0, $to = 2147483647, $getQuery = false)
 {
     $dql = "\n            SELECT i FROM FormaLibre\\InvoiceBundle\\Entity\\Invoice i\n            JOIN i.chart chart\n            JOIN chart.owner owner\n            WHERE (\n                i.paymentSystemName = 'free'\n                OR i.paymentSystemName = 'none'\n            )\n            AND chart.validationDate BETWEEN :from and :to\n        ";
     if ($search) {
         $search = strtoupper($search);
         $dql .= '
             AND (
                 UPPER(owner.mail) LIKE :search OR
                 UPPER(owner.firstName) LIKE :search OR
                 UPPER(owner.lastName) like :search OR
                 UPPER(i.invoiceNumber) like :search
             )
         ';
     }
     $fromTime = new \DateTime();
     $fromTime->setTimeStamp($from);
     $toTime = new \DateTime();
     $toTime->setTimeStamp($to);
     $query = $this->em->createQuery($dql);
     $query->setParameter('from', $fromTime);
     $query->setParameter('to', $toTime);
     if ($search) {
         $query->setParameter('search', "%{$search}%");
     }
     return $getQuery ? $query : $query->getResult();
 }
Exemplo n.º 24
0
 /**
  * 
  * @param mixed $value
  * @param array $limits
  * @param string $operator
  * @return boolean
  */
 protected function doCompare($value, $limits, $operator)
 {
     $doCompare = true;
     if (isset($limits[0]) && !is_null($limits[0])) {
         switch ($operator) {
             case 'BETWEEN':
                 if (isset($limits[1]) && !is_null($limits[1]) && ($limits[0] > $value || $value > $limits[1])) {
                     $doCompare = false;
                 }
                 break;
             case 'AFTER':
                 if ($limits[0] > $value) {
                     $doCompare = false;
                 }
                 break;
             case 'BEFORE':
                 if ($limits[0] < $value) {
                     $doCompare = false;
                 }
                 break;
             case 'AGE':
                 if (abs($limits[0]) > abs($value)) {
                     $age = $value;
                     $date = $limits[0];
                 } else {
                     $age = $limits[0];
                     $date = $value;
                 }
                 $dateCheck = new DateTime();
                 $dateCheck->setTimestamp($date);
                 $now = new DateTime();
                 $now->setTimestamp($limits[1]);
                 $interval = $dateCheck->diff($now);
                 if ($age != $interval->y) {
                     $doCompare = false;
                 }
                 break;
             case 'TODAY':
                 $today = date('Y-m-d');
                 $new = new DateTime($today);
                 $dateCheck = new DateTime();
                 $dateCheck->setTimeStamp($value);
                 if ($new != $dateCheck) {
                     $doCompare = false;
                 }
                 break;
         }
     }
     return $doCompare;
 }