示例#1
0
 /**
  * Generate table
  */
 protected function generate()
 {
     $days = $this->getSpecificDays();
     $table = new Table\Sheet();
     $line = new Table\Line();
     $lastTimeFrom = NULL;
     $lastTimeTo = NULL;
     $lastDay = NULL;
     $lastTags = NULL;
     $now = new DateTime();
     foreach ($days as $day) {
         $timeFrom = (new FilterTime\Def($day->openTime))->output;
         $timeTo = (new FilterTime\Def($day->closeTime))->output;
         if ($lastTimeFrom === $timeFrom && $lastTimeTo === $timeTo && $this->tagsAreSame($lastTags, $day->tags) && $lastDay !== NULL && (int) $lastDay->day->diff($day->day)->format('%r%a') === 1) {
             $line->dateTo = $day->day;
         } else {
             $lastTimeTo !== NULL && $table->addLine($line);
             $line = new Table\Line();
             $line->dateFrom = $day->day;
             $line->dateTo = $day->day;
             $line->tags = $day->tags;
             $this->lineAddTime($line, $timeFrom, $timeTo);
         }
         if ($day->day->format('Y-m-d') === $now->format('Y-m-d')) {
             $line->setActive();
         }
         $lastTags = $day->tags;
         $lastTimeFrom = $timeFrom;
         $lastTimeTo = $timeTo;
         $lastDay = $day;
     }
     $lastTimeTo !== NULL && $table->addLine($line);
     $this->generatedTable = $table;
 }
示例#2
0
 /**
  * Generate table
  */
 protected function generate()
 {
     $openingHours = $this->openingHours;
     $days = $this->getRelativeDays();
     $table = new Table\Sheet();
     foreach ($days as $day) {
         $line = new Table\Line();
         if ($day === 0) {
             $line->setActive();
         }
         $now = new DateTime();
         $dayOpeningHours = $openingHours->getDay($day === 0 ? $now : $now->modifyClone(($day > 0 ? '+' : '-') . $day . ' days'));
         $timeFrom = (new FilterTime\Def($dayOpeningHours->getOpenTime()))->getOutput();
         $timeTo = (new FilterTime\Def($dayOpeningHours->getCloseTime()))->getOutput();
         foreach ($this->timeFilters as $filter) {
             $timeFromFormatted = (new $filter($timeFrom))->getOutput();
             $timeToFormatted = (new $filter($timeTo))->getOutput();
         }
         $line->setTitle($day);
         $line->setTimeFrom($timeFrom);
         $line->setTimeFromFormatted($timeFromFormatted);
         $line->setTimeTo($timeTo);
         $line->setTimeToFormatted($timeToFormatted);
         $line->tags = $dayOpeningHours->tags;
         if ($dayOpeningHours instanceof \Cothema\OpeningHours\Model\SpecificDay) {
             $line->specific = TRUE;
         }
         $table->addLine($line);
     }
     $this->generatedTable = $table;
 }
示例#3
0
 public function isOk()
 {
     $now = new DateTime();
     if ($this->active && intval($this->getExpiration()->format("U")) > intval($now->format("U"))) {
         return TRUE;
     }
     return FALSE;
 }
示例#4
0
 /**
  * Save past text into database
  * Return generated hash
  * @param array $data
  * @return string
  */
 public function save($data)
 {
     $data->hash = Random::generate(6, '0-9a-zA-Z');
     $data->inserted = $this->dateTime->getTimestamp();
     $data->id_user = '';
     $this->dtb->table('pastes')->insert($data);
     return $data->hash;
 }
示例#5
0
 public function update(Items\Base $item, $data)
 {
     if (preg_match('~^\\d{1,2}[/.]{1}[ ]{0,1}\\d{1,2}[/.]{1}[ ]{0,1}\\d{4}$~', $data, $arr)) {
         $dateArr = preg_split('/[.\\/]{1}[ ]{0,1}/s', $arr[0]);
         $date = new Nette\Utils\DateTime($dateArr[2] . '-' . $dateArr[1] . '-' . $dateArr[0]);
         $data = $date->format('Y-m-d');
     }
     return $data;
 }
 public function renderEmail()
 {
     $person = $this->userManager->get($this->user->getId());
     $this->template->person = $person;
     $now = new DateTime();
     $diff = $now->diff($person->change_email_requested);
     if ($diff->h < 1 && $diff->days == 0) {
         $this->template->openStepTwo = TRUE;
     }
 }
示例#7
0
 /**
  * Set specific payment properties
  *
  * @param Payment $payment
  * @return void
  */
 public function initializePayment(Payment $payment)
 {
     $payment->setMerchantReference('12345678');
     $payment->setPaymentAmount(10000);
     $today = new DateTime();
     $shipDate = $today->modifyClone('+ 10 days');
     $payment->setShipBeforeDate($shipDate);
     $sessionValidity = $today->modifyClone('+ 30 minutes');
     $payment->setSessionValidity($sessionValidity);
 }
示例#8
0
 /**
  * 
  * @return string|boolean
  */
 public function getOpeningAtWarning()
 {
     $timeModified = new DateTime($this->time);
     $timeModified->modify($this->warningOpeningDiff);
     $status = $this->getStatus();
     if ($status instanceof StatusModel\Closed && $this->isOpenedByTime($timeModified)) {
         return $this->openingAtByWeekDay($timeModified->format('w'));
     }
     return FALSE;
 }
示例#9
0
 public function distributionPlanIsCreated()
 {
     $date = new DateTime();
     $from = '"' . $date->format('Y.m.d') . ' 00:00:00"';
     $to = '"' . $date->format('Y.m.d') . ' 23:59:00"';
     $data = $this->db->select('*')->from($this->table)->where('date>' . $from . ' AND date<' . $to)->fetchAll();
     if (isset($data[0])) {
         return true;
     }
     return false;
 }
示例#10
0
文件: String.php 项目: brabijan/fio
 /**
  * Convert string to DateTime
  *
  * @param string $value
  * @param bool $midnight
  * @return DateTime
  */
 public static function createFromFormat($value, $format, $midnight = TRUE)
 {
     if ($value === null) {
         $now = new \DateTime();
         //because of php 5.3 I have to split it to two lines.
         $dt = $now->setTimestamp(0);
         //oldest date
     } else {
         $dt = date_create_from_format($format, $value);
     }
     if ($midnight) {
         $dt->setTime(0, 0, 0);
     }
     return $dt;
 }
示例#11
0
 /**
  * @return Template
  */
 public function createTemplate(UI\Control $control = NULL)
 {
     $latte = $this->latteFactory->create();
     $template = new Template($latte);
     $presenter = $control ? $control->getPresenter(FALSE) : NULL;
     if ($control instanceof UI\Presenter) {
         $latte->setLoader(new Loader($control));
     }
     if ($latte->onCompile instanceof \Traversable) {
         $latte->onCompile = iterator_to_array($latte->onCompile);
     }
     array_unshift($latte->onCompile, function ($latte) use($control, $template) {
         $latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro($latte->getCompiler()));
         UIMacros::install($latte->getCompiler());
         if (class_exists(Nette\Bridges\FormsLatte\FormMacros::class)) {
             Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler());
         }
         if ($control) {
             $control->templatePrepareFilters($template);
         }
     });
     $latte->addFilter('url', 'rawurlencode');
     // back compatiblity
     foreach (['normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse'] as $name) {
         $latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name);
     }
     $latte->addFilter('null', function () {
     });
     $latte->addFilter('modifyDate', function ($time, $delta, $unit = NULL) {
         return $time == NULL ? NULL : Nette\Utils\DateTime::from($time)->modify($delta . $unit);
         // intentionally ==
     });
     if (!isset($latte->getFilters()['translate'])) {
         $latte->addFilter('translate', function (Latte\Runtime\FilterInfo $fi) {
             throw new Nette\InvalidStateException('Translator has not been set. Set translator using $template->setTranslator().');
         });
     }
     // default parameters
     $template->user = $this->user;
     $template->baseUri = $template->baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/') : NULL;
     $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl);
     $template->flashes = [];
     if ($control) {
         $template->control = $control;
         $template->presenter = $presenter;
         $latte->addProvider('uiControl', $control);
         $latte->addProvider('uiPresenter', $presenter);
         $latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($control));
     }
     $latte->addProvider('cacheStorage', $this->cacheStorage);
     // back compatibility
     $template->_control = $control;
     $template->_presenter = $presenter;
     $template->netteCacheStorage = $this->cacheStorage;
     if ($presenter instanceof UI\Presenter && $presenter->hasFlashSession()) {
         $id = $control->getParameterId('flash');
         $template->flashes = (array) $presenter->getFlashSession()->{$id};
     }
     return $template;
 }
示例#12
0
 public function __construct($time = 'now', $object = null)
 {
     parent::__construct($time, $object);
     $this->_oneDayInterval = new \DateInterval('P1D');
     $this->_oneMonthInterval = new \DateInterval('P1M');
     $this->_oneYearInterval = new \DateInterval('P1Y');
 }
示例#13
0
 public function formSucceeded(Form $form)
 {
     try {
         $p = $this->getPresenter();
         $values = $form->getValues();
         $latest = $this->wikiDraftRepository->getLatestByWiki($this->item);
         $start = DateTime::from($values->startTime);
         if ($latest && $start < $latest->createdAt) {
             throw new Exceptions\WikiDraftConflictException($this->translator->translate('locale.error.newer_draft_created_meanwhile'));
         }
         unset($values->name);
         unset($values->startTime);
         $this->wikiDraftRepository->create($values, $this->user, $this->item, new Entities\WikiDraftEntity());
         $ent = $this->item;
         $p->flashMessage($this->translator->translate('locale.item.updated'));
     } catch (Exceptions\WikiDraftConflictException $e) {
         $this->newerDraftExists = true;
         $this->addFormError($form, $e);
     } catch (Exceptions\MissingTagException $e) {
         $this->addFormError($form, $e);
     } catch (PossibleUniqueKeyDuplicationException $e) {
         $this->addFormError($form, $e);
     } catch (\Exception $e) {
         $this->addFormError($form, $e, $this->translator->translate('locale.error.occurred'));
     }
     if (!empty($ent)) {
         $p->redirect('this');
     }
 }
 /**
  * @return Nette\Utils\DateTime|NULL
  */
 public function getValue()
 {
     if ($this->value instanceof DateTime) {
         // clone
         return Nette\Utils\DateTime::from($this->value);
     } elseif (is_int($this->value)) {
         // timestamp
         return Nette\Utils\DateTime::from($this->value);
     } elseif (empty($this->value)) {
         return NULL;
     } elseif (is_string($this->value)) {
         $parsers = $this->parsers;
         $parsers[] = $this->getDefaultParser();
         foreach ($parsers as $parser) {
             $value = $parser($this->value);
             if ($value instanceof DateTime) {
                 return $value;
             }
         }
         try {
             // DateTime constructor throws Exception when invalid input given
             return Nette\Utils\DateTime::from($this->value);
         } catch (\Exception $e) {
             return NULL;
         }
     }
     return NULL;
 }
示例#15
0
 public function sinceDate($placeId, $date = null, $count = 7)
 {
     $files = array();
     $dir = dir($this->resolveDir($placeId));
     if ($dir === false) {
         return array();
     }
     while (false != ($entry = $dir->read())) {
         if (strrpos($entry, '.') != 10 || strrchr($entry, '.') != '.tmp') {
             continue;
         }
         // add filename without ext
         $files[] = strstr($entry, '.', true);
     }
     sort($files);
     $datePlain = is_int($date) ? date('Y-m-d', $date) : $date;
     $pos = 0;
     self::binarySearch($datePlain, $files, 'strcmp', $pos);
     $selection = array_slice($files, $pos, $count);
     $result = array();
     foreach ($selection as $item) {
         $itemDate = DateTime::createFromFormat('Y-m-d', $item)->getTimestamp();
         $result[$itemDate] = $this->forDate($placeId, $item);
     }
     return $result;
 }
示例#16
0
 /**
  * Returns date
  *
  * @return mixed
  */
 public function getValue()
 {
     if (strlen($this->value) > 0) {
         return DateTime::createFromFormat($this->format, $this->value);
     }
     return $this->value;
 }
示例#17
0
 public function handleUpdateDate($firstName, $surName, $mail, $date, $type, $spz, $tel, $carMakes, $carModel, $additionalInfo)
 {
     if ($this->isAjax()) {
         $this->defaults = array('firstName' => $firstName, 'surName' => $surName, 'mail' => $mail, 'date' => $date, 'type' => $type, 'spz' => $spz, 'telNumber' => $tel, 'carMakes' => $carMakes, 'carModel' => $carModel, 'additionalInfo' => $additionalInfo);
         $day = date('N', strtotime(str_replace(' ', '', $date)));
         $multiplier = 0;
         switch ($type) {
             case 5:
                 $multiplier = 1;
                 break;
             case 6:
                 $multiplier = 3;
                 break;
             case 7:
                 $multiplier = 3;
                 break;
         }
         if ($day != 7) {
             $this->timeIntervals = $this->reservationManager->getIntervalsForDay(Nette\Utils\DateTime::createFromFormat('d. m. Y', $date), $multiplier);
         } else {
             $this->timeIntervals = array(Model\ExceptionMessages::NOT_DEFINED => 'Zavřeno');
         }
         $this->redrawControl('addReservationSnippet');
     }
 }
示例#18
0
 protected function createComponentFaktura()
 {
     $dateNow = new DateTime();
     $variableSymbol = 123;
     $supplierBuilder = new ParticipantBuilder("company", "Street", '', "City", "Postcode");
     $supplier = $supplierBuilder->setIn(1111)->setTin("CZ1111")->setAccountNumber("123/0800")->build();
     $nazev = "Customer Name";
     $customerBuilder = new ParticipantBuilder($nazev, "Customer street", '', "Customer city", "Postcode");
     $customer = $customerBuilder->build();
     $items = array(new ItemImpl('Sample item', 1, 1111, TaxImpl::fromPercent(22), false));
     $dataBuilder = new DataBuilder(999, 'Faktura', $supplier, $customer, $dateNow->modifyClone("+14 days"), $dateNow, $items);
     $dataBuilder->setVariableSymbol($variableSymbol)->setDateOfVatRevenueRecognition($dateNow->modifyClone("+15 days"));
     $data = $dataBuilder->build();
     $env = new Eciovni($data);
     $env->setTemplatePath(__DIR__ . "/templates/faktura.latte");
     return $env;
 }
示例#19
0
 public function validityCheck($form)
 {
     $values = $form->getValues();
     if ($values->password != $values->password2) {
         $form->addError('Obě varianty hesla musí být stejné.');
     }
     $bdate = new \Nette\Utils\DateTime($values->birthdate);
     $diff = $bdate->diff(new \Nette\Utils\DateTime());
     $diff = $diff->format('%d');
     if ($diff < 7) {
         $form->addError('Uživatelé by měli být starší než jeden týden. ' . $diff . ' dní je příliš málo.');
     }
     $data = $this->model->getSelection()->where(array("email" => $values->email))->fetch();
     if ($data) {
         $form->addError('Email ' . $values->email . ' je již používán.');
     }
 }
示例#20
0
 /**
  * @param array $data
  * @return Address
  */
 public static function createFromArray(array $data)
 {
     $data['first_seen'] = DateTime::createFromFormat(DateTime::ATOM, $data['first_seen']);
     $data['last_seen'] = DateTime::createFromFormat(DateTime::ATOM, $data['last_seen']);
     $address = new Address();
     $address->data = $data;
     return $address;
 }
示例#21
0
 /**
  * @param array $data
  * @return Block
  */
 public static function createFromArray(array $data)
 {
     $data['block_time'] = DateTime::createFromFormat(DateTime::ATOM, $data['block_time']);
     $data['arrival_time'] = DateTime::createFromFormat(DateTime::ATOM, $data['arrival_time']);
     $block = new Block();
     $block->data = $data;
     return $block;
 }
示例#22
0
 protected function getDefaultParser()
 {
     return function ($value) {
         if (!preg_match('#^(?P<dd>\\d{1,2})[. -] *(?P<mm>\\d{1,2})([. -] *(?P<yyyy>\\d{4})?)?$#', $value, $matches)) {
             return NULL;
         }
         $dd = $matches['dd'];
         $mm = $matches['mm'];
         $yyyy = isset($matches['yyyy']) ? $matches['yyyy'] : date('Y');
         if (!checkdate($mm, $dd, $yyyy)) {
             return NULL;
         }
         $value = new Nette\Utils\DateTime();
         $value->setDate($yyyy, $mm, $dd);
         $value->setTime(0, 0, 0);
         return $value;
     };
 }
示例#23
0
 /**
  * @return UI\ITemplate
  */
 protected function createTemplate()
 {
     /** @var Nette\Bridges\ApplicationLatte\Template $template */
     $template = parent::createTemplate();
     $latte = $template->getLatte();
     $latte->addFilter('texy', function ($input) {
         $texy = $this->prepareTexy();
         $html = new Nette\Utils\Html();
         return $html::el()->setHtml($texy->process($input));
     });
     $latte->addFilter('vlna', function ($string) {
         $string = preg_replace('<([^a-zA-Z0-9])([ksvzaiou])\\s([a-zA-Z0-9]{1,})>i', "\$1\$2 \$3", $string);
         //&nbsp; === \xc2\xa0
         return $string;
     });
     $latte->addFilter('dateInWords', function ($time) {
         $time = Nette\Utils\DateTime::from($time);
         $months = [1 => 'leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'];
         return $time->format('j. ') . $months[$time->format('n')] . $time->format(' Y');
     });
     $latte->addFilter('timeAgoInWords', function ($time) {
         $time = Nette\Utils\DateTime::from($time);
         $delta = round((time() - $time->getTimestamp()) / 60);
         if ($delta == 0) {
             return 'před okamžikem';
         }
         if ($delta == 1) {
             return 'před minutou';
         }
         if ($delta < 45) {
             return "před {$delta} minutami";
         }
         if ($delta < 90) {
             return 'před hodinou';
         }
         if ($delta < 1440) {
             return 'před ' . round($delta / 60) . ' hodinami';
         }
         if ($delta < 2880) {
             return 'včera';
         }
         if ($delta < 43200) {
             return 'před ' . round($delta / 1440) . ' dny';
         }
         if ($delta < 86400) {
             return 'před měsícem';
         }
         if ($delta < 525960) {
             return 'před ' . round($delta / 43200) . ' měsíci';
         }
         if ($delta < 1051920) {
             return 'před rokem';
         }
         return 'před ' . round($delta / 525960) . ' lety';
     });
     return $template;
 }
示例#24
0
 /**
  * @param string $email
  * @param User|null $sender
  */
 public function __construct($email, User $sender = null)
 {
     $this->setEmail($email);
     $this->sender = $sender;
     $this->generateToken();
     $startDate = \Nette\Utils\DateTime::createFromFormat('!Y-m-d', date('Y-m-d'));
     $this->setValidity($startDate);
     $this->lastSending = $startDate;
 }
示例#25
0
 /**
  * @return DataGrid
  */
 public function create()
 {
     $grid = $this->gridFactory->create();
     $grid->addColumnText("id", "ID");
     $grid->addColumnText("name", "Name")->setFilterText();
     $grid->addColumnDateTime("date", "Date")->setFilterDate();
     $grid->setDataSource([["id" => 1, "name" => "Karel", "date" => DateTime::createFromFormat("d.m.Y", "10.10.2000")], ["id" => 2, "name" => "Pavel", "date" => new DateTime()]]);
     return $grid;
 }
 /**
  * @param array $data
  * @return \FlickrDownloadr\Photo\Photo
  */
 public function fromPlainToEntity(array $data, $photoSizeName)
 {
     $code = $this->photoSizeHelper->getCode($photoSizeName);
     $url = $data['url_' . $code];
     $width = $data['width_' . $code];
     $height = $data['height_' . $code];
     $date = \Nette\Utils\DateTime::from($data['datetaken']);
     return new Photo($data, $url, $width, $height, $date);
 }
示例#27
0
 /**
  * Returns control's value.
  * @return string
  */
 public function getValue()
 {
     $value = parent::getValue();
     // convert to Nette\Utils\DateTime
     if ($value && is_string($value)) {
         $format = "d.m.Y";
         $value = DateTime::createFromFormat($format, $value);
     }
     return $value ? $value : NULL;
 }
示例#28
0
 /**
  * @param \Nette\Application\UI\Form $form
  */
 public function processForm(Form $form)
 {
     $values = $form->values;
     $event = $this->event ? $this->event : new Entity\Event($this->securityUser->getIdentity());
     $event->name = $values->name;
     $event->date = DateTime::from($values->date);
     $event->place = $values->place;
     $event->note = $values->note;
     $this->eventFacade->save($event);
 }
示例#29
0
 /**
  * @param SplFileInfo $articleDirectory
  * @param string $relativePath
  * @return array
  */
 private function getMeta($articleDirectory, $relativePath)
 {
     $filePath = sprintf('%s/%s', $articleDirectory->getRealPath(), self::META_FILE_NAME);
     $data = Neon::decode(file_get_contents($filePath));
     $data['perex'] = $this->parsedown->text($data['perex']);
     $data['publishedAt'] = $data['publishedAt'] ? DateTime::from($data['publishedAt']) : null;
     $data['imagePath'] = "{$relativePath}/" . self::IMAGE_NAME;
     $data['keyIdentifier'] = $this->parseKeyIdentifier($relativePath);
     return $data;
 }
    /**
     * @return void
     *
     * Results of this function are periodically deleted
     * from production database. Update with caution!
     */
    public function deleteOldEmpty()
    {
        $this->connection->query('
			DELETE FROM [video_views]
			WHERE [percent] = 0
				AND [time] = 0
				AND [furthest] = 0
				AND [events]::text = "[]"
				AND [created_at] < ?
		', DateTime::from('7 days ago'));
    }