Exemple #1
0
 /**
  * Auto generate duration if empty
  *
  * @ORM\PrePersist
  * @ORM\PreUpdate
  * @return Timeslice
  */
 public function updateDurationOnEmpty()
 {
     if (empty($this->duration) && !empty($this->startedAt) && !empty($this->stoppedAt)) {
         $this->duration = abs($this->stoppedAt->getTimestamp() - $this->startedAt->getTimestamp());
     }
     return $this;
 }
Exemple #2
0
 /**
  * Get publishedAtString.
  *
  * @return string
  */
 public function getPublishedAtString()
 {
     setlocale(LC_TIME, 'fr_FR');
     if ($this->publishedAt) {
         return strftime('%d %B %Y', $this->publishedAt->getTimestamp());
     } else {
         return '';
     }
 }
Exemple #3
0
 /**
  * Get publishedAtString
  *
  * @return string
  */
 public function getPublishedAtString()
 {
     setlocale(LC_TIME, "fr_FR");
     return strftime('%d %B %Y', $this->publishedAt->getTimestamp());
 }
Exemple #4
0
 /**
  * Ajax exec cron.
  * 
  * @access public
  * @return void
  */
 public function ajaxExec()
 {
     ignore_user_abort(true);
     set_time_limit(0);
     session_write_close();
     /* Check cron turnon. */
     if (empty($this->config->global->cron)) {
         die;
     }
     /* make cron status to running. */
     $configID = $this->cron->getConfigID();
     $configID = $this->cron->markCronStatus('running', $configID);
     /* Get and parse crons. */
     $crons = $this->cron->getCrons('nostop');
     $parsedCrons = $this->cron->parseCron($crons);
     /* Update last time. */
     $this->cron->changeStatus(key($parsedCrons), 'normal', true);
     $this->loadModel('common');
     $startedTime = time();
     while (true) {
         /* When cron is null then die. */
         if (empty($crons)) {
             break;
         }
         if (empty($parsedCrons)) {
             break;
         }
         if (!$this->cron->getTurnon()) {
             break;
         }
         /* Run crons. */
         $now = new datetime('now');
         $this->common->loadConfigFromDB();
         foreach ($parsedCrons as $id => $cron) {
             $cronInfo = $this->cron->getById($id);
             /* Skip empty and stop cron.*/
             if (empty($cronInfo) or $cronInfo->status == 'stop') {
                 continue;
             }
             /* Skip cron that status is running and run time is less than max. */
             if ($cronInfo->status == 'running' and time() - strtotime($cronInfo->lastTime) < $this->config->cron->maxRunTime) {
                 continue;
             }
             /* Skip cron that last time is more than this cron time. */
             if ($cronInfo->lastTime > $cron['time']->format(DT_DATETIME1)) {
                 die;
             }
             if ($now > $cron['time']) {
                 $this->cron->changeStatus($id, 'running');
                 $parsedCrons[$id]['time'] = $cron['cron']->getNextRunDate();
                 /* Execution command. */
                 $output = '';
                 $return = '';
                 if ($cron['command']) {
                     if (isset($crons[$id]) and $crons[$id]->type == 'zentao') {
                         parse_str($cron['command'], $params);
                         if (isset($params['moduleName']) and isset($params['methodName'])) {
                             $this->app->loadConfig($params['moduleName']);
                             $output = $this->fetch($params['moduleName'], $params['methodName']);
                         }
                     } elseif (isset($crons[$id]) and $crons[$id]->type == 'system') {
                         exec($cron['command'], $output, $return);
                         if ($output) {
                             $output = join("\n", $output);
                         }
                     }
                     /* Save log. */
                     $log = '';
                     $time = $now->format('G:i:s');
                     $log = "{$time} task " . $id . " executed,\ncommand: {$cron['command']}.\nreturn : {$return}.\noutput : {$output}\n";
                     $this->cron->logCron($log);
                     unset($log);
                 }
                 /* Revert cron status. */
                 $this->cron->changeStatus($id, 'normal');
             }
         }
         /* Check whether the task change. */
         $newCrons = $this->cron->getCrons('nostop');
         $changed = $this->cron->checkChange();
         if (count($newCrons) != count($crons) or $changed) {
             $crons = $newCrons;
             $parsedCrons = $this->cron->parseCron($newCrons);
         }
         /* Sleep some seconds. */
         $sleepTime = 60 - (time() - $now->getTimestamp()) % 60;
         sleep($sleepTime);
         /* Break while. */
         if (connection_status() != CONNECTION_NORMAL) {
             break;
         }
         if ((time() - $startedTime) / 3600 / 24 >= $this->config->cron->maxRunDays) {
             break;
         }
     }
     /* Revert cron status to stop. */
     $this->cron->markCronStatus('stop', $configID);
 }
Exemple #5
0
<?php

$timestamp = 1445594400;
date_default_timezone_set('Europe/Madrid');
echo date("d/m/Y", $timestamp);
//echo('Fecha obtenida '.strtotime($timestamp));
//echo date('c',$timestamp);
echo '<br/>';
$local = 1445072400;
echo 'Fecha obtenida ' . date("Y/m/d", $local);
echo '<br/>';
$data = new datetime("2015-12-20 00:00:00");
echo 'Fecha convertida: ' . $data->getTimestamp();
echo '<br/>';
$fechahoy = new datetime($now);
echo 'Datetime Actual -> ' . $fechahoy->getTimestamp();
echo '<br/>';
echo '-----------------CONVERSIÓN DE UNA FECHA ---------------';
echo '<br/>';
$fecha = new DateTime();
echo $fecha->getTimestamp();
echo '<br/>';
//echo date ('c',$local);