PHP Carbon 中的 ceilMinute 和 ceilMinutes 有什么区别?
What is the difference between ceilMinute and ceilMinutes in PHP Carbon?
在 Laravel 8 附带的 Carbon.php 源文件中显示
* @method $this ceilMinute(float $precision = 1) Ceil the current instance minute with given precision.
* @method $this ceilMinutes(float $precision = 1) Ceil the current instance minute with given precision.
基本测试显示给定输入“2021-11-26 11:25:10.000000”,两个函数都将其四舍五入为“2021-11-26 11:26:00.000000”.
我想知道这两个函数有什么区别吗?
如有任何帮助,我们将不胜感激。
简短回答:它们 100% 等效。
Carbon 实现几乎所有使用 magic methods. The implementation of __call()
basically strips trailing s
:
/**
* Dynamically handle calls to the class.
*
* @param string $method magic method name called
* @param array $parameters parameters list
*
* @throws UnknownMethodException|BadMethodCallException|ReflectionException|Throwable
*
* @return mixed
*/
public function __call($method, $parameters)
{
// [...]
$unit = rtrim($method, 's');
... 并将其用于 fetch a value from the units list:
if (\in_array($unit, static::$units)) {
return $this->setUnit($unit, ...$parameters);
}
protected static $units = [
// @call setUnit
// @call addUnit
'year',
// @call setUnit
// @call addUnit
'month',
// @call setUnit
// @call addUnit
'day',
// @call setUnit
// @call addUnit
'hour',
// @call setUnit
// @call addUnit
'minute',
// @call setUnit
// @call addUnit
'second',
// @call setUnit
// @call addUnit
'milli',
// @call setUnit
// @call addUnit
'millisecond',
// @call setUnit
// @call addUnit
'micro',
// @call setUnit
// @call addUnit
'microsecond',
];
在 Laravel 8 附带的 Carbon.php 源文件中显示
* @method $this ceilMinute(float $precision = 1) Ceil the current instance minute with given precision.
* @method $this ceilMinutes(float $precision = 1) Ceil the current instance minute with given precision.
基本测试显示给定输入“2021-11-26 11:25:10.000000”,两个函数都将其四舍五入为“2021-11-26 11:26:00.000000”.
我想知道这两个函数有什么区别吗?
如有任何帮助,我们将不胜感激。
简短回答:它们 100% 等效。
Carbon 实现几乎所有使用 magic methods. The implementation of __call()
basically strips trailing s
:
/**
* Dynamically handle calls to the class.
*
* @param string $method magic method name called
* @param array $parameters parameters list
*
* @throws UnknownMethodException|BadMethodCallException|ReflectionException|Throwable
*
* @return mixed
*/
public function __call($method, $parameters)
{
// [...]
$unit = rtrim($method, 's');
... 并将其用于 fetch a value from the units list:
if (\in_array($unit, static::$units)) {
return $this->setUnit($unit, ...$parameters);
}
protected static $units = [
// @call setUnit
// @call addUnit
'year',
// @call setUnit
// @call addUnit
'month',
// @call setUnit
// @call addUnit
'day',
// @call setUnit
// @call addUnit
'hour',
// @call setUnit
// @call addUnit
'minute',
// @call setUnit
// @call addUnit
'second',
// @call setUnit
// @call addUnit
'milli',
// @call setUnit
// @call addUnit
'millisecond',
// @call setUnit
// @call addUnit
'micro',
// @call setUnit
// @call addUnit
'microsecond',
];