code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.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 toString()
{
if ($this->hidden) {
return '';
}
return trim($this->getName() .
(!empty($this->version) && !$this->version->hidden ? ' ' . $this->getVersion() : '')) .
(!empty($this->edition) ? ' ' . $this->edition : '');
} | Get the name and version in a human readable format
@return string | toString | php | WhichBrowser/Parser-PHP | src/Model/Os.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Os.php | MIT |
public function toArray()
{
$result = [];
if (!empty($this->name)) {
$result['name'] = $this->name;
}
if (!empty($this->family)) {
$result['family'] = $this->family->toArray();
}
if (!empty($this->alias)) {
$result['alias'] = $this->alias;
}
if (!empty($this->edition)) {
$result['edition'] = $this->edition;
}
if (!empty($this->version)) {
$result['version'] = $this->version->toArray();
}
if (isset($result['version']) && empty($result['version'])) {
unset($result['version']);
}
return $result;
} | Get an array of all defined properties
@internal
@return array | toArray | php | WhichBrowser/Parser-PHP | src/Model/Os.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Os.php | MIT |
public function toArray()
{
$result = [];
if (!empty($this->name) && empty($this->version)) {
return $this->name;
}
if (!empty($this->name)) {
$result['name'] = $this->name;
}
if (!empty($this->version)) {
$result['version'] = $this->version->toArray();
}
return $result;
} | Get an array of all defined properties
@internal
@return array | toArray | php | WhichBrowser/Parser-PHP | src/Model/Using.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Using.php | MIT |
public function is()
{
$valid = false;
$arguments = func_get_args();
if (count($arguments)) {
$operator = '=';
$compare = null;
if (count($arguments) == 1) {
$compare = $arguments[0];
}
if (count($arguments) >= 2) {
$operator = $arguments[0];
$compare = $arguments[1];
}
if (!is_null($compare)) {
$min = min(substr_count($this->value, '.'), substr_count($compare, '.')) + 1;
$v1 = $this->toValue($this->value, $min);
$v2 = $this->toValue($compare, $min);
switch ($operator) {
case '<':
$valid = $v1 < $v2;
break;
case '<=':
$valid = $v1 <= $v2;
break;
case '=':
$valid = $v1 == $v2;
break;
case '>':
$valid = $v1 > $v2;
break;
case '>=':
$valid = $v1 >= $v2;
break;
}
}
}
return $valid;
} | Determine if the version is lower, equal or higher than the specified value
@param string The operator, must be <, <=, =, >= or >
@param mixed The value, can be an integer, float or string with a version number
@return boolean | is | php | WhichBrowser/Parser-PHP | src/Model/Version.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Version.php | MIT |
public function getParts()
{
$parts = !is_null($this->value) ? explode('.', $this->value) : [];
return (object) [
'major' => !empty($parts[0]) ? intval($parts[0]) : 0,
'minor' => !empty($parts[1]) ? intval($parts[1]) : 0,
'patch' => !empty($parts[2]) ? intval($parts[2]) : 0,
];
} | Return an object with each part of the version number
@return object | getParts | php | WhichBrowser/Parser-PHP | src/Model/Version.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Version.php | MIT |
public function getMajor()
{
return $this->getParts()->major;
} | Return the major version as an integer
@return integer | getMajor | php | WhichBrowser/Parser-PHP | src/Model/Version.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Version.php | MIT |
public function getMinor()
{
return $this->getParts()->minor;
} | Return the minor version as an integer
@return integer | getMinor | php | WhichBrowser/Parser-PHP | src/Model/Version.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Version.php | MIT |
public function getPatch()
{
return $this->getParts()->patch;
} | Return the patch number as an integer
@return integer | getPatch | php | WhichBrowser/Parser-PHP | src/Model/Version.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Version.php | MIT |
private function toValue($value = null, $count = null)
{
if (is_null($value)) {
$value = $this->value;
}
$parts = explode('.', $value);
if (!is_null($count)) {
$parts = array_slice($parts, 0, $count);
}
$result = $parts[0];
if (count($parts) > 1) {
$result .= '.';
$count = count($parts);
for ($p = 1; $p < $count; $p++) {
$result .= substr('0000' . $parts[$p], -4);
}
}
return floatval($result);
} | Convert a version string seperated by dots into a float that can be compared
@internal
@param string Version string, with elements seperated by a dot
@param int The maximum precision
@return float | toValue | php | WhichBrowser/Parser-PHP | src/Model/Version.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Version.php | MIT |
public function toFloat()
{
return floatval($this->value);
} | Return the version as a float
@return float | toFloat | php | WhichBrowser/Parser-PHP | src/Model/Version.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Version.php | MIT |
public function toNumber()
{
return intval($this->value);
} | Return the version as an integer
@return int | toNumber | php | WhichBrowser/Parser-PHP | src/Model/Version.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Version.php | MIT |
public function toString()
{
if (!empty($this->alias)) {
return $this->alias;
}
$version = '';
if (!empty($this->nickname)) {
$version .= $this->nickname . ' ';
}
if (!empty($this->value)) {
if (preg_match("/([0-9]+)(?:\.([0-9]+))?(?:\.([0-9]+))?(?:\.([0-9]+))?(?:([ab])([0-9]+))?/", $this->value, $match)) {
$v = [ $match[1] ];
if (array_key_exists(2, $match) && strlen($match[2])) {
$v[] = $match[2];
}
if (array_key_exists(3, $match) && strlen($match[3])) {
$v[] = $match[3];
}
if (array_key_exists(4, $match) && strlen($match[4])) {
$v[] = $match[4];
}
if (!empty($this->details)) {
if ($this->details < 0) {
array_splice($v, $this->details, 0 - $this->details);
}
if ($this->details > 0) {
array_splice($v, $this->details, count($v) - $this->details);
}
}
if (isset($this->builds) && !$this->builds) {
$count = count($v);
for ($i = 0; $i < $count; $i++) {
if ($v[$i] > 999) {
array_splice($v, $i, 1);
}
}
}
$version .= implode('.', $v);
if (array_key_exists(5, $match) && strlen($match[5])) {
$version .= $match[5] . (!empty($match[6]) ? $match[6] : '');
}
}
}
return $version;
} | Return the version as a human readable string
@return string | toString | php | WhichBrowser/Parser-PHP | src/Model/Version.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Version.php | MIT |
public function toArray()
{
$result = [];
if (!empty($this->value)) {
if (!empty($this->details)) {
$parts = explode('.', $this->value);
$result['value'] = join('.', array_slice($parts, 0, $this->details));
} else {
$result['value'] = $this->value;
}
}
if (!empty($this->alias)) {
$result['alias'] = $this->alias;
}
if (!empty($this->nickname)) {
$result['nickname'] = $this->nickname;
}
if (isset($result['value']) && !isset($result['alias']) && !isset($result['nickname'])) {
return $result['value'];
}
return $result;
} | Get an array of all defined properties
@internal
@return array | toArray | php | WhichBrowser/Parser-PHP | src/Model/Version.php | https://github.com/WhichBrowser/Parser-PHP/blob/master/src/Model/Version.php | MIT |
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() . ' })';
} elseif ($key == 'family') {
$line .= 'new Family({ ' . $value->toJavaScript() . ' })';
} elseif ($key == 'using') {
$line .= 'new Using({ ' . $value->toJavaScript() . ' })';
} else {
switch (gettype($value)) {
case 'boolean':
$line .= $value ? 'true' : 'false';
break;
case 'string':
$line .= '"' . addslashes($value) . '"';
break;
case 'integer':
$line .= $value;
break;
}
}
$lines[] = $line;
}
}
return implode(", ", $lines);
} | 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 reset($properties = null)
{
unset($this->name);
unset($this->alias);
unset($this->version);
if (is_array($properties)) {
$this->set($properties);
}
} | Set the properties to the default values
@param array|null $properties An optional array of properties to set after setting it to the default values
@internal | reset | 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 identifyVersion($pattern, $subject, $defaults = [])
{
if (preg_match($pattern, $subject, $match)) {
$version = $match[1];
if (isset($defaults['type'])) {
switch ($defaults['type']) {
case 'underscore':
$version = str_replace('_', '.', $version);
break;
case 'legacy':
$version = preg_replace("/([0-9])([0-9])/", '$1.$2', $version);
break;
}
}
$this->version = new Version(array_merge($defaults, [ 'value' => $version ]));
}
} | 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 the value
@return string | 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 getName()
{
return !empty($this->alias) ? $this->alias : (!empty($this->name) ? $this->name : '');
} | Get the name in a human readable format
@return string | getName | 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 toString()
{
return trim($this->getName() . ' ' . (!empty($this->version) && !$this->version->hidden ? $this->getVersion() : ''));
} | Get the name and version in a human readable format
@return string | toString | 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) $attributes as $attribute) {
$this->owner->$attribute = $this->$method($this->owner->$attribute, $event->name);
}
}
}
}
} | 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_aes_key
], $config);
parent::__construct($config);
} | @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,
'dataProvider' => $dataProvider,
]);
} | 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 NotFoundHttpException('The requested page does not exist.');
}
} | 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 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 Media 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/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()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'wid' => $this->wid,
'status' => $this->status,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'open_id', $this->open_id]);
return $dataProvider;
} | 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 |
public function search($params)
{
$query = Media::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'material' => $this->material,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'mediaId', $this->mediaId])
->andFilterWhere(['like', 'post', $this->post])
->andFilterWhere(['like', 'result', $this->result])
->andFilterWhere(['like', 'type', $this->type]);
return $dataProvider;
} | Creates data provider instance with search query applied
@param array $params
@return ActiveDataProvider | search | php | callmez/yii2-wechat | models/MediaSearch.php | https://github.com/callmez/yii2-wechat/blob/master/models/MediaSearch.php | MIT |
public function search($params)
{
$query = MessageHistory::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'wid' => $this->wid,
'rid' => $this->rid,
'kid' => $this->kid,
'created_at' => $this->created_at,
]);
$query->andFilterWhere(['like', 'from', $this->from])
->andFilterWhere(['like', 'to', $this->to])
->andFilterWhere(['like', 'module', $this->module])
->andFilterWhere(['like', 'message', $this->message])
->andFilterWhere(['like', 'type', $this->type]);
return $dataProvider;
} | Creates data provider instance with search query applied
@param array $params
@return ActiveDataProvider | search | php | callmez/yii2-wechat | models/MessageHistorySearch.php | https://github.com/callmez/yii2-wechat/blob/master/models/MessageHistorySearch.php | MIT |
public function search($params)
{
$query = ReplyRule::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'wid' => $this->wid,
'status' => $this->status,
'priority' => $this->priority,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'mid', $this->mid]);
return $dataProvider;
} | Creates data provider instance with search query applied
@param array $params
@return ActiveDataProvider | search | php | callmez/yii2-wechat | models/ReplyRuleSearch.php | https://github.com/callmez/yii2-wechat/blob/master/models/ReplyRuleSearch.php | MIT |
public function search($params)
{
$query = Wechat::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'type' => $this->type,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'token', $this->token])
->andFilterWhere(['like', 'access_token', $this->access_token])
->andFilterWhere(['like', 'account', $this->account])
->andFilterWhere(['like', 'original', $this->original])
->andFilterWhere(['like', 'key', $this->key])
->andFilterWhere(['like', 'secret', $this->secret])
->andFilterWhere(['like', 'encoding_aes_key', $this->encoding_aes_key])
->andFilterWhere(['like', 'avatar', $this->avatar])
->andFilterWhere(['like', 'qrcode', $this->qrcode])
->andFilterWhere(['like', 'address', $this->address])
->andFilterWhere(['like', 'description', $this->description])
->andFilterWhere(['like', 'username', $this->username])
->andFilterWhere(['like', 'password', $this->password]);
return $dataProvider;
} | Creates data provider instance with search query applied
@param array $params
@return ActiveDataProvider | search | php | callmez/yii2-wechat | models/WechatSearch.php | https://github.com/callmez/yii2-wechat/blob/master/models/WechatSearch.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->registerJs($js);
} | 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;
}
if ($timezone !== null) {
$timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
}
if (is_object($time)) {
if ($time instanceof DateTimeInterface) {
$timezone = $time->getTimezone();
}
$time = $time->format('Y-m-d H:i:s.u');
}
$testNow = static::getTestNow();
if ($testNow === null) {
parent::__construct($time ?? 'now', $timezone);
return;
}
$relative = static::hasRelativeKeywords($time);
if ($time && $time !== 'now' && !$relative) {
parent::__construct($time, $timezone);
return;
}
$testNow = clone $testNow;
$relativeTime = self::isTimeExpression($time);
if (!$relativeTime && $timezone !== $testNow->getTimezone()) {
$testNow = $testNow->setTimezone($timezone ?? date_default_timezone_get());
}
if ($relative) {
$testNow = $testNow->modify($time ?? 'now');
}
parent::__construct($testNow->format('Y-m-d H:i:s.u'), $timezone);
} | 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 \DateTimeZone|string|null $timezone The timezone for the instance | __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(null)
- When the string "now" is passed to the constructor or parse(), ex. new Chronos('now')
- When a string containing the desired time is passed to Chronos::parse()
Note the timezone parameter was left out of the examples above and
has no affect as the mock value will be returned regardless of its value.
To clear the test instance call this method using the default
parameter of null.
@param \Cake\Chronos\Chronos|string|null $testNow The instance to use for all future instances.
@return void | 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::$relativePattern, $time) > 0;
}
return false;
} | 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::$diffFormatter;
}
return static::$diffFormatter = $formatter;
} | 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 $time The strtotime compatible string to parse
@param \DateTimeZone|string|null $timezone The DateTimeZone object or timezone name.
@return static | 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::now();
$year = $year ?? (int)$now->format('Y');
$month = $month ?? $now->format('m');
$day = $day ?? $now->format('d');
if ($hour === null) {
$hour = $now->format('H');
$minute = $minute ?? $now->format('i');
$second = $second ?? $now->format('s');
$microsecond = $microsecond ?? $now->format('u');
} else {
$minute = $minute ?? 0;
$second = $second ?? 0;
$microsecond = $microsecond ?? 0;
}
$instance = static::createFromFormat(
'Y-m-d H:i:s.u',
sprintf('%s-%s-%s %s:%02s:%02s.%06s', 0, $month, $day, $hour, $minute, $second, $microsecond),
$timezone,
);
return $instance->addYears($year);
} | 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 for $minute, $second
and $microsecond will be 0.
@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 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 instance with.
@param \DateTimeZone|string|null $timezone The DateTimeZone object or timezone name the new instance should use.
@return static | 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 timezone name the new instance should use.
@return static | 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, $timezone);
} | 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 instance with.
@param \DateTimeZone|string|null $timezone The DateTimeZone object or timezone name the new instance should use.
@return static | 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);
} else {
$dateTime = parent::createFromFormat($format, $time);
}
static::$lastErrors = DateTimeImmutable::getLastErrors();
if (!$dateTime) {
$message = static::$lastErrors ? implode(PHP_EOL, static::$lastErrors['errors']) : 'Unknown error';
throw new InvalidArgumentException($message);
}
return $dateTime;
} | 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 \InvalidArgumentException | 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_numeric($values['year']) &&
is_numeric($values['month']) &&
is_numeric($values['day'])
)
) {
$formatted .= sprintf('%04d-%02d-%02d ', $values['year'], $values['month'], $values['day']);
}
if (isset($values['meridian']) && (int)$values['hour'] === 12) {
$values['hour'] = 0;
}
if (isset($values['meridian'])) {
$values['hour'] = strtolower((string)$values['meridian']) === 'am' ? (int)$values['hour'] : (int)$values['hour'] + 12;
}
$formatted .= sprintf(
'%02d:%02d:%02d.%06d',
$values['hour'],
$values['minute'],
$values['second'],
$values['microsecond'],
);
assert(!is_int($values['timezone']), 'Timezone cannot be of type `int`');
return static::parse($formatted, $values['timezone']);
} | 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
- meridian ('am' or 'pm')
- timezone
@param array<int|string> $values Array of date and time values.
@return static | 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 DateTimeZone($object);
} | 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';
$rollover = static::rolloverTime($microseconds, 1_000_000);
$seconds = $seconds === null ? $rollover : $seconds + (int)$rollover;
$rollover = static::rolloverTime($seconds, 60);
$minutes = $minutes === null ? $rollover : $minutes + (int)$rollover;
$rollover = static::rolloverTime($minutes, 60);
$hours = $hours === null ? $rollover : $hours + (int)$rollover;
$rollover = static::rolloverTime($hours, 24);
$days = $days === null ? $rollover : $days + (int)$rollover;
if ($years) {
$spec .= $years . 'Y';
}
if ($months) {
$spec .= $months . 'M';
}
if ($weeks) {
$spec .= $weeks . 'W';
}
if ($days) {
$spec .= $days . 'D';
}
if ($hours || $minutes || $seconds) {
$spec .= 'T';
if ($hours) {
$spec .= $hours . 'H';
}
if ($minutes) {
$spec .= $minutes . 'M';
}
if ($seconds) {
$spec .= $seconds . 'S';
}
}
if ($microseconds && $spec === 'P') {
$spec .= 'T0S';
}
$instance = new DateInterval($spec);
if ($microseconds) {
$instance->f = $microseconds / 1000000;
}
return $instance;
} | 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 $seconds The seconds to use.
@param int|null $microseconds The microseconds to use.
@return \DateInterval | 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
(new Chronos('2012-02-29'))->addYears(1); // Results in 2013-02-28
```
@param int $value The number of years to add.
@return static | 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 $value The number of years to add.
@return static | 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(1); // Results in 2015-02-03
(new Chronos('2015-01-31'))->addMonths(1); // Results in 2015-02-28
```
@param int $value The number of months to add.
@return static | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.