Aggiornato Composer
This commit is contained in:
@@ -16,6 +16,7 @@ use Carbon\CarbonImmutable;
|
||||
use Carbon\CarbonInterface;
|
||||
use Carbon\CarbonInterval;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Carbon\CarbonPeriodImmutable;
|
||||
use Carbon\Exceptions\UnitException;
|
||||
use Closure;
|
||||
use DateTime;
|
||||
@@ -34,39 +35,7 @@ use ReturnTypeWillChange;
|
||||
*/
|
||||
trait Converter
|
||||
{
|
||||
/**
|
||||
* Format to use for __toString method when type juggling occurs.
|
||||
*
|
||||
* @var string|Closure|null
|
||||
*/
|
||||
protected static $toStringFormat;
|
||||
|
||||
/**
|
||||
* Reset the format used to the default when type juggling a Carbon instance to a string
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function resetToStringFormat()
|
||||
{
|
||||
static::setToStringFormat(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
|
||||
* You should rather let Carbon object being casted to string with DEFAULT_TO_STRING_FORMAT, and
|
||||
* use other method or custom format passed to format() method if you need to dump an other string
|
||||
* format.
|
||||
*
|
||||
* Set the default format used when type juggling a Carbon instance to a string
|
||||
*
|
||||
* @param string|Closure|null $format
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setToStringFormat($format)
|
||||
{
|
||||
static::$toStringFormat = $format;
|
||||
}
|
||||
use ToStringFormat;
|
||||
|
||||
/**
|
||||
* Returns the formatted date string on success or FALSE on failure.
|
||||
@@ -110,7 +79,7 @@ trait Converter
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* echo Carbon::now(); // Carbon instances can be casted to string
|
||||
* echo Carbon::now(); // Carbon instances can be cast to string
|
||||
* ```
|
||||
*
|
||||
* @return string
|
||||
@@ -158,6 +127,21 @@ trait Converter
|
||||
return $this->rawFormat('M j, Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the instance with the day, and a readable date
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* echo Carbon::now()->toFormattedDayDateString();
|
||||
* ```
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toFormattedDayDateString(): string
|
||||
{
|
||||
return $this->rawFormat('D, M j, Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the instance as time
|
||||
*
|
||||
@@ -622,16 +606,18 @@ trait Converter
|
||||
$interval = CarbonInterval::make("$interval ".static::pluralUnit($unit));
|
||||
}
|
||||
|
||||
$period = (new CarbonPeriod())->setDateClass(static::class)->setStartDate($this);
|
||||
$period = ($this->isMutable() ? new CarbonPeriod() : new CarbonPeriodImmutable())
|
||||
->setDateClass(static::class)
|
||||
->setStartDate($this);
|
||||
|
||||
if ($interval) {
|
||||
$period->setDateInterval($interval);
|
||||
$period = $period->setDateInterval($interval);
|
||||
}
|
||||
|
||||
if (\is_int($end) || \is_string($end) && ctype_digit($end)) {
|
||||
$period->setRecurrences($end);
|
||||
if (\is_int($end) || (\is_string($end) && ctype_digit($end))) {
|
||||
$period = $period->setRecurrences($end);
|
||||
} elseif ($end) {
|
||||
$period->setEndDate($end);
|
||||
$period = $period->setEndDate($end);
|
||||
}
|
||||
|
||||
return $period;
|
||||
|
||||
Reference in New Issue
Block a user