Exemplo n.º 1
0
 /**
  * @param $value
  * @param $dataSource
  * @return mixed
  */
 public function filter($value, IDataSource $dataSource)
 {
     $value = strtotime($value);
     $begin = strtotime('today', $value);
     $end = strtotime('+1 day', $begin);
     $dataSource->filter(['%n BETWEEN %s AND %s', $this->column->getColumn(), DateTime::from($begin), DateTime::from($end)]);
 }
Exemplo n.º 2
0
 /**
  * Returns date
  *
  * @return mixed
  */
 public function getValue()
 {
     if (strlen($this->value) > 0) {
         return DateTime::createFromFormat($this->format, $this->value);
     }
     return $this->value;
 }
Exemplo n.º 3
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\DateTime($values->birthdate);
     $diff = $bdate->diff(new \Nette\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.');
     }
 }
Exemplo n.º 4
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\DateTime();
         $value->setDate($yyyy, $mm, $dd);
         $value->setTime(0, 0, 0);
         return $value;
     };
 }
Exemplo n.º 5
0
 public function setValue($value)
 {
     if ($value) {
         $date = DateTime::from($value);
         $this->day = $date->format('j');
         $this->month = $date->format('n');
         $this->year = $date->format('Y');
     } else {
         $this->day = $this->month = $this->year = NULL;
     }
 }
Exemplo n.º 6
0
 /**
  *
  * @param string $modify
  * @return type
  */
 public function modify($modify)
 {
     if ($modify == 'midnight' || $modify == 'today') {
         return $this->setTime(0, 0, 0);
         //fix for linux
     }
     if ($this->isRelative($modify) && $this->isSunday()) {
         parent::modify('-1 week');
     }
     $res = parent::modify($modify);
     return $res;
 }
Exemplo n.º 7
0
 protected function getDefaultParser()
 {
     return function ($value) {
         if (!preg_match('#^(?P<dd>\\d{1,2})[. -] *(?P<mm>\\d{1,2})(?:[. -] *(?P<yyyy>\\d{4})?)?(?: *[ -@] *(?P<hh>\\d{1,2})[:.](?P<ii>\\d{1,2})(?:[:.](?P<ss>\\d{1,2}))?)?$#', $value, $matches)) {
             return NULL;
         }
         $dd = $matches['dd'];
         $mm = $matches['mm'];
         $yyyy = isset($matches['yyyy']) ? $matches['yyyy'] : date('Y');
         $hh = isset($matches['hh']) ? $matches['hh'] : 0;
         $ii = isset($matches['ii']) ? $matches['ii'] : 0;
         $ss = isset($matches['ss']) ? $matches['ss'] : 0;
         if (!($hh >= 0 && $hh < 24 && $ii >= 0 && $ii <= 59 && $ss >= 0 && $ss <= 59)) {
             $hh = $ii = $ss = 0;
         }
         if (!checkdate($mm, $dd, $yyyy)) {
             return NULL;
         }
         $value = new Nette\DateTime();
         $value->setDate($yyyy, $mm, $dd);
         $value->setTime($hh, $ii, $ss);
         return $value;
     };
 }
Exemplo n.º 8
0
 /**
  * Parses the txt file and updates the cache files
  *
  * @return bool whether the file was correctly written to the disk
  */
 public function updateCache($force = FALSE)
 {
     if (($this->_registry = $this->load(Registry::REGISTRY)) !== NULL) {
         $cver = $this->load(Registry::ETAG);
         $this->getRemoteData($cver);
         if ($cver == $this->_etag && $this->load(Registry::MD5) == md5($this->_sourceData) && !$force) {
             return TRUE;
         }
     }
     $this->getRemoteData();
     $this->raw2csv();
     $this->csv2registry();
     // Save and return
     $expiration = \Nette\DateTime::from(time())->add(new \DateInterval('P2W'));
     $dependencies = [Caching\Cache::CONSTS => ['Nette\\Framework::REVISION'], Caching\Cache::EXPIRATION => $expiration];
     $this->save(Registry::SOURCE, $this->sourceUrl, $dependencies);
     $this->save(Registry::DATA, $this->_sourceData, $dependencies);
     $this->save(Registry::ETAG, $this->_etag, $dependencies);
     $this->save(Registry::MD5, md5($this->_sourceData), $dependencies);
     $this->save(Registry::REGISTRY, $this->_registry, $dependencies);
     $this->release();
 }
Exemplo n.º 9
0
 function setValue($value)
 {
     if ($value instanceof DateTime) {
     } elseif (is_int($value)) {
     } elseif (empty($value)) {
         $rawValue = $value;
         $value = NULL;
     } elseif (is_string($value)) {
         $rawValue = $value;
         if (preg_match('#^(?P<dd>\\d{1,2})[. -] *(?P<mm>\\d{1,2})([. -] *(?P<yyyy>\\d{4})?)?$#', $value, $matches)) {
             $dd = $matches['dd'];
             $mm = $matches['mm'];
             $yyyy = isset($matches['yyyy']) ? $matches['yyyy'] : date('Y');
             if (checkdate($mm, $dd, $yyyy)) {
                 $value = "{$yyyy}-{$mm}-{$dd}";
             } else {
                 $value = NULL;
             }
         }
     } else {
         throw new \InvalidArgumentException();
     }
     if ($value !== NULL) {
         try {
             $value = Nette\DateTime::from($value);
         } catch (\Exception $e) {
             $value = NULL;
         }
     }
     if (!isset($rawValue) && isset($value)) {
         $rawValue = $value->format(self::W3C_DATE_FORMAT);
     }
     $this->value = $value;
     $this->rawValue = $rawValue;
     return $this;
 }
Exemplo n.º 10
0
 /**
  * Creates Addon entity from Nette\Database row.
  *
  * @todo   Consider lazy loading for versions and tags.
  *
  * @param \Nette\Database\Table\ActiveRow
  * @param AddonVotes
  * @return Addon
  */
 public static function fromActiveRow(ActiveRow $row, AddonVotes $addonVotes = NULL)
 {
     $addon = new static();
     $addon->id = (int) $row->id;
     $addon->name = $row->name;
     $addon->composerVendor = $row->composerVendor;
     $addon->composerName = $row->composerName;
     $addon->userId = (int) $row->user->id;
     $addon->shortDescription = $row->shortDescription;
     $addon->description = $row->description;
     $addon->descriptionFormat = $row->descriptionFormat;
     $addon->defaultLicense = $row->defaultLicense;
     $addon->repository = $row->repository;
     $addon->repositoryHosting = $row->repositoryHosting;
     $addon->demo = $row->demo;
     $addon->updatedAt = $row->updatedAt ? DateTime::from($row->updatedAt) : NULL;
     $addon->deletedAt = $row->deletedAt;
     $addon->deletedBy = $row->ref('deletedBy');
     $addon->type = $row->type;
     $addon->stars = $row->stars;
     foreach ($row->related('versions') as $versionRow) {
         $version = AddonVersion::fromActiveRow($versionRow);
         $version->addon = $addon;
         $addon->versions[$version->version] = $version;
     }
     foreach ($row->related('tags') as $tagRow) {
         $addon->tags[$tagRow->tag->id] = Tag::fromActiveRow($tagRow->tag);
     }
     foreach ($row->related('addons_resources') as $resourceRow) {
         $addon->resources[$resourceRow->type] = $resourceRow->resource;
     }
     if ($addonVotes) {
         $addon->votes = $addonVotes->calculatePopularity($row);
     }
     return $addon;
 }
Exemplo n.º 11
0
 /**
  * Sends a cookie.
  * @param  string name of the cookie
  * @param  string value
  * @param  string|int|DateTime  expiration time, value 0 means "until the browser is closed"
  * @param  string
  * @param  string
  * @param  bool
  * @param  bool
  * @return Response  provides a fluent interface
  * @throws Nette\InvalidStateException  if HTTP headers have been sent
  */
 public function setCookie($name, $value, $time, $path = NULL, $domain = NULL, $secure = NULL, $httpOnly = NULL)
 {
     if (headers_sent($file, $line)) {
         throw new Nette\InvalidStateException("Cannot set cookie after HTTP headers have been sent" . ($file ? " (output started at {$file}:{$line})." : "."));
     }
     setcookie($name, $value, $time ? Nette\DateTime::from($time)->format('U') : 0, $path === NULL ? $this->cookiePath : (string) $path, $domain === NULL ? $this->cookieDomain : (string) $domain, $secure === NULL ? $this->cookieSecure : (bool) $secure, $httpOnly === NULL ? $this->cookieHttpOnly : (bool) $httpOnly);
     return $this;
 }
 /**
  * Restricts the search by modified time.
  * @param  string  "[operator] [date]" example: >1978-01-23
  * @param  mixed
  * @return self
  */
 public function date($operator, $date = NULL)
 {
     if (func_num_args() === 1) {
         // in $operator is predicate
         if (!preg_match('#^(?:([=<>!]=?|<>)\\s*)?(.+)\\z#i', $operator, $matches)) {
             throw new Nette\InvalidArgumentException('Invalid date predicate format.');
         }
         list(, $operator, $date) = $matches;
         $operator = $operator ? $operator : '=';
     }
     $date = Nette\DateTime::from($date)->format('U');
     return $this->filter(function ($file) use($operator, $date) {
         return Finder::compare($file->getMTime(), $operator, $date);
     });
 }
Exemplo n.º 13
0
 private function completeDependencies($dp, $data)
 {
     if (is_object($data)) {
         $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkSerializationVersion'), get_class($data), Nette\Reflection\ClassType::from($data)->getAnnotation('serializationVersion'));
     }
     // convert expire into relative amount of seconds
     if (isset($dp[Cache::EXPIRATION])) {
         $dp[Cache::EXPIRATION] = Nette\DateTime::from($dp[Cache::EXPIRATION])->format('U') - time();
     }
     // convert FILES into CALLBACKS
     if (isset($dp[self::FILES])) {
         //clearstatcache();
         foreach (array_unique((array) $dp[self::FILES]) as $item) {
             $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkFile'), $item, @filemtime($item));
             // @ - stat may fail
         }
         unset($dp[self::FILES]);
     }
     // add namespaces to items
     if (isset($dp[self::ITEMS])) {
         $dp[self::ITEMS] = array_unique(array_map(array($this, 'generateKey'), (array) $dp[self::ITEMS]));
     }
     // convert CONSTS into CALLBACKS
     if (isset($dp[self::CONSTS])) {
         foreach (array_unique((array) $dp[self::CONSTS]) as $item) {
             $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkConst'), $item, constant($item));
         }
         unset($dp[self::CONSTS]);
     }
     if (!is_array($dp)) {
         $dp = array();
     }
     return $dp;
 }
Exemplo n.º 14
0
 /**
  * Date/time formatting.
  * @param  string|int|DateTime
  * @param  string
  * @return string
  */
 public static function date($time, $format = NULL)
 {
     if ($time == NULL) {
         // intentionally ==
         return NULL;
     }
     if (!isset($format)) {
         $format = self::$dateFormat;
     }
     $time = Nette\DateTime::from($time);
     return Strings::contains($format, '%') ? strftime($format, $time->format('U')) : $time->format($format);
     // formats using date()
 }
Exemplo n.º 15
0
 /**
  * Sends a cookie.
  * @param  string name of the cookie
  * @param  string value
  * @param  string|int|DateTime  expiration time, value 0 means "until the browser is closed"
  * @param  string
  * @param  string
  * @param  bool
  * @param  bool
  * @return self
  * @throws Nette\InvalidStateException  if HTTP headers have been sent
  */
 public function setCookie($name, $value, $time, $path = NULL, $domain = NULL, $secure = NULL, $httpOnly = NULL)
 {
     if (!headers_sent() && ob_get_level() && ob_get_length()) {
         trigger_error("Possible problem: you are sending a cookie while already having some data in output buffer.  This may not work if the outputted data grows. Try starting the session earlier.", E_USER_NOTICE);
     }
     if (headers_sent($file, $line)) {
         throw new Nette\InvalidStateException("Cannot set cookie after HTTP headers have been sent" . ($file ? " (output started at {$file}:{$line})." : "."));
     }
     setcookie($name, $value, $time ? Nette\DateTime::from($time)->format('U') : 0, $path === NULL ? $this->cookiePath : (string) $path, $domain === NULL ? $this->cookieDomain : (string) $domain, $secure === NULL ? $this->cookieSecure : (bool) $secure, $httpOnly === NULL ? $this->cookieHttpOnly : (bool) $httpOnly);
     $this->removeDuplicateCookies();
     return $this;
 }
Exemplo n.º 16
0
 /**
  *
  * @param float $amount
  * @param string $iban
  * @param string $bic
  * @param string $benefName
  * @param string $benefCountry
  * @throws FioException
  */
 public function addPaymentForeing($amount, $iban, $bic, $benefName, $benefCountry)
 {
     if ($this->content) {
         $this->createEmptyXml();
     }
     if (strlen($bic) != 11) {
         throw new FioException('BIC must lenght 11. Is ISO 9362.');
     }
     if (strlen($benefCountry) != 2 && $benefCountry != 'TCH') {
         throw new FioException('Country code consists of two letters.');
     }
     $this->xml->startElement('T2Transaction');
     $this->xmlContent($amount, $iban);
     $this->addXmlNode('bic', $bic, TRUE);
     $this->addXmlNode('date', DateTime::from($this->date)->format('Y-m-d'));
     $this->addXmlNode('comment', $this->comment);
     $this->addXmlNode('benefName', $benefName, TRUE);
     $this->addXmlNode('benefStreet', $this->benefStreet);
     $this->addXmlNode('benefCity', $this->benefCity);
     $this->addXmlNode('benefCountry', strtoupper($benefCountry), TRUE);
     $this->addXmlNode('remittanceInfo1', $this->remittanceInfo1);
     $this->addXmlNode('remittanceInfo2', $this->remittanceInfo2);
     $this->addXmlNode('remittanceInfo3', $this->remittanceInfo3);
     $this->addXmlNode('paymentReason', $this->paymentReason, FALSE);
     $this->addXmlNode('paymentType', $this->paymentTypeEuro, self::PAYMENT_STANDARD_EURO);
     $this->xml->endElement();
 }
Exemplo n.º 17
0
 public function setValidated($id)
 {
     $now = new \Nette\DateTime();
     $this->localLoginModel->update($id, array("validated" => $now->format('Y-m-d H:i:s')));
 }
Exemplo n.º 18
0
 /**
  * Enables log out after inactivity.
  * @param  string|int|DateTime Number of seconds or timestamp
  * @param  int Log out when the browser is closed | Clear the identity from persistent storage?
  * @return self
  */
 public function setExpiration($time, $flags = 0)
 {
     $section = $this->getSessionSection(TRUE);
     if ($time) {
         $time = Nette\DateTime::from($time)->format('U');
         $section->expireTime = $time;
         $section->expireDelta = $time - time();
     } else {
         unset($section->expireTime, $section->expireDelta);
     }
     $section->expireIdentity = (bool) ($flags & self::CLEAR_IDENTITY);
     $section->expireBrowser = (bool) ($flags & self::BROWSER_CLOSED);
     $section->browserCheck = TRUE;
     $section->setExpiration(0, 'browserCheck');
     $section->setExpiration($time, 'foo');
     // time check
     return $this;
 }
Exemplo n.º 19
0
 /**
  * Sends a cookie.
  * @param  string name of the cookie
  * @param  string value
  * @param  string|int|DateTime  expiration time, value 0 means "until the browser is closed"
  * @param  string
  * @param  string
  * @param  bool
  * @param  bool
  * @return self
  * @throws Nette\InvalidStateException  if HTTP headers have been sent
  */
 public function setCookie($name, $value, $time, $path = NULL, $domain = NULL, $secure = NULL, $httpOnly = NULL)
 {
     self::checkHeaders();
     setcookie($name, $value, $time ? Nette\DateTime::from($time)->format('U') : 0, $path === NULL ? $this->cookiePath : (string) $path, $domain === NULL ? $this->cookieDomain : (string) $domain, $secure === NULL ? $this->cookieSecure : (bool) $secure, $httpOnly === NULL ? $this->cookieHttpOnly : (bool) $httpOnly);
     $this->removeDuplicateCookies();
     return $this;
 }
Exemplo n.º 20
0
 /**
  * Writes item into the cache.
  * Dependencies are:
  * - Cache::PRIORITY => (int) priority
  * - Cache::EXPIRATION => (timestamp) expiration
  * - Cache::SLIDING => (bool) use sliding expiration?
  * - Cache::TAGS => (array) tags
  * - Cache::FILES => (array|string) file names
  * - Cache::ITEMS => (array|string) cache items
  * - Cache::CONSTS => (array|string) cache items
  *
  * @param  mixed  key
  * @param  mixed  value
  * @param  array  dependencies
  * @return mixed  value itself
  * @throws Nette\InvalidArgumentException
  */
 public function save($key, $data, array $dp = NULL)
 {
     $this->key = is_scalar($key) ? (string) $key : serialize($key);
     $key = $this->namespace . md5($this->key);
     // convert expire into relative amount of seconds
     if (isset($dp[Cache::EXPIRATION])) {
         $dp[Cache::EXPIRATION] = Nette\DateTime::from($dp[Cache::EXPIRATION])->format('U') - time();
     }
     // convert FILES into CALLBACKS
     if (isset($dp[self::FILES])) {
         //clearstatcache();
         foreach ((array) $dp[self::FILES] as $item) {
             $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkFile'), $item, @filemtime($item));
             // @ - stat may fail
         }
         unset($dp[self::FILES]);
     }
     // add namespaces to items
     if (isset($dp[self::ITEMS])) {
         $dp[self::ITEMS] = (array) $dp[self::ITEMS];
         foreach ($dp[self::ITEMS] as $k => $item) {
             $dp[self::ITEMS][$k] = $this->namespace . md5(is_scalar($item) ? $item : serialize($item));
         }
     }
     // convert CONSTS into CALLBACKS
     if (isset($dp[self::CONSTS])) {
         foreach ((array) $dp[self::CONSTS] as $item) {
             $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkConst'), $item, constant($item));
         }
         unset($dp[self::CONSTS]);
     }
     if ($data instanceof Nette\Callback || $data instanceof \Closure) {
         Nette\Utils\CriticalSection::enter();
         $data = $data->__invoke();
         Nette\Utils\CriticalSection::leave();
     }
     if (is_object($data)) {
         $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkSerializationVersion'), get_class($data), Nette\Reflection\ClassType::from($data)->getAnnotation('serializationVersion'));
     }
     $this->data = $data;
     if ($data === NULL) {
         $this->storage->remove($key);
     } else {
         $this->storage->write($key, $data, (array) $dp);
     }
     return $data;
 }
Exemplo n.º 21
0
 /**
  * Date/time modification.
  * @param  string|int|DateTime
  * @param  string|int
  * @param  string
  * @return Nette\DateTime
  */
 public static function modifyDate($time, $delta, $unit = NULL)
 {
     return $time == NULL ? NULL : Nette\DateTime::from($time)->modify($delta . $unit);
 }
Exemplo n.º 22
0
 /**
  * Date/time formatting.
  * @param  string|int|DateTime
  * @param  string
  * @return string
  */
 public static function date($time, $format = NULL)
 {
     if ($time == NULL) {
         // intentionally ==
         return NULL;
     }
     if (!isset($format)) {
         $format = self::$dateFormat;
     }
     $time = Nette\DateTime::from($time);
     return strpos($format, '%') === FALSE ? $time->format($format) : strftime($format, $time->format('U'));
     // formats according to locales
 }
 /**
  * Sets the expiration of the section or specific variables.
  * @param  string|int|DateTime  time, value 0 means "until the browser is closed"
  * @param  mixed   optional list of variables / single variable to expire
  * @return SessionSection  provides a fluent interface
  */
 public function setExpiration($time, $variables = NULL)
 {
     $this->start();
     if (empty($time)) {
         $time = NULL;
         $whenBrowserIsClosed = TRUE;
     } else {
         $time = Nette\DateTime::from($time)->format('U');
         $max = ini_get('session.gc_maxlifetime');
         if ($time - time() > $max + 3) {
             // bulgarian constant
             trigger_error("The expiration time is greater than the session expiration {$max} seconds", E_USER_NOTICE);
         }
         $whenBrowserIsClosed = FALSE;
     }
     if ($variables === NULL) {
         // to entire section
         $this->meta['']['T'] = $time;
         $this->meta['']['B'] = $whenBrowserIsClosed;
     } elseif (is_array($variables)) {
         // to variables
         foreach ($variables as $variable) {
             $this->meta[$variable]['T'] = $time;
             $this->meta[$variable]['B'] = $whenBrowserIsClosed;
         }
     } else {
         // to variable
         $this->meta[$variables]['T'] = $time;
         $this->meta[$variables]['B'] = $whenBrowserIsClosed;
     }
     return $this;
 }
Exemplo n.º 24
0
 /**
  * Sends a cookie.
  * @param  string name of the cookie
  * @param  string value
  * @param  string|int|DateTime  expiration time, value 0 means "until the browser is closed"
  * @param  string
  * @param  string
  * @param  bool
  * @param  bool
  * @return Response  provides a fluent interface
  * @throws Nette\InvalidStateException  if HTTP headers have been sent
  */
 public function setCookie($name, $value, $time, $path = NULL, $domain = NULL, $secure = NULL, $httpOnly = NULL)
 {
     if (headers_sent($file, $line)) {
         throw new Nette\InvalidStateException("Cannot set cookie after HTTP headers have been sent" . ($file ? " (output started at {$file}:{$line})." : "."));
     }
     setcookie($name, $value, $time ? Nette\DateTime::from($time)->format('U') : 0, $path === NULL ? $this->cookiePath : (string) $path, $domain === NULL ? $this->cookieDomain : (string) $domain, $secure === NULL ? $this->cookieSecure : (bool) $secure, $httpOnly === NULL ? $this->cookieHttpOnly : (bool) $httpOnly);
     $flatten = array();
     foreach (headers_list() as $header) {
         if (preg_match('#^Set-Cookie: .+?=#', $header, $m)) {
             $flatten[$m[0]] = $header;
             if (PHP_VERSION_ID < 50300) {
                 // multiple deleting due PHP bug #61605
                 header('Set-Cookie:');
             } else {
                 header_remove('Set-Cookie');
             }
         }
     }
     foreach (array_values($flatten) as $key => $header) {
         header($header, $key === 0);
     }
     return $this;
 }
Exemplo n.º 25
0
 /**
  * Normalizes result row.
  * @param  array
  * @return array
  */
 public function normalizeRow($row)
 {
     if ($this->types === NULL) {
         $this->types = (array) $this->supplementalDriver->getColumnTypes($this->pdoStatement);
     }
     foreach ($this->types as $key => $type) {
         $value = $row[$key];
         if ($value === NULL || $value === FALSE || $type === IReflection::FIELD_TEXT) {
         } elseif ($type === IReflection::FIELD_INTEGER) {
             $row[$key] = is_float($tmp = $value * 1) ? $value : $tmp;
         } elseif ($type === IReflection::FIELD_FLOAT) {
             if (($pos = strpos($value, '.')) !== FALSE) {
                 $value = rtrim(rtrim($pos === 0 ? "0{$value}" : $value, '0'), '.');
             }
             $float = (double) $value;
             $row[$key] = (string) $float === $value ? $float : $value;
         } elseif ($type === IReflection::FIELD_BOOL) {
             $row[$key] = (bool) $value && $value !== 'f' && $value !== 'F';
         } elseif ($type === IReflection::FIELD_DATETIME || $type === IReflection::FIELD_DATE || $type === IReflection::FIELD_TIME) {
             $row[$key] = new Nette\DateTime($value);
         } elseif ($type === IReflection::FIELD_TIME_INTERVAL) {
             preg_match('#^(-?)(\\d+)\\D(\\d+)\\D(\\d+)\\z#', $value, $m);
             $row[$key] = new \DateInterval("PT{$m['2']}H{$m['3']}M{$m['4']}S");
             $row[$key]->invert = (int) (bool) $m[1];
         } elseif ($type === IReflection::FIELD_UNIX_TIMESTAMP) {
             $row[$key] = Nette\DateTime::from($value);
         }
     }
     return $this->supplementalDriver->normalizeRow($row);
 }
Exemplo n.º 26
0
Arquivo: Fio.php Projeto: svobodni/web
 /**
  * Na datum posledního neúspěšně staženého dne
  *
  * @param mixed $date
  * @return string
  */
 public function setLastDate($date)
 {
     $this->requestUrl = self::REST_URL . sprintf('set-last-date/%s/%s/', $this->token, DateTime::from($date)->format('Y-m-d'));
     $this->availableAnotherRequest();
     return CurlBuilder::download($this->requestUrl);
 }
Exemplo n.º 27
0
 /**
  * Sets the amount of time allowed between requests before the session will be terminated.
  * @param  string|int|DateTime  time, value 0 means "until the browser is closed"
  * @return self
  */
 public function setExpiration($time)
 {
     if (empty($time)) {
         return $this->setOptions(array('gc_maxlifetime' => self::DEFAULT_FILE_LIFETIME, 'cookie_lifetime' => 0));
     } else {
         $time = Nette\DateTime::from($time)->format('U') - time();
         return $this->setOptions(array('gc_maxlifetime' => $time, 'cookie_lifetime' => $time));
     }
 }
Exemplo n.º 28
0
 /**
  * Sets DatePicker value.
  *
  * @author   Jan Tvrdík
  * @param    DateTime|int|string
  * @return   self
  */
 public function setValue($value)
 {
     if ($value instanceof DateTime) {
     } elseif (is_int($value)) {
         // timestamp
     } elseif (empty($value)) {
         $rawValue = $value;
         $value = NULL;
     } elseif (is_string($value)) {
         $rawValue = $value;
         if (preg_match('#^(?P<hh>\\d{1,2})[:](?P<mm>\\d{1,2})([:](?P<ss>\\d{2})?)?$#', $value, $matches)) {
             $hh = $matches['hh'];
             $mm = $matches['mm'];
             $ss = isset($matches['ss']) ? $matches['ss'] : '00';
             //				if (checkdate($mm, $dd, $yyyy)) {
             $value = "{$hh}:{$mm}:{$ss}";
             //				} else {
             //					$value = NULL;
             //				}
         }
     } else {
         throw new \InvalidArgumentException();
     }
     if ($value !== NULL) {
         // DateTime constructor throws Exception when invalid input given
         try {
             $value = Nette\DateTime::from($value);
             // clone DateTime when given
         } catch (\Exception $e) {
             $value = NULL;
         }
     }
     if (!isset($rawValue) && isset($value)) {
         $rawValue = $value->format(self::W3C_DATE_FORMAT);
     }
     $this->value = $value;
     $this->rawValue = $rawValue;
     return $this;
 }
Exemplo n.º 29
0
 /**
  * Enables log out after inactivity.
  * @param  string|int|DateTime number of seconds or timestamp
  * @param  bool  log out when the browser is closed?
  * @param  bool  clear the identity from persistent storage?
  * @return User  provides a fluent interface
  */
 public function setExpiration($time, $whenBrowserIsClosed = TRUE, $clearIdentity = FALSE)
 {
     $session = $this->getSessionSection(TRUE);
     if ($time) {
         $time = Nette\DateTime::from($time)->format('U');
         $session->expireTime = $time;
         $session->expireDelta = $time - time();
     } else {
         unset($session->expireTime, $session->expireDelta);
     }
     $session->expireIdentity = (bool) $clearIdentity;
     $session->expireBrowser = (bool) $whenBrowserIsClosed;
     $session->browserCheck = TRUE;
     $session->setExpiration(0, 'browserCheck');
     return $this;
 }
Exemplo n.º 30
0
 /**
  * Parse column
  * @param mixed $value
  * @param mixed $rowData
  * @return mixed|string
  */
 public function render($value, $rowData)
 {
     $value = parent::render($value, $rowData);
     $value = \Nette\DateTime::from($value);
     return $value->format($this->format);
 }