/**
 * @param string $key
 * @param string $aud
 * @param string $iss
 * @param array $addl_payload_params
 * @return string
 */
function createNewToken($key, $aud, $iss, $addl_payload_params = array())
{
    $now = new \DateTime('now');
    $expires = new \Datetime('now');
    $expires->add(new \DateInterval("P42D"));
    // sets token expiration date to six weeks from now
    $payload = array();
    $payload['iat'] = $now->format('U');
    $payload['exp'] = $expires->format('U');
    $payload['iss'] = $iss;
    $payload['aud'] = $aud;
    $payload = array_merge($payload, $addl_payload_params);
    return JWT::encode($payload, $key);
}
 protected function getScheduleDateTime()
 {
     $now = new Datetime(SS_Datetime::now()->Format(DateTime::ATOM));
     // Presume where checking at a point before the StartDate
     $nextDateTime = $this->getStartDateTime();
     if ($now >= $this->getStartDateTime()) {
         //Inside the ScheduleRange so set nextDateTime to now + interval
         $nextDateTime = $now->add(new DateInterval('PT' . $this->Interval . 'S'));
     }
     if ($nextDateTime > $this->getEndDateTime()) {
         //Now + interval falls outside the Schedule range
         if ($nextDateTime > $this->getLastScheduleTime()) {
             $nextDateTime = null;
         } else {
             $this->goToNextDay();
             $nextDateTime = $this->getScheduleDateTime();
         }
     }
     return $nextDateTime;
 }
Exemple #3
0
 /**
  * Creates a new JobModel model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new JobModel();
     $now = new \DateTime();
     $now = $now->getTimestamp();
     //         var_dump($now);
     //         var_dump(Yii::$app->user->identity);
     //         die;
     $model->modify_time = $model->create_time = $now;
     $model->modify_user = $model->create_user = $model->owner = Yii::$app->user->identity->username;
     $model->cron_str = "1 * * * *";
     #$date = date_create(); # php, hehe
     $date = date('Y-m-d');
     $date = new \Datetime($date);
     // $date = $date->getTimestamp();
     $model->start_date = $date->getTimestamp();
     $model->end_date = $date->add(new \DateInterval('P99Y'));
     $model->host_strategy = 0;
     $model->restore_strategy = 0;
     $model->retry_strategy = 0;
     $model->error_strategy = 0;
     $model->exist_strategy = 0;
     $model->mails = Yii::$app->user->identity->mail;
     $model->next_run_time = 0;
     $model->status = 0;
     $model->running_timeout_s = 99999;
     $model->oupput_match_reg = 'error';
     $model->team = 'backend';
     $model->phones = '10086';
     $model->desc = ' ';
     // $model->phone = Yii::$app->user->identity->phone;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemple #4
0
 /**
  * Method to emulate MySQL DATE_ADD() function.
  *
  * This function adds the time value of $interval expression to $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 add.
  * @return string date formated as '0000-00-00 00:00:00'.
  */
 public function date_add($date, $interval)
 {
     $interval = $this->deriveInterval($interval);
     switch (strtolower($date)) {
         case "curdate()":
             $objDate = new Datetime($this->curdate());
             $objDate->add(new DateInterval($interval));
             $returnval = $objDate->format("Y-m-d");
             break;
         case "now()":
             $objDate = new Datetime($this->now());
             $objDate->add(new DateInterval($interval));
             $returnval = $objDate->format("Y-m-d H:i:s");
             break;
         default:
             $objDate = new Datetime($date);
             $objDate->add(new DateInterval($interval));
             $returnval = $objDate->format("Y-m-d H:i:s");
     }
     return $returnval;
 }
Exemple #5
0
 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);
 }
 /**
  * このオブジェクトがタイムゾーンを利用する場合は,
  * 引数の時間オブジェクトを補正した結果を返します.
  * タイムゾーンを利用しない場合は引数をそのまま返します.
  * このメソッドは各種 format メソッドから呼ばれます.
  * 
  * @param  Datetime $d 補正対象の時間オブジェクト
  * @return Datetime    補正結果
  */
 private function adjustFromFormat(Datetime $d)
 {
     return $this->usingTz ? $d->add("minute", $this->internalOffset - $this->externalOffset) : $d;
 }
 public function searchFlight(Subscription $subs)
 {
     //echo "search";
     echo "start search for new subscription " . $subs->ID . "\n";
     date_default_timezone_set('Asia/Shanghai');
     $today = new DateTime('now');
     $today->setTime(0, 0, 0);
     $date = new DateTime($subs->StartDate);
     $endDate = new DateTime($subs->EndDate);
     //echo $endDate->format('Y-m-d H:i:s') . " ". $today->format('Y-m-d H:i:s');
     if ($endDate < $today) {
         echo "end date is yesterday\n";
         return;
     }
     while ($date <= $endDate) {
         echo "search for " . $date->format(DateTime::W3C) . "\n";
         if ($date < $today) {
             echo "yesterday\n";
             $date = new Datetime();
             //$date->add(new DateInterval('P1D'));
             continue;
         }
         sleep(3);
         $this->DepartCity = $subs->DepartCity;
         $this->ArriveCity = $subs->ArriveCity;
         $this->DepartDate = $date->format('Y-m-d');
         if ($this->EarliestDepartTime != null) {
             $this->EarliestDepartTime = $this->DepartDate . "T" . $subs->EarliestDepartTime;
         }
         if ($this->LatestDepartTime != null) {
             $this->LatestDepartTime = $this->DepartDate . "T" . $subs->LatestDepartTime;
         }
         $this->AirlineDibitCode = $subs->AirlineDibitCode;
         $this->IsLowestPrice = "true";
         $this->OrderBy = "Price";
         $this->main();
         $returnXML = $this->ResponseXML;
         print_r($returnXML);
         /*
         				查看返回代码是否为成功
         */
         $resultCode = $returnXML->Header->attributes()->ResultCode;
         echo "result code: " . $resultCode . "\n";
         if ($resultCode != 'Success') {
             $date->add(new DateInterval('P1D'));
             continue;
         }
         /*
         				查看返回航班数量是否为0
         */
         $recordCount = $returnXML->FlightSearchResponse->FlightRoutes->DomesticFlightRoute->RecordCount;
         if ($recordCount == 0) {
             $date->add(new DateInterval('P1D'));
             continue;
         }
         $this->obj_xml[] = $returnXML;
         if (!$this->checkReturnXML($returnXML)) {
             $date->add(new DateInterval('P1D'));
             continue;
         }
         //print_r($returnXML);
         $flight = $returnXML->FlightSearchResponse->FlightRoutes->DomesticFlightRoute->FlightsList->DomesticFlightData;
         if ((int) $this->price > (int) $flight->Price || $this->price == NULL) {
             //echo "\n";
             //print_r($flight->Price);
             //echo "\n";
             $this->price = $flight->Price;
             echo "price updated to " . $this->price . "\n";
         }
         $date->add(new DateInterval('P1D'));
     }
     $this->deleteNoneLowestPriceFlights();
     return $this->price;
 }
Exemple #8
0
 public function GetTaskCount()
 {
     if ($this->IsUserLogger()) {
         $date = new Datetime();
         $from = $date->format('Y-m-d') . ' 00:00:00';
         $date->add(new DateInterval("P1D"));
         $to = $date->format('Y-m-d') . ' 00:00:00';
         $sql = "SELECT COUNT(t.task_id) FROM `task` t, `task_to_user` ttu " . "WHERE ttu.user_id = '" . $this->user["user_id"] . "' AND t.task_id = ttu.task_id AND " . " t.start <= '" . $to . "' AND t.end > '" . $from . "'" . "ORDER BY t.start;";
         $result = $this->db->query($sql);
         return $result->row["COUNT(t.task_id)"];
     }
 }
Exemple #9
0
 public function testCasoEmQuePrazoNaoEstaVencido()
 {
     $dt = new \Datetime();
     $prazo = $dt->add(\DateInterval::createFromDateString("3 months + 15 days"));
     $this->assertFalse($this->dt->isValid($prazo->format("Y-m-d")));
 }
 /**
  * Mail mit heutigen Terminen und denen der nächsten 7 Tage an mich senden
  *
  * Einrichten:
  * Da cron @ reboot wahrscheinlich abläuft, wenn apache noch nicht gestartet
  * ist, muss die URL per rc.local gestartet werden, welches am Ende aller
  * andern Startscripts läuft. In /etc/rc.local einfügen:
  *
  * wget http://paperhill.localhost/app.php/cron/reminders > /dev/null 2>&1
  *
  * @Route("/cron/reminders")
  */
 public function cronRemindersAction()
 {
     $em = $this->getDoctrine()->getManager();
     $repo = $em->getRepository('AppBundle:Document');
     $today = new \Datetime();
     $remindersToday = $repo->fetchRemindersByDate($today);
     $begin = new \Datetime();
     $begin->add(new \DateInterval('P1D'));
     $end = new \Datetime();
     $end->add(new \DateInterval('P7D'));
     $remindersNext7Days = $repo->fetchRemindersByPeriod($begin, $end);
     $overdueReminders = $repo->fetchOverdueOpenReminders();
     $message = \Swift_Message::newInstance()->setSubject('Paperhill Terminübersicht ' . $today->format('d.m.Y'))->setFrom('*****@*****.**')->setTo('*****@*****.**')->setBody($this->renderView('email/reminders.html.twig', array('today' => $today, 'remindersToday' => $remindersToday, 'remindersNext7Days' => $remindersNext7Days, 'overdueReminders' => $overdueReminders)), 'text/html');
     $this->get('mailer')->send($message);
     return $this->render('email/reminders.html.twig', ['today' => $today, 'remindersToday' => $remindersToday, 'remindersNext7Days' => $remindersNext7Days, 'overdueReminders' => $overdueReminders]);
 }
$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) {
            if (rand(0, 100) > $mp) {
                continue;
            }
            foreach ($paths as $p => $pp) {
                if (rand(0, 100) > $pp) {
                    continue;
                }
                foreach ($responseCodes as $r => $rp) {
                    if (rand(0, 100) > $rp) {
                        continue;
                    }
                    $metrics[] = ['_id' => ['date' => new MongoDate($date->getTimestamp()), 'method' => $m, 'path' => $p, 'userId' => $user['_id'], 'circleId' => null, 'isTrial' => false, 'responseCode' => $r], 'count' => rand(5, 20)];
                }
            }
        }
    }
    $date->add(new DateInterval('P1D'));
}
echo "Inserting " . count($metrics) . " metrics\n";
if (count($metrics) > 0) {
    $db->metrics->batchInsert($metrics);
}
echo sprintf($outputFormat, $time, $timeStamp, $date);
$time = 'now';
$dateObj = new DateTime();
$dateObj->add(DateInterval::createFormDateString($time));
$timeStamp = $dateObj->getTimestamp();
$date = $dateObj->format('Y-m-d H:i:s');
echo sprintf($outputFormat, $time, $timeStamp, $date);
$time = '+1 day';
$dateObj = new DateTime();
$dateObj->add(DateInterval::createFormDateString($time));
$timeStamp = $dateObj->getTimestamp();
$date = $dateObj->format('Y-m-d H:i:s');
echo sprintf($outputFormat, $time, $timeStamp, $date);
$time = '+1 year 2 month 3weeks';
$dateObj = new DateTime();
$dateObj->add(DateInterval::createFormDateString($time));
$timeStamp = $dateObj->getTimestamp();
$date = $dateObj->format('Y-m-d H:i:s');
echo sprintf($outputFormat, $time, $timeStamp, $date);
// 日付として無効な文字列の場合、現在日時になる
$time = 'Time is Money';
$dateObj = new Datetime();
$dateObj->add(DateInterval::CreateFormDateString($time));
$timeStamp = $dateObj->getTimestamp();
$date = $dateObj->format('Y-m-d H:i:s');
echo sprintf($outputFormat, $time, $timeStamp, $date);
echo '</table>';
?>
	</div>
</body>
</html>
function from(Datetime $dt)
{
    return $dt->add(DateInterval::createFromDateString("1000000000 seconds"));
}
Exemple #14
0
 public function getJwt()
 {
     if (!$this->user) {
         throw new \Exception('Can not build a JWT, we have no user');
     }
     $now = new \DateTime();
     $expires = new \Datetime();
     $expires->add(new \DateInterval("PT8H"));
     $arr = array('iss' => 'ilios', 'aud' => 'ilios', 'iat' => $now->format('U'), 'exp' => $expires->format('U'), 'user_id' => $this->user->getId());
     return TokenLib::encode($arr, $this->key);
 }