code
stringlengths
31
707k
docstring
stringlengths
23
14.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function __construct($defaults = null) { if (is_array($defaults)) { $this->set($defaults); } }
Set the properties of the object the the values specified in the array @param array|null An array, the key of an element determines the name of the property
__construct
php
WhichBrowser/Parser-PHP
src/Model/Primitive/Base.php
https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Primitive/Base.php
MIT
public function set($properties) { foreach ($properties as $k => $v) { $this->{$k} = $v; } }
Set the properties of the object the the values specified in the array @param array $properties An array, the key of an element determines the name of the property @internal
set
php
WhichBrowser/Parser-PHP
src/Model/Primitive/Base.php
https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Primitive/Base.php
MIT
public function toJavaScript() { $lines = []; foreach (get_object_vars($this) as $key => $value) { if (!is_null($value)) { $line = $key . ": "; if ($key == 'version') { $line .= 'new Version({ ' . $value->toJavaScript() . ' })'; ...
Get a string containing a JavaScript representation of the object @internal @return string
toJavaScript
php
WhichBrowser/Parser-PHP
src/Model/Primitive/Base.php
https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Primitive/Base.php
MIT
public function identifyVersion($pattern, $subject, $defaults = []) { if (preg_match($pattern, $subject, $match)) { $version = $match[1]; if (isset($defaults['type'])) { switch ($defaults['type']) { case 'underscore': $vers...
Identify the version based on a pattern @param string $pattern The regular expression that defines the group that matches the version string @param string $subject The string the regular expression is matched with @param array|null $defaults An optional array of properties to set together with th...
identifyVersion
php
WhichBrowser/Parser-PHP
src/Model/Primitive/NameVersion.php
https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Primitive/NameVersion.php
MIT
public function getVersion() { return !empty($this->version) ? $this->version->toString() : ''; }
Get the version in a human readable format @return string
getVersion
php
WhichBrowser/Parser-PHP
src/Model/Primitive/NameVersion.php
https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Primitive/NameVersion.php
MIT
public function invokeMethod(&$object, $methodName, array $parameters = array()) { $reflection = new \ReflectionClass(get_class($object)); $method = $reflection->getMethod($methodName); $method->setAccessible(true); return $method->invokeArgs($object, $parameters); }
Call protected/private method of a class. @param object &$object Instantiated object that we will run method on. @param string $methodName Method name to call @param array $parameters Array of parameters to pass into method. @return mixed Method return.
invokeMethod
php
WhichBrowser/Parser-PHP
tests/unit/Model/VersionTest.php
https://github.com/WhichBrowser/Parser-PHP/blob/master/tests/unit/Model/VersionTest.php
MIT
public function evaluateAttributes($event) { if (in_array($event->name, $this->events)) { foreach ($this->attributes as $type => $attributes) { $method = 'get' . $type . 'value'; if (method_exists($this, $method)) { foreach ( (array) $attribute...
Evaluates the attribute value and assigns it to the current attributes. @param Event $event
evaluateAttributes
php
callmez/yii2-wechat
behaviors/ArrayBehavior.php
https://github.com/callmez/yii2-wechat/blob/master/behaviors/ArrayBehavior.php
MIT
public function __construct(Wechat $wechat, $config = []) { $this->model = $wechat; $config = array_merge([ 'appId' => $this->model->key, 'appSecret' => $this->model->secret, 'token' => $this->model->token, 'encodingAesKey' => $this->model->encoding_ae...
@param Wechat $wechat @param array $config
__construct
php
callmez/yii2-wechat
components/MpWechat.php
https://github.com/callmez/yii2-wechat/blob/master/components/MpWechat.php
MIT
public function __construct($message, $wechat, $config = []) { $this->message = $message; $this->wechat = $wechat; parent::__construct($config); }
@param array $message @param $wechat @param array $config
__construct
php
callmez/yii2-wechat
components/ProcessEvent.php
https://github.com/callmez/yii2-wechat/blob/master/components/ProcessEvent.php
MIT
public function actionIndex() { $searchModel = new FansSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams, true); $dataProvider->query->andWhere(['wid' => $this->getWechat()->id]); return $this->render('index', [ 'searchModel' => $searchModel,...
Lists all Fans models. @return mixed
actionIndex
php
callmez/yii2-wechat
controllers/FansController.php
https://github.com/callmez/yii2-wechat/blob/master/controllers/FansController.php
MIT
public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', [ 'model' => $model, ...
Updates an existing Fans model. If update is successful, the browser will be redirected to the 'view' page. @param integer $id @return mixed
actionUpdate
php
callmez/yii2-wechat
controllers/FansController.php
https://github.com/callmez/yii2-wechat/blob/master/controllers/FansController.php
MIT
protected function findModel($id) { $query = Fans::find() ->andWhere([ 'id' => $id, 'wid' => $this->getWechat()->id ]); if (($model = $query->one()) !== null) { return $model; } else { throw new NotFoundHttpExcep...
Finds the Fans model based on its primary key value. If the model is not found, a 404 HTTP exception will be thrown. @param integer $id @return Fans the loaded model @throws NotFoundHttpException if the model cannot be found
findModel
php
callmez/yii2-wechat
controllers/FansController.php
https://github.com/callmez/yii2-wechat/blob/master/controllers/FansController.php
MIT
public function actionIndex() { $searchModel = new MediaSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
Lists all Media models. @return mixed
actionIndex
php
callmez/yii2-wechat
controllers/MediaController.php
https://github.com/callmez/yii2-wechat/blob/master/controllers/MediaController.php
MIT
public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), ]); }
Displays a single Media model. @param integer $id @return mixed
actionView
php
callmez/yii2-wechat
controllers/MediaController.php
https://github.com/callmez/yii2-wechat/blob/master/controllers/MediaController.php
MIT
public function actionDelete($id) { $this->findModel($id)->delete(); return $this->redirect(['index']); }
Deletes an existing Media model. If deletion is successful, the browser will be redirected to the 'index' page. @param integer $id @return mixed
actionDelete
php
callmez/yii2-wechat
controllers/MediaController.php
https://github.com/callmez/yii2-wechat/blob/master/controllers/MediaController.php
MIT
protected function findModel($id) { if (($model = Media::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
Finds the Media model based on its primary key value. If the model is not found, a 404 HTTP exception will be thrown. @param integer $id @return Media the loaded model @throws NotFoundHttpException if the model cannot be found
findModel
php
callmez/yii2-wechat
controllers/MediaController.php
https://github.com/callmez/yii2-wechat/blob/master/controllers/MediaController.php
MIT
public function actionDelete($id) { $model = $this->findModel($id); $mid = $model->mid; $model->delete(); return $this->redirect(['index', 'mid' => $mid]); }
Deletes an existing ReplyRule model. If deletion is successful, the browser will be redirected to the 'index' page. @param integer $id @return mixed
actionDelete
php
callmez/yii2-wechat
controllers/ReplyController.php
https://github.com/callmez/yii2-wechat/blob/master/controllers/ReplyController.php
MIT
protected function findModel($id) { if (($model = ReplyRule::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
Finds the ReplyRule model based on its primary key value. If the model is not found, a 404 HTTP exception will be thrown. @param integer $id @return ReplyRule the loaded model @throws NotFoundHttpException if the model cannot be found
findModel
php
callmez/yii2-wechat
controllers/ReplyController.php
https://github.com/callmez/yii2-wechat/blob/master/controllers/ReplyController.php
MIT
protected function findModel($id) { if (($model = WechatForm::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
Finds the Wechat model based on its primary key value. If the model is not found, a 404 HTTP exception will be thrown. @param integer $id @return Wechat the loaded model @throws NotFoundHttpException if the model cannot be found
findModel
php
callmez/yii2-wechat
controllers/WechatController.php
https://github.com/callmez/yii2-wechat/blob/master/controllers/WechatController.php
MIT
public function getModulePath() { return Yii::getAlias('@' . str_replace('\\', '/', substr($this->moduleClass, 0, strrpos($this->moduleClass, '\\')))); }
@return boolean the directory that contains the module class
getModulePath
php
callmez/yii2-wechat
generators/module/Generator.php
https://github.com/callmez/yii2-wechat/blob/master/generators/module/Generator.php
MIT
public function search($params, $user = false) { $query = Fans::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); if ($user) { $query->with('user'); } $this->load($params); if (!$this->validate()) { ...
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
search
php
callmez/yii2-wechat
models/FansSearch.php
https://github.com/callmez/yii2-wechat/blob/master/models/FansSearch.php
MIT
protected function registerPlugin($name) { $view = $this->getView(); BootstrapPluginAsset::register($view); $id = $this->options['id']; $options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions); $js = "jQuery('#$id').$name($options);"; $view-...
Registers a specific Bootstrap plugin and the related events @param string $name the name of the Bootstrap plugin
registerPlugin
php
callmez/yii2-wechat
widgets/CategoryMenu.php
https://github.com/callmez/yii2-wechat/blob/master/widgets/CategoryMenu.php
MIT
public function __construct( ChronosDate|ChronosTime|DateTimeInterface|string|int|null $time = 'now', DateTimeZone|string|null $timezone = null, ) { if (is_int($time) || (is_string($time) && ctype_digit($time))) { parent::__construct("@{$time}"); return; } ...
Create a new Chronos instance. Please see the testing aids section (specifically static::setTestNow()) for more on the possibility of this constructor returning a test instance. @param \Cake\Chronos\ChronosDate|\Cake\Chronos\ChronosTime|\DateTimeInterface|string|int|null $time Fixed or relative time @param \DateTimeZ...
__construct
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function setTestNow(Chronos|string|null $testNow = null): void { static::$testNow = is_string($testNow) ? static::parse($testNow) : $testNow; }
Set a Chronos instance (real or mock) to be returned when a "now" instance is created. The provided instance will be returned specifically under the following conditions: - A call to the static now() method, ex. Chronos::now() - When a null (or blank string) is passed to the constructor or parse(), ex. new Chronos...
setTestNow
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function getTestNow(): ?Chronos { return static::$testNow; }
Get the Chronos instance (real or mock) to be returned when a "now" instance is created. @return \Cake\Chronos\Chronos|null The current instance used for testing
getTestNow
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function hasTestNow(): bool { return static::$testNow !== null; }
Determine if there is a valid test instance set. A valid test instance is anything that is not null. @return bool True if there is a test instance, otherwise false
hasTestNow
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
private static function isTimeExpression(?string $time): bool { // Just a time if (is_string($time) && preg_match('/^[0-2]?[0-9]:[0-5][0-9](?::[0-5][0-9](?:\.[0-9]{1,6})?)?$/', $time)) { return true; } return false; }
Determine if there is just a time in the time string @param string|null $time The time string to check. @return bool true if there is a keyword, otherwise false
isTimeExpression
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function hasRelativeKeywords(?string $time): bool { if (self::isTimeExpression($time)) { return true; } // skip common format with a '-' in it if ($time && preg_match('/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/', $time) !== 1) { return preg_match(static::$...
Determine if there is a relative keyword in the time string, this is to create dates relative to now for test instances. e.g.: next tuesday @param string|null $time The time string to check. @return bool true if there is a keyword, otherwise false
hasRelativeKeywords
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function setWeekendDays(array $days): void { static::$weekendDays = $days; }
Set weekend days @param array $days Which days are 'weekends'. @return void
setWeekendDays
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function getWeekStartsAt(): int { return static::$weekStartsAt; }
Get the first day of week @return int
getWeekStartsAt
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function setWeekStartsAt(int $day): void { static::$weekStartsAt = $day; }
Set the first day of week @param int $day The day the week starts with. @return void
setWeekStartsAt
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function getWeekEndsAt(): int { return static::$weekEndsAt; }
Get the last day of week @return int
getWeekEndsAt
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function setWeekEndsAt(int $day): void { static::$weekEndsAt = $day; }
Set the last day of week @param int $day The day the week ends with. @return void
setWeekEndsAt
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function diffFormatter(?DifferenceFormatterInterface $formatter = null): DifferenceFormatterInterface { if ($formatter === null) { if (static::$diffFormatter === null) { static::$diffFormatter = new DifferenceFormatter(); } return static::$d...
Get the difference formatter instance or overwrite the current one. @param \Cake\Chronos\DifferenceFormatterInterface|null $formatter The formatter instance when setting. @return \Cake\Chronos\DifferenceFormatterInterface The formatter instance.
diffFormatter
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function instance(DateTimeInterface $other): static { return new static($other); }
Create an instance from a DateTimeInterface @param \DateTimeInterface $other The datetime instance to convert. @return static
instance
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function parse( ChronosDate|ChronosTime|DateTimeInterface|string|int|null $time = 'now', DateTimeZone|string|null $timezone = null, ): static { return new static($time, $timezone); }
Create an instance from a string. This is an alias for the constructor that allows better fluent syntax as it allows you to do Chronos::parse('Monday next week')->fn() rather than (new Chronos('Monday next week'))->fn() @param \Cake\Chronos\ChronosDate|\Cake\Chronos\ChronosTime|\DateTimeInterface|string|int|null $tim...
parse
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function now(DateTimeZone|string|null $timezone = null): static { return new static('now', $timezone); }
Get an instance for the current date and time @param \DateTimeZone|string|null $timezone The DateTimeZone object or timezone name. @return static
now
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function today(DateTimeZone|string|null $timezone = null): static { return new static('midnight', $timezone); }
Create an instance for today @param \DateTimeZone|string|null $timezone The timezone to use. @return static
today
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function tomorrow(DateTimeZone|string|null $timezone = null): static { return new static('tomorrow, midnight', $timezone); }
Create an instance for tomorrow @param \DateTimeZone|string|null $timezone The DateTimeZone object or timezone name the new instance should use. @return static
tomorrow
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function yesterday(DateTimeZone|string|null $timezone = null): static { return new static('yesterday, midnight', $timezone); }
Create an instance for yesterday @param \DateTimeZone|string|null $timezone The DateTimeZone object or timezone name the new instance should use. @return static
yesterday
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function maxValue(): static { return static::createFromTimestamp(PHP_INT_MAX); }
Create an instance for the greatest supported date. @return static
maxValue
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function minValue(): static { $max = PHP_INT_SIZE === 4 ? PHP_INT_MAX : PHP_INT_MAX / 10; return static::createFromTimestamp(~$max); }
Create an instance for the lowest supported date. @return static
minValue
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function create( ?int $year = null, ?int $month = null, ?int $day = null, ?int $hour = null, ?int $minute = null, ?int $second = null, ?int $microsecond = null, DateTimeZone|string|null $timezone = null, ): static { $now = static:...
Create an instance from a specific date and time. If any of $year, $month or $day are set to null their now() values will be used. If $hour is null it will be set to its now() value and the default values for $minute, $second and $microsecond will be their now() values. If $hour is not null then the default values fo...
create
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function createFromDate( ?int $year = null, ?int $month = null, ?int $day = null, DateTimeZone|string|null $timezone = null, ): static { return static::create($year, $month, $day, null, null, null, null, $timezone); }
Create an instance from just a date. The time portion is set to now. @param int|null $year The year to create an instance with. @param int|null $month The month to create an instance with. @param int|null $day The day to create an instance with. @param \DateTimeZone|string|null $timezone The DateTimeZone object or tim...
createFromDate
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function createFromTime( ?int $hour = null, ?int $minute = null, ?int $second = null, ?int $microsecond = null, DateTimeZone|string|null $timezone = null, ): static { return static::create(null, null, null, $hour, $minute, $second, $microsecond, $timezon...
Create an instance from just a time. The date portion is set to today. @param int|null $hour The hour to create an instance with. @param int|null $minute The minute to create an instance with. @param int|null $second The second to create an instance with. @param int|null $microsecond The microsecond to create an insta...
createFromTime
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function createFromFormat( string $format, string $time, DateTimeZone|string|null $timezone = null, ): static { if ($timezone !== null) { $dateTime = parent::createFromFormat($format, $time, $timezone ? static::safeCreateDateTimeZone($timezone) : null); ...
Create an instance from a specific format @param string $format The date() compatible format string. @param string $time The formatted date string to interpret. @param \DateTimeZone|string|null $timezone The DateTimeZone object or timezone name the new instance should use. @return static @throws \InvalidArgumentExcept...
createFromFormat
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function getLastErrors(): array|false { return static::$lastErrors; }
Returns parse warnings and errors from the last ``createFromFormat()`` call. Returns the same data as DateTimeImmutable::getLastErrors(). @return array|false
getLastErrors
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function createFromArray(array $values): static { $values += ['hour' => 0, 'minute' => 0, 'second' => 0, 'microsecond' => 0, 'timezone' => null]; $formatted = ''; if ( isset($values['year'], $values['month'], $values['day']) && ( is_nume...
Creates an instance from an array of date and time values. The 'year', 'month' and 'day' values must all be set for a date. The time values all default to 0. The 'timezone' value can be any format supported by `\DateTimeZone`. Allowed values: - year - month - day - hour - minute - second - microsecond - meri...
createFromArray
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function createFromTimestamp(float|int $timestamp, DateTimeZone|string|null $timezone = null): static { $instance = PHP_VERSION_ID >= 80400 ? parent::createFromTimestamp($timestamp) : new static('@' . $timestamp); return $timezone ? $instance->setTimezone($timezone) : $instance; }
Create an instance from a timestamp @param float|int $timestamp The timestamp to create an instance from. @param \DateTimeZone|string|null $timezone The DateTimeZone object or timezone name the new instance should use. @return static
createFromTimestamp
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
protected static function safeCreateDateTimeZone(DateTimeZone|string|null $object): DateTimeZone { if ($object === null) { return new DateTimeZone(date_default_timezone_get()); } if ($object instanceof DateTimeZone) { return $object; } return new Dat...
Creates a DateTimeZone from a string or a DateTimeZone @param \DateTimeZone|string|null $object The value to convert. @return \DateTimeZone
safeCreateDateTimeZone
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function createInterval( ?int $years = null, ?int $months = null, ?int $weeks = null, ?int $days = null, ?int $hours = null, ?int $minutes = null, ?int $seconds = null, ?int $microseconds = null, ): DateInterval { $spec = 'P'; ...
Create a new DateInterval instance from specified values. @param int|null $years The year to use. @param int|null $months The month to use. @param int|null $weeks The week to use. @param int|null $days The day to use. @param int|null $hours The hours to use. @param int|null $minutes The minutes to use. @param int|null...
createInterval
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
protected static function rolloverTime(?int &$value, int $max): ?int { if ($value === null || $value < $max) { return null; } $rollover = intdiv($value, $max); $value = $value % $max; return $rollover; }
Updates value to remaininger and returns rollover value for time unit or null if no rollover. @param int|null $value Time unit value @param int $max Time unit max value @return int|null
rolloverTime
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function setDateTime( int $year, int $month, int $day, int $hour, int $minute, int $second = 0, ): static { return $this->setDate($year, $month, $day)->setTime($hour, $minute, $second); }
Sets the date and time. @param int $year The year to set. @param int $month The month to set. @param int $day The day to set. @param int $hour The hour to set. @param int $minute The minute to set. @param int $second The second to set. @return static
setDateTime
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function setDate(int $year, int $month, int $day): static { return parent::setDate($year, $month, $day); }
Sets the date. @param int $year The year to set. @param int $month The month to set. @param int $day The day to set. @return static
setDate
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function setISODate(int $year, int $week, int $dayOfWeek = 1): static { return parent::setISODate($year, $week, $dayOfWeek); }
Sets the date according to the ISO 8601 standard @param int $year Year of the date. @param int $week Week of the date. @param int $dayOfWeek Offset from the first day of the week. @return static
setISODate
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function setTime(int $hours, int $minutes, int $seconds = 0, int $microseconds = 0): static { return parent::setTime($hours, $minutes, $seconds, $microseconds); }
Sets the time. @param int $hours Hours of the time @param int $minutes Minutes of the time @param int $seconds Seconds of the time @param int $microseconds Microseconds of the time @return static
setTime
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function modify(string $modifier): static { $new = parent::modify($modifier); if ($new === false) { throw new InvalidArgumentException(sprintf('Unable to modify date using `%s`', $modifier)); } return $new; }
Creates a new instance with date modified according to DateTimeImmutable::modifier(). @param string $modifier Date modifier @return static @throws \InvalidArgumentException @see https://www.php.net/manual/en/datetimeimmutable.modify.php
modify
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diff(DateTimeInterface $target, bool $absolute = false): DateInterval { return parent::diff($target, $absolute); }
Returns the difference between this instance and target. @param \DateTimeInterface $target Target instance @param bool $absolute Whether the interval is forced to be positive @return \DateInterval
diff
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function format(string $format): string { return parent::format($format); }
Returns formatted date string according to DateTimeImmutable::format(). @param string $format String format @return string
format
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function getOffset(): int { return parent::getOffset(); }
Returns the timezone offset. @return int
getOffset
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function setTimestamp(int $timestamp): static { return parent::setTimestamp($timestamp); }
Sets the date and time based on a Unix timestamp. @param int $timestamp Unix timestamp representing the date @return static
setTimestamp
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function getTimestamp(): int { return parent::getTimestamp(); }
Gets the Unix timestamp for this instance. @return int
getTimestamp
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function setTimezone(DateTimeZone|string $value): static { return parent::setTimezone(static::safeCreateDateTimeZone($value)); }
Set the instance's timezone from a string or object @param \DateTimeZone|string $value The DateTimeZone object or timezone name to use. @return static
setTimezone
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function getTimezone(): DateTimeZone { $tz = parent::getTimezone(); if ($tz === false) { throw new RuntimeException('Time zone could not be retrieved.'); } return $tz; }
Return time zone set for this instance. @return \DateTimeZone
getTimezone
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function setTimeFromTimeString(string $time): static { $time = explode(':', $time); $hour = $time[0]; $minute = $time[1] ?? 0; $second = $time[2] ?? 0; return $this->setTime((int)$hour, (int)$minute, (int)$second); }
Set the time by time string @param string $time Time as string. @return static
setTimeFromTimeString
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function timestamp(int $value): static { return $this->setTimestamp($value); }
Set the instance's timestamp @param int $value The timestamp value to set. @return static
timestamp
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function year(int $value): static { return $this->setDate($value, $this->month, $this->day); }
Set the instance's year @param int $value The year value. @return static
year
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function month(int $value): static { return $this->setDate($this->year, $value, $this->day); }
Set the instance's month @param int $value The month value. @return static
month
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function day(int $value): static { return $this->setDate($this->year, $this->month, $value); }
Set the instance's day @param int $value The day value. @return static
day
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function hour(int $value): static { return $this->setTime($value, $this->minute, $this->second); }
Set the instance's hour @param int $value The hour value. @return static
hour
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function minute(int $value): static { return $this->setTime($this->hour, $value, $this->second); }
Set the instance's minute @param int $value The minute value. @return static
minute
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function second(int $value): static { return $this->setTime($this->hour, $this->minute, $value); }
Set the instance's second @param int $value The seconds value. @return static
second
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function microsecond(int $value): static { return $this->setTime($this->hour, $this->minute, $this->second, $value); }
Set the instance's microsecond @param int $value The microsecond value. @return static
microsecond
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addYears(int $value): static { $month = $this->month; $date = $this->modify($value . ' years'); if ($date->month !== $month) { return $date->modify('last day of previous month'); } return $date; }
Add years to the instance. Positive $value travel forward while negative $value travel into the past. If the new ChronosDate does not exist, the last day of the month is used instead instead of overflowing into the next month. ### Example: ``` (new Chronos('2015-01-03'))->addYears(1); // Results in 2016-01-03 (ne...
addYears
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subYears(int $value): static { return $this->addYears(-$value); }
Remove years from the instance. Has the same behavior as `addYears()`. @param int $value The number of years to remove. @return static
subYears
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addYearsWithOverflow(int $value): static { return $this->modify($value . ' year'); }
Add years with overflowing to the instance. Positive $value travels forward while negative $value travels into the past. If the new ChronosDate does not exist, the days overflow into the next month. ### Example: ``` (new Chronos('2012-02-29'))->addYearsWithOverflow(1); // Results in 2013-03-01 ``` @param int $valu...
addYearsWithOverflow
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subYearsWithOverflow(int $value): static { return $this->addYearsWithOverflow(-1 * $value); }
Remove years with overflow from the instance Has the same behavior as `addYeasrWithOverflow()`. @param int $value The number of years to remove. @return static
subYearsWithOverflow
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addMonths(int $value): static { $day = $this->day; $date = $this->modify($value . ' months'); if ($date->day !== $day) { return $date->modify('last day of previous month'); } return $date; }
Add months to the instance. Positive $value travels forward while negative $value travels into the past. When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month. ### Example: ``` (new Chronos('2015-01-03')...
addMonths
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subMonths(int $value): static { return $this->addMonths(-$value); }
Remove months from the instance Has the same behavior as `addMonths()`. @param int $value The number of months to remove. @return static
subMonths
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addMonthsWithOverflow(int $value): static { return $this->modify($value . ' months'); }
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past. If the new ChronosDate does not exist, the days overflow into the next month. ### Example: ``` (new Chronos('2012-01-30'))->addMonthsWithOverflow(1); // Results in 2013-03-01 ``` @param int $va...
addMonthsWithOverflow
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subMonthsWithOverflow(int $value): static { return $this->addMonthsWithOverflow(-1 * $value); }
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past. If the new ChronosDate does not exist, the days overflow into the next month. ### Example: ``` (new Chronos('2012-01-30'))->addMonthsWithOverflow(1); // Results in 2013-03-01 ``` @param int $va...
subMonthsWithOverflow
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addDays(int $value): static { return $this->modify("$value days"); }
Add days to the instance. Positive $value travels forward while negative $value travels into the past. @param int $value The number of days to add. @return static
addDays
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subDays(int $value): static { return $this->addDays(-$value); }
Remove days from the instance @param int $value The number of days to remove. @return static
subDays
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addWeekdays(int $value): static { return $this->modify($value . ' weekdays, ' . $this->format('H:i:s')); }
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past. @param int $value The number of weekdays to add. @return static
addWeekdays
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subWeekdays(int $value): static { return $this->addWeekdays(-$value); }
Remove weekdays from the instance @param int $value The number of weekdays to remove. @return static
subWeekdays
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addWeeks(int $value): static { return $this->modify("$value week"); }
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past. @param int $value The number of weeks to add. @return static
addWeeks
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subWeeks(int $value): static { return $this->addWeeks(-$value); }
Remove weeks to the instance @param int $value The number of weeks to remove. @return static
subWeeks
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addHours(int $value): static { return $this->modify("$value hour"); }
Add hours to the instance. Positive $value travels forward while negative $value travels into the past. @param int $value The number of hours to add. @return static
addHours
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subHours(int $value): static { return $this->addHours(-$value); }
Remove hours from the instance @param int $value The number of hours to remove. @return static
subHours
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addMinutes(int $value): static { return $this->modify("$value minute"); }
Add minutes to the instance. Positive $value travels forward while negative $value travels into the past. @param int $value The number of minutes to add. @return static
addMinutes
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subMinutes(int $value): static { return $this->addMinutes(-$value); }
Remove minutes from the instance @param int $value The number of minutes to remove. @return static
subMinutes
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addSeconds(int $value): static { return $this->modify("$value second"); }
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past. @param int $value The number of seconds to add. @return static
addSeconds
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subSeconds(int $value): static { return $this->addSeconds(-$value); }
Remove seconds from the instance @param int $value The number of seconds to remove. @return static
subSeconds
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function startOfDay(): static { return $this->modify('midnight'); }
Sets the time to 00:00:00 @return static
startOfDay
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function endOfDay(bool $microseconds = false): static { if ($microseconds) { return $this->modify('23:59:59.999999'); } return $this->modify('23:59:59'); }
Sets the time to 23:59:59 or 23:59:59.999999 if `$microseconds` is true. @param bool $microseconds Whether to set microseconds @return static
endOfDay
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function startOfMonth(): static { return $this->modify('first day of this month midnight'); }
Sets the date to the first day of the month and the time to 00:00:00 @return static
startOfMonth
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function endOfMonth(): static { return $this->modify('last day of this month, 23:59:59'); }
Sets the date to end of the month and time to 23:59:59 @return static
endOfMonth
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function startOfYear(): static { return $this->modify('first day of january midnight'); }
Sets the date to the first day of the year and the time to 00:00:00 @return static
startOfYear
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function endOfYear(): static { return $this->modify('last day of december, 23:59:59'); }
Sets the date to end of the year and time to 23:59:59 @return static
endOfYear
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function startOfDecade(): static { $year = $this->year - $this->year % Chronos::YEARS_PER_DECADE; return $this->modify("first day of january $year, midnight"); }
Sets the date to the first day of the decade and the time to 00:00:00 @return static
startOfDecade
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT