-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.8] Upgrade Carbon to version 2 and allow CarbonImmutable #25310
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
|
||
namespace Illuminate\Auth\Passwords; | ||
|
||
use Carbon\Factory; | ||
use Illuminate\Support\Str; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Database\ConnectionInterface; | ||
use Illuminate\Contracts\Hashing\Hasher as HasherContract; | ||
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; | ||
|
@@ -107,7 +107,11 @@ protected function deleteExisting(CanResetPasswordContract $user) | |
*/ | ||
protected function getPayload($email, $token) | ||
{ | ||
return ['email' => $email, 'token' => $this->hasher->make($token), 'created_at' => new Carbon]; | ||
return [ | ||
'email' => $email, | ||
'token' => $this->hasher->make($token), | ||
'created_at' => app(Factory::class)->now(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just used to store "now" as |
||
]; | ||
} | ||
|
||
/** | ||
|
@@ -136,7 +140,7 @@ public function exists(CanResetPasswordContract $user, $token) | |
*/ | ||
protected function tokenExpired($createdAt) | ||
{ | ||
return Carbon::parse($createdAt)->addSeconds($this->expires)->isPast(); | ||
return app(Factory::class)->parse($createdAt)->addSeconds($this->expires)->isPast(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just to check if the token has expired. Why do we need to make it complicated? |
||
} | ||
|
||
/** | ||
|
@@ -157,7 +161,7 @@ public function delete(CanResetPasswordContract $user) | |
*/ | ||
public function deleteExpired() | ||
{ | ||
$expiredAt = Carbon::now()->subSeconds($this->expires); | ||
$expiredAt = app(Factory::class)->now()->subSeconds($this->expires); | ||
|
||
$this->getTable()->where('created_at', '<', $expiredAt)->delete(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Auth component doesn't load |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ | |
|
||
use Closure; | ||
use ArrayAccess; | ||
use Carbon\Factory; | ||
use DateTimeInterface; | ||
use BadMethodCallException; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Cache\Events\CacheHit; | ||
use Illuminate\Contracts\Cache\Store; | ||
use Illuminate\Cache\Events\KeyWritten; | ||
|
@@ -554,7 +554,8 @@ protected function getMinutes($duration) | |
$duration = $this->parseDateInterval($duration); | ||
|
||
if ($duration instanceof DateTimeInterface) { | ||
$duration = Carbon::now()->diffInSeconds(Carbon::createFromTimestamp($duration->getTimestamp()), false) / 60; | ||
$dateFactory = app(Factory::class); | ||
$duration = $dateFactory->now()->diffInSeconds($dateFactory->createFromTimestamp($duration->getTimestamp()), false) / 60; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cache component doesn't load |
||
} | ||
|
||
return (int) ($duration * 60) > 0 ? $duration : null; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,11 @@ | |
namespace Illuminate\Console\Scheduling; | ||
|
||
use Closure; | ||
use Carbon\Carbon; | ||
use Carbon\Factory; | ||
use Cron\CronExpression; | ||
use Carbon\CarbonImmutable; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Carbon; | ||
use GuzzleHttp\Client as HttpClient; | ||
use Illuminate\Contracts\Mail\Mailer; | ||
use Symfony\Component\Process\Process; | ||
|
@@ -295,7 +297,8 @@ public function runsInMaintenanceMode() | |
*/ | ||
protected function expressionPasses() | ||
{ | ||
$date = Carbon::now(); | ||
/** @var Carbon|CarbonImmutable $date */ | ||
$date = app(Factory::class)->now(); | ||
|
||
if ($this->timezone) { | ||
$date->setTimezone($this->timezone); | ||
|
@@ -687,11 +690,11 @@ public function getSummaryForDisplay() | |
* @param \DateTime|string $currentTime | ||
* @param int $nth | ||
* @param bool $allowCurrentDate | ||
* @return \Illuminate\Support\Carbon | ||
* @return \Carbon\Carbon | ||
*/ | ||
public function nextRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false) | ||
{ | ||
return Carbon::instance(CronExpression::factory( | ||
return app(Factory::class)->instance(CronExpression::factory( | ||
$this->getExpression() | ||
)->getNextRunDate($currentTime, $nth, $allowCurrentDate, $this->timezone)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Console component doesn't load |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,12 @@ | |
|
||
namespace Illuminate\Database\Eloquent\Concerns; | ||
|
||
use Carbon\Factory; | ||
use LogicException; | ||
use DateTimeInterface; | ||
use Carbon\CarbonInterface; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Support\Str; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Contracts\Support\Arrayable; | ||
use Illuminate\Database\Eloquent\Relations\Relation; | ||
use Illuminate\Support\Collection as BaseCollection; | ||
|
@@ -716,7 +717,7 @@ public function fromJson($value, $asObject = false) | |
* Return a timestamp as DateTime object with time set to 00:00:00. | ||
* | ||
* @param mixed $value | ||
* @return \Illuminate\Support\Carbon | ||
* @return \Carbon\Carbon | ||
*/ | ||
protected function asDate($value) | ||
{ | ||
|
@@ -727,22 +728,24 @@ protected function asDate($value) | |
* Return a timestamp as DateTime object. | ||
* | ||
* @param mixed $value | ||
* @return \Illuminate\Support\Carbon | ||
* @return \Carbon\Carbon | ||
*/ | ||
protected function asDateTime($value) | ||
{ | ||
// If this value is already a Carbon instance, we shall just return it as is. | ||
// This prevents us having to re-instantiate a Carbon instance when we know | ||
// it already is one, which wouldn't be fulfilled by the DateTime check. | ||
if ($value instanceof Carbon) { | ||
if ($value instanceof CarbonInterface) { | ||
return $value; | ||
} | ||
|
||
$dateFactory = app(Factory::class); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Database component doesn't load |
||
|
||
// If the value is already a DateTime instance, we will just skip the rest of | ||
// these checks since they will be a waste of time, and hinder performance | ||
// when checking the field. We will just return the DateTime right away. | ||
if ($value instanceof DateTimeInterface) { | ||
return new Carbon( | ||
return $dateFactory->parse( | ||
$value->format('Y-m-d H:i:s.u'), $value->getTimezone() | ||
); | ||
} | ||
|
@@ -751,20 +754,20 @@ protected function asDateTime($value) | |
// and format a Carbon object from this timestamp. This allows flexibility | ||
// when defining your date fields as they might be UNIX timestamps here. | ||
if (is_numeric($value)) { | ||
return Carbon::createFromTimestamp($value); | ||
return $dateFactory->createFromTimestamp($value); | ||
} | ||
|
||
// If the value is in simply year, month, day format, we will instantiate the | ||
// Carbon instances from that format. Again, this provides for simple date | ||
// fields on the database, while still supporting Carbonized conversion. | ||
if ($this->isStandardDateFormat($value)) { | ||
return Carbon::createFromFormat('Y-m-d', $value)->startOfDay(); | ||
return $dateFactory->createFromFormat('Y-m-d', $value)->startOfDay(); | ||
} | ||
|
||
// Finally, we will just assume this date is in the format used by default on | ||
// the database connection and use that format to create the Carbon object | ||
// that is returned back out to the developers after we convert it here. | ||
return Carbon::createFromFormat( | ||
return $dateFactory->createFromFormat( | ||
str_replace('.v', '.u', $this->getDateFormat()), $value | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
|
||
namespace Illuminate\Filesystem; | ||
|
||
use Carbon\Factory; | ||
use RuntimeException; | ||
use Illuminate\Http\File; | ||
use Illuminate\Support\Str; | ||
use InvalidArgumentException; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Http\UploadedFile; | ||
use Illuminate\Support\Collection; | ||
use League\Flysystem\AdapterInterface; | ||
|
@@ -548,7 +548,7 @@ public function getAwsTemporaryUrl($adapter, $path, $expiration, $options) | |
public function getRackspaceTemporaryUrl($adapter, $path, $expiration, $options) | ||
{ | ||
return $adapter->getContainer()->getObject($path)->getTemporaryUrl( | ||
Carbon::now()->diffInSeconds($expiration), | ||
app(Factory::class)->now()->diffInSeconds($expiration), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filesystem component doesn't load |
||
$options['method'] ?? 'GET', | ||
$options['forcePublicUrl'] ?? true | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just going to create a "60 minutes datetime from now", a plain
Carbon::now()->addMinutes(60)
should work fine.