diff --git a/composer.json b/composer.json index df1aacbd3801..b8cee8a6389b 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "erusev/parsedown": "^1.7", "league/flysystem": "^1.0.8", "monolog/monolog": "^1.12", - "nesbot/carbon": "^1.26.3", + "nesbot/carbon": "^2.0", "psr/container": "^1.0", "psr/simple-cache": "^1.0", "ramsey/uuid": "^3.7", diff --git a/src/Illuminate/Auth/Notifications/VerifyEmail.php b/src/Illuminate/Auth/Notifications/VerifyEmail.php index f8f316260e98..b2adb189b914 100644 --- a/src/Illuminate/Auth/Notifications/VerifyEmail.php +++ b/src/Illuminate/Auth/Notifications/VerifyEmail.php @@ -2,7 +2,7 @@ namespace Illuminate\Auth\Notifications; -use Illuminate\Support\Carbon; +use Carbon\Factory; use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\Lang; use Illuminate\Notifications\Notification; @@ -59,7 +59,7 @@ public function toMail($notifiable) protected function verificationUrl($notifiable) { return URL::temporarySignedRoute( - 'verification.verify', Carbon::now()->addMinutes(60), ['id' => $notifiable->getKey()] + 'verification.verify', app(Factory::class)->now()->addMinutes(60), ['id' => $notifiable->getKey()] ); } diff --git a/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php b/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php index c4701759929d..66661079cccc 100755 --- a/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php +++ b/src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php @@ -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(), + ]; } /** @@ -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(); } /** @@ -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(); } diff --git a/src/Illuminate/Cache/Repository.php b/src/Illuminate/Cache/Repository.php index 2e4b1cabe5a2..5177b7787b17 100755 --- a/src/Illuminate/Cache/Repository.php +++ b/src/Illuminate/Cache/Repository.php @@ -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; } return (int) ($duration * 60) > 0 ? $duration : null; diff --git a/src/Illuminate/Console/Scheduling/Event.php b/src/Illuminate/Console/Scheduling/Event.php index 0adb9bf3d6db..bcda958c5771 100644 --- a/src/Illuminate/Console/Scheduling/Event.php +++ b/src/Illuminate/Console/Scheduling/Event.php @@ -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)); } diff --git a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php index 073e1897a555..96a17b50869c 100644 --- a/src/Illuminate/Console/Scheduling/ManagesFrequencies.php +++ b/src/Illuminate/Console/Scheduling/ManagesFrequencies.php @@ -2,7 +2,7 @@ namespace Illuminate\Console\Scheduling; -use Illuminate\Support\Carbon; +use Carbon\Factory; trait ManagesFrequencies { @@ -53,9 +53,11 @@ public function unlessBetween($startTime, $endTime) private function inTimeInterval($startTime, $endTime) { return function () use ($startTime, $endTime) { - return Carbon::now($this->timezone)->between( - Carbon::parse($startTime, $this->timezone), - Carbon::parse($endTime, $this->timezone), + $dateFactory = app(Factory::class); + + return $dateFactory->now($this->timezone)->between( + $dateFactory->parse($startTime, $this->timezone), + $dateFactory->parse($endTime, $this->timezone), true ); }; diff --git a/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php b/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php index 21695438aa2a..3c7cbc893081 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php @@ -2,7 +2,7 @@ namespace Illuminate\Console\Scheduling; -use Illuminate\Support\Carbon; +use Carbon\Factory; use Illuminate\Console\Command; class ScheduleRunCommand extends Command @@ -31,7 +31,7 @@ class ScheduleRunCommand extends Command /** * The 24 hour timestamp this scheduler command started running. * - * @var \Illuminate\Support\Carbon; + * @var \Carbon\Carbon; */ protected $startedAt; @@ -52,7 +52,7 @@ public function __construct(Schedule $schedule) { $this->schedule = $schedule; - $this->startedAt = Carbon::now(); + $this->startedAt = app(Factory::class)->now(); parent::__construct(); } diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index b61321af509e..9ff84913fc41 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -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); + // 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 ); } diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php b/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php index 8e3d488edd2d..213810521fa7 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php @@ -2,7 +2,7 @@ namespace Illuminate\Database\Eloquent\Concerns; -use Illuminate\Support\Carbon; +use Carbon\Factory; trait HasTimestamps { @@ -77,11 +77,11 @@ public function setUpdatedAt($value) /** * Get a fresh timestamp for the model. * - * @return \Illuminate\Support\Carbon + * @return \Carbon\Carbon */ public function freshTimestamp() { - return new Carbon; + return app(Factory::class)->now(); } /** diff --git a/src/Illuminate/Filesystem/FilesystemAdapter.php b/src/Illuminate/Filesystem/FilesystemAdapter.php index 64f45b5c721c..08b681364fb5 100644 --- a/src/Illuminate/Filesystem/FilesystemAdapter.php +++ b/src/Illuminate/Filesystem/FilesystemAdapter.php @@ -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), $options['method'] ?? 'GET', $options['forcePublicUrl'] ?? true ); diff --git a/src/Illuminate/Foundation/Http/Exceptions/MaintenanceModeException.php b/src/Illuminate/Foundation/Http/Exceptions/MaintenanceModeException.php index 6d5a2ab71f27..97693b2356d6 100644 --- a/src/Illuminate/Foundation/Http/Exceptions/MaintenanceModeException.php +++ b/src/Illuminate/Foundation/Http/Exceptions/MaintenanceModeException.php @@ -3,7 +3,8 @@ namespace Illuminate\Foundation\Http\Exceptions; use Exception; -use Illuminate\Support\Carbon; +use Carbon\Carbon; +use Carbon\Factory; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; class MaintenanceModeException extends ServiceUnavailableHttpException @@ -11,7 +12,7 @@ class MaintenanceModeException extends ServiceUnavailableHttpException /** * When the application was put in maintenance mode. * - * @var \Illuminate\Support\Carbon + * @var Carbon */ public $wentDownAt; @@ -25,7 +26,7 @@ class MaintenanceModeException extends ServiceUnavailableHttpException /** * When the application should next be available. * - * @var \Illuminate\Support\Carbon + * @var Carbon */ public $willBeAvailableAt; @@ -43,12 +44,13 @@ public function __construct($time, $retryAfter = null, $message = null, Exceptio { parent::__construct($retryAfter, $message, $previous, $code); - $this->wentDownAt = Carbon::createFromTimestamp($time); + $dateFactory = app(Factory::class); + $this->wentDownAt = $dateFactory->createFromTimestamp($time); if ($retryAfter) { $this->retryAfter = $retryAfter; - $this->willBeAvailableAt = Carbon::createFromTimestamp($time)->addSeconds($this->retryAfter); + $this->willBeAvailableAt = $dateFactory->createFromTimestamp($time)->addSeconds($this->retryAfter); } } } diff --git a/src/Illuminate/Foundation/Testing/TestCase.php b/src/Illuminate/Foundation/Testing/TestCase.php index 1e9d33e2077c..fe23954d17a4 100644 --- a/src/Illuminate/Foundation/Testing/TestCase.php +++ b/src/Illuminate/Foundation/Testing/TestCase.php @@ -3,7 +3,8 @@ namespace Illuminate\Foundation\Testing; use Mockery; -use Illuminate\Support\Carbon; +use Carbon\Carbon; +use Carbon\CarbonImmutable; use Illuminate\Support\Facades\Facade; use Illuminate\Database\Eloquent\Model; use Illuminate\Console\Application as Artisan; @@ -165,6 +166,9 @@ protected function tearDown() if (class_exists(Carbon::class)) { Carbon::setTestNow(); } + if (class_exists(CarbonImmutable::class)) { + CarbonImmutable::setTestNow(); + } $this->afterApplicationCreatedCallbacks = []; $this->beforeApplicationDestroyedCallbacks = []; diff --git a/src/Illuminate/Foundation/Testing/TestResponse.php b/src/Illuminate/Foundation/Testing/TestResponse.php index dbec9ee890ed..005b441fc67a 100644 --- a/src/Illuminate/Foundation/Testing/TestResponse.php +++ b/src/Illuminate/Foundation/Testing/TestResponse.php @@ -3,9 +3,11 @@ namespace Illuminate\Foundation\Testing; use Closure; +use Carbon\Carbon; +use Carbon\Factory; +use Carbon\CarbonImmutable; use Illuminate\Support\Arr; use Illuminate\Support\Str; -use Illuminate\Support\Carbon; use Illuminate\Contracts\View\View; use Illuminate\Support\Traits\Macroable; use PHPUnit\Framework\Assert as PHPUnit; @@ -256,15 +258,18 @@ public function assertCookie($cookieName, $value = null, $encrypted = true, $uns */ public function assertCookieExpired($cookieName) { + $dateFactory = app(Factory::class); + PHPUnit::assertNotNull( $cookie = $this->getCookie($cookieName), "Cookie [{$cookieName}] not present on response." ); - $expiresAt = Carbon::createFromTimestamp($cookie->getExpiresTime()); + /** @var Carbon|CarbonImmutable $expiresAt */ + $expiresAt = $dateFactory->createFromTimestamp($cookie->getExpiresTime()); PHPUnit::assertTrue( - $expiresAt->lessThan(Carbon::now()), + $expiresAt->lessThan($dateFactory->now()), "Cookie [{$cookieName}] is not expired, it expires at [{$expiresAt}]." ); @@ -279,15 +284,18 @@ public function assertCookieExpired($cookieName) */ public function assertCookieNotExpired($cookieName) { + $dateFactory = app(Factory::class); + PHPUnit::assertNotNull( $cookie = $this->getCookie($cookieName), "Cookie [{$cookieName}] not present on response." ); - $expiresAt = Carbon::createFromTimestamp($cookie->getExpiresTime()); + /** @var Carbon|CarbonImmutable $expiresAt */ + $expiresAt = $dateFactory->createFromTimestamp($cookie->getExpiresTime()); PHPUnit::assertTrue( - $expiresAt->greaterThan(Carbon::now()), + $expiresAt->greaterThan($dateFactory->now()), "Cookie [{$cookieName}] is expired, it expired at [{$expiresAt}]." ); diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index a462a0ea1e98..c65b983a48a1 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -1,7 +1,7 @@ now($tz); } } @@ -882,11 +882,11 @@ function storage_path($path = '') * Create a new Carbon instance for the current date. * * @param \DateTimeZone|string|null $tz - * @return \Illuminate\Support\Carbon + * @return \Carbon\Carbon */ function today($tz = null) { - return Carbon::today($tz); + return app(Factory::class)->today($tz); } } diff --git a/src/Illuminate/Queue/Console/WorkCommand.php b/src/Illuminate/Queue/Console/WorkCommand.php index 8d759c7d0983..3e202a894df2 100644 --- a/src/Illuminate/Queue/Console/WorkCommand.php +++ b/src/Illuminate/Queue/Console/WorkCommand.php @@ -2,8 +2,8 @@ namespace Illuminate\Queue\Console; +use Carbon\Factory; use Illuminate\Queue\Worker; -use Illuminate\Support\Carbon; use Illuminate\Console\Command; use Illuminate\Contracts\Queue\Job; use Illuminate\Queue\WorkerOptions; @@ -169,7 +169,7 @@ protected function writeStatus(Job $job, $status, $type) { $this->output->writeln(sprintf( "<{$type}>[%s][%s] %s %s", - Carbon::now()->format('Y-m-d H:i:s'), + app(Factory::class)->now()->format('Y-m-d H:i:s'), $job->getJobId(), str_pad("{$status}:", 11), $job->resolveName() )); diff --git a/src/Illuminate/Queue/DatabaseQueue.php b/src/Illuminate/Queue/DatabaseQueue.php index f40536aeef21..e5efd1d56cba 100644 --- a/src/Illuminate/Queue/DatabaseQueue.php +++ b/src/Illuminate/Queue/DatabaseQueue.php @@ -2,7 +2,7 @@ namespace Illuminate\Queue; -use Illuminate\Support\Carbon; +use Carbon\Factory; use Illuminate\Database\Connection; use Illuminate\Queue\Jobs\DatabaseJob; use Illuminate\Queue\Jobs\DatabaseJobRecord; @@ -242,7 +242,7 @@ protected function isAvailable($query) */ protected function isReservedButExpired($query) { - $expiration = Carbon::now()->subSeconds($this->retryAfter)->getTimestamp(); + $expiration = app(Factory::class)->now()->subSeconds($this->retryAfter)->getTimestamp(); $query->orWhere(function ($query) use ($expiration) { $query->where('reserved_at', '<=', $expiration); diff --git a/src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php b/src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php index 59de88e1a9f5..695e45292503 100644 --- a/src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php +++ b/src/Illuminate/Queue/Failed/DatabaseFailedJobProvider.php @@ -2,7 +2,7 @@ namespace Illuminate\Queue\Failed; -use Illuminate\Support\Carbon; +use Carbon\Factory; use Illuminate\Database\ConnectionResolverInterface; class DatabaseFailedJobProvider implements FailedJobProviderInterface @@ -54,7 +54,7 @@ public function __construct(ConnectionResolverInterface $resolver, $database, $t */ public function log($connection, $queue, $payload, $exception) { - $failed_at = Carbon::now(); + $failed_at = app(Factory::class)->now(); $exception = (string) $exception; diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 1983723ec5f9..a55984411be1 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -4,7 +4,7 @@ use Exception; use Throwable; -use Illuminate\Support\Carbon; +use Carbon\Factory; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\DetectsLostConnections; use Illuminate\Contracts\Debug\ExceptionHandler; @@ -389,7 +389,7 @@ protected function markJobAsFailedIfAlreadyExceedsMaxAttempts($connectionName, $ $timeoutAt = $job->timeoutAt(); - if ($timeoutAt && Carbon::now()->getTimestamp() <= $timeoutAt) { + if ($timeoutAt && app(Factory::class)->now()->getTimestamp() <= $timeoutAt) { return; } @@ -417,7 +417,7 @@ protected function markJobAsFailedIfWillExceedMaxAttempts($connectionName, $job, { $maxTries = ! is_null($job->maxTries()) ? $job->maxTries() : $maxTries; - if ($job->timeoutAt() && $job->timeoutAt() <= Carbon::now()->getTimestamp()) { + if ($job->timeoutAt() && $job->timeoutAt() <= app(Factory::class)->now()->getTimestamp()) { $this->failJob($connectionName, $job, $e); } diff --git a/src/Illuminate/Routing/UrlGenerator.php b/src/Illuminate/Routing/UrlGenerator.php index 98446c8d4f62..8fc6db1ea873 100755 --- a/src/Illuminate/Routing/UrlGenerator.php +++ b/src/Illuminate/Routing/UrlGenerator.php @@ -3,11 +3,11 @@ namespace Illuminate\Routing; use Closure; +use Carbon\Factory; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Http\Request; use InvalidArgumentException; -use Illuminate\Support\Carbon; use Illuminate\Support\Traits\Macroable; use Illuminate\Support\InteractsWithTime; use Illuminate\Contracts\Routing\UrlRoutable; @@ -352,7 +352,7 @@ public function hasValidSignature(Request $request) $signature = hash_hmac('sha256', $original, call_user_func($this->keyResolver)); return hash_equals($signature, $request->query('signature', '')) && - ! ($expires && Carbon::now()->getTimestamp() > $expires); + ! ($expires && app(Factory::class)->now()->getTimestamp() > $expires); } /** diff --git a/src/Illuminate/Session/DatabaseSessionHandler.php b/src/Illuminate/Session/DatabaseSessionHandler.php index 976c2901e6b8..add202d1dad6 100644 --- a/src/Illuminate/Session/DatabaseSessionHandler.php +++ b/src/Illuminate/Session/DatabaseSessionHandler.php @@ -2,9 +2,9 @@ namespace Illuminate\Session; +use Carbon\Factory; use Illuminate\Support\Arr; use SessionHandlerInterface; -use Illuminate\Support\Carbon; use Illuminate\Contracts\Auth\Guard; use Illuminate\Database\QueryException; use Illuminate\Support\InteractsWithTime; @@ -114,7 +114,7 @@ public function read($sessionId) protected function expired($session) { return isset($session->last_activity) && - $session->last_activity < Carbon::now()->subMinutes($this->minutes)->getTimestamp(); + $session->last_activity < app(Factory::class)->now()->subMinutes($this->minutes)->getTimestamp(); } /** diff --git a/src/Illuminate/Session/FileSessionHandler.php b/src/Illuminate/Session/FileSessionHandler.php index 839e6e4c2e53..ee99f539120c 100644 --- a/src/Illuminate/Session/FileSessionHandler.php +++ b/src/Illuminate/Session/FileSessionHandler.php @@ -2,8 +2,8 @@ namespace Illuminate\Session; +use Carbon\Factory; use SessionHandlerInterface; -use Illuminate\Support\Carbon; use Symfony\Component\Finder\Finder; use Illuminate\Filesystem\Filesystem; @@ -67,7 +67,7 @@ public function close() public function read($sessionId) { if ($this->files->isFile($path = $this->path.'/'.$sessionId)) { - if ($this->files->lastModified($path) >= Carbon::now()->subMinutes($this->minutes)->getTimestamp()) { + if ($this->files->lastModified($path) >= app(Factory::class)->now()->subMinutes($this->minutes)->getTimestamp()) { return $this->files->sharedGet($path); } } diff --git a/src/Illuminate/Session/Middleware/StartSession.php b/src/Illuminate/Session/Middleware/StartSession.php index b47fde27aaac..66f1fc4c4c33 100644 --- a/src/Illuminate/Session/Middleware/StartSession.php +++ b/src/Illuminate/Session/Middleware/StartSession.php @@ -3,8 +3,8 @@ namespace Illuminate\Session\Middleware; use Closure; +use Carbon\Factory; use Illuminate\Http\Request; -use Illuminate\Support\Carbon; use Illuminate\Session\SessionManager; use Illuminate\Contracts\Session\Session; use Illuminate\Session\CookieSessionHandler; @@ -194,13 +194,13 @@ protected function getSessionLifetimeInSeconds() /** * Get the cookie lifetime in seconds. * - * @return \DateTimeInterface + * @return \DateTimeInterface|int */ protected function getCookieExpirationDate() { $config = $this->manager->getSessionConfig(); - return $config['expire_on_close'] ? 0 : Carbon::now()->addMinutes($config['lifetime']); + return $config['expire_on_close'] ? 0 : app(Factory::class)->now()->addMinutes($config['lifetime']); } /** diff --git a/src/Illuminate/Support/InteractsWithTime.php b/src/Illuminate/Support/InteractsWithTime.php index 19ed3f242a62..a38e34afd619 100644 --- a/src/Illuminate/Support/InteractsWithTime.php +++ b/src/Illuminate/Support/InteractsWithTime.php @@ -3,11 +3,13 @@ namespace Illuminate\Support; use DateInterval; +use Carbon\Factory; use DateTimeInterface; trait InteractsWithTime { /** + * Get the number of seconds until the given DateTime. * Get the number of seconds until the given DateTime. * * @param \DateTimeInterface|\DateInterval|int $delay @@ -34,7 +36,7 @@ protected function availableAt($delay = 0) return $delay instanceof DateTimeInterface ? $delay->getTimestamp() - : Carbon::now()->addSeconds($delay)->getTimestamp(); + : app(Factory::class)->now()->addSeconds($delay)->getTimestamp(); } /** @@ -46,7 +48,7 @@ protected function availableAt($delay = 0) protected function parseDateInterval($delay) { if ($delay instanceof DateInterval) { - $delay = Carbon::now()->add($delay); + $delay = app(Factory::class)->now()->add($delay); } return $delay; @@ -59,6 +61,6 @@ protected function parseDateInterval($delay) */ protected function currentTime() { - return Carbon::now()->getTimestamp(); + return app(Factory::class)->now()->getTimestamp(); } } diff --git a/src/Illuminate/Support/composer.json b/src/Illuminate/Support/composer.json index 722ac685ca66..e52a0f67b279 100644 --- a/src/Illuminate/Support/composer.json +++ b/src/Illuminate/Support/composer.json @@ -18,7 +18,7 @@ "ext-mbstring": "*", "doctrine/inflector": "^1.1", "illuminate/contracts": "5.8.*", - "nesbot/carbon": "^1.24.1" + "nesbot/carbon": "^2.0" }, "conflict": { "tightenco/collect": "<5.5.33" diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index b32f9876b714..62479c1a05ed 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -7,11 +7,11 @@ use Exception; use Throwable; use DateTimeZone; +use Carbon\Factory; use DateTimeInterface; use Illuminate\Support\Arr; use Illuminate\Support\Str; use InvalidArgumentException; -use Illuminate\Support\Carbon; use Illuminate\Validation\Rules\Exists; use Illuminate\Validation\Rules\Unique; use Illuminate\Validation\ValidationData; @@ -240,7 +240,7 @@ protected function getDateTime($value) { try { if ($this->isTestingRelativeDateTime($value)) { - return new Carbon($value); + return app(Factory::class)->parse($value); } return new DateTime($value); @@ -257,8 +257,10 @@ protected function getDateTime($value) */ protected function isTestingRelativeDateTime($value) { - return Carbon::hasTestNow() && is_string($value) && ( - $value === 'now' || Carbon::hasRelativeKeywords($value) + $dateFactory = app(Factory::class); + + return $dateFactory->hasTestNow() && is_string($value) && ( + $value === 'now' || $dateFactory->hasRelativeKeywords($value) ); } diff --git a/tests/Auth/AuthDatabaseTokenRepositoryTest.php b/tests/Auth/AuthDatabaseTokenRepositoryTest.php index 5eafc2f3ee1a..7d4df42061e7 100755 --- a/tests/Auth/AuthDatabaseTokenRepositoryTest.php +++ b/tests/Auth/AuthDatabaseTokenRepositoryTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Auth; use Mockery as m; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Auth\Passwords\DatabaseTokenRepository; diff --git a/tests/Cache/CacheFileStoreTest.php b/tests/Cache/CacheFileStoreTest.php index 860abd1ed94b..b81841548f4d 100755 --- a/tests/Cache/CacheFileStoreTest.php +++ b/tests/Cache/CacheFileStoreTest.php @@ -2,7 +2,7 @@ namespace Illuminate\Tests\Cache; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use Illuminate\Cache\FileStore; use PHPUnit\Framework\TestCase; use Illuminate\Contracts\Filesystem\FileNotFoundException; diff --git a/tests/Cache/CacheMemcachedStoreTest.php b/tests/Cache/CacheMemcachedStoreTest.php index 5bbebf0a25d7..334c24e29513 100755 --- a/tests/Cache/CacheMemcachedStoreTest.php +++ b/tests/Cache/CacheMemcachedStoreTest.php @@ -63,12 +63,12 @@ public function testSetMethodProperlyCallsMemcache() $this->markTestSkipped('Memcached module not installed'); } - \Illuminate\Support\Carbon::setTestNow($now = \Illuminate\Support\Carbon::now()); + \Carbon\Carbon::setTestNow($now = \Carbon\Carbon::now()); $memcache = $this->getMockBuilder('Memcached')->setMethods(['set'])->getMock(); $memcache->expects($this->once())->method('set')->with($this->equalTo('foo'), $this->equalTo('bar'), $this->equalTo($now->timestamp + 60)); $store = new MemcachedStore($memcache); $store->put('foo', 'bar', 1); - \Illuminate\Support\Carbon::setTestNow(); + \Carbon\Carbon::setTestNow(); } public function testIncrementMethodProperlyCallsMemcache() diff --git a/tests/Cache/CacheRepositoryTest.php b/tests/Cache/CacheRepositoryTest.php index f91980120eae..7a259f222d8e 100755 --- a/tests/Cache/CacheRepositoryTest.php +++ b/tests/Cache/CacheRepositoryTest.php @@ -5,8 +5,8 @@ use DateTime; use DateInterval; use Mockery as m; +use Carbon\Carbon; use DateTimeImmutable; -use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; class CacheRepositoryTest extends TestCase diff --git a/tests/Console/ConsoleScheduledEventTest.php b/tests/Console/ConsoleScheduledEventTest.php index 1db5dc7f282b..4dc972e547ef 100644 --- a/tests/Console/ConsoleScheduledEventTest.php +++ b/tests/Console/ConsoleScheduledEventTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Console; use Mockery as m; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Console\Scheduling\Event; diff --git a/tests/Console/Scheduling/CacheSchedulingMutexTest.php b/tests/Console/Scheduling/CacheSchedulingMutexTest.php index 5313e2773349..b0acd48ec2da 100644 --- a/tests/Console/Scheduling/CacheSchedulingMutexTest.php +++ b/tests/Console/Scheduling/CacheSchedulingMutexTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Console\Scheduling; use Mockery as m; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Console\Scheduling\Event; use Illuminate\Console\Scheduling\CacheEventMutex; diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index 45e3d349b590..aea9594c5dda 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Database; use Exception; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Collection; @@ -605,8 +605,8 @@ public function testHasOnSelfReferencingBelongsToRelationship() public function testAggregatedValuesOfDatetimeField() { - EloquentTestUser::create(['id' => 1, 'email' => 'test1@test.test', 'created_at' => '2016-08-10 09:21:00', 'updated_at' => \Illuminate\Support\Carbon::now()]); - EloquentTestUser::create(['id' => 2, 'email' => 'test2@test.test', 'created_at' => '2016-08-01 12:00:00', 'updated_at' => \Illuminate\Support\Carbon::now()]); + EloquentTestUser::create(['id' => 1, 'email' => 'test1@test.test', 'created_at' => '2016-08-10 09:21:00', 'updated_at' => \Carbon\Carbon::now()]); + EloquentTestUser::create(['id' => 2, 'email' => 'test2@test.test', 'created_at' => '2016-08-01 12:00:00', 'updated_at' => \Carbon\Carbon::now()]); $this->assertEquals('2016-08-10 09:21:00', EloquentTestUser::max('created_at')); $this->assertEquals('2016-08-01 12:00:00', EloquentTestUser::min('created_at')); @@ -1129,8 +1129,8 @@ public function testIsAfterRetrievingTheSameModel() public function testFreshMethodOnModel() { - $now = \Illuminate\Support\Carbon::now(); - \Illuminate\Support\Carbon::setTestNow($now); + $now = \Carbon\Carbon::now(); + \Carbon\Carbon::setTestNow($now); $storedUser1 = EloquentTestUser::create(['id' => 1, 'email' => 'taylorotwell@gmail.com']); $storedUser1->newQuery()->update(['email' => 'dev@mathieutu.ovh', 'name' => 'Mathieu TUDISCO']); diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 1bd28a05ecea..961cf740212d 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -6,10 +6,10 @@ use stdClass; use Exception; use Mockery as m; +use Carbon\Carbon; use ReflectionClass; use DateTimeImmutable; use DateTimeInterface; -use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; @@ -35,7 +35,7 @@ public function tearDown() Carbon::setTestNow(null); \Illuminate\Database\Eloquent\Model::unsetEventDispatcher(); - \Illuminate\Support\Carbon::resetToStringFormat(); + \Carbon\Carbon::resetToStringFormat(); } public function testAttributeManipulation() @@ -355,8 +355,8 @@ public function testTimestampsAreReturnedAsObjects() 'updated_at' => '2012-12-05', ]); - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->updated_at); + $this->assertInstanceOf(\Carbon\Carbon::class, $model->created_at); + $this->assertInstanceOf(\Carbon\Carbon::class, $model->updated_at); } public function testTimestampsAreReturnedAsObjectsFromPlainDatesAndTimestamps() @@ -368,15 +368,15 @@ public function testTimestampsAreReturnedAsObjectsFromPlainDatesAndTimestamps() 'updated_at' => $this->currentTime(), ]); - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->updated_at); + $this->assertInstanceOf(\Carbon\Carbon::class, $model->created_at); + $this->assertInstanceOf(\Carbon\Carbon::class, $model->updated_at); } public function testTimestampsAreReturnedAsObjectsOnCreate() { $timestamps = [ - 'created_at' => \Illuminate\Support\Carbon::now(), - 'updated_at' => \Illuminate\Support\Carbon::now(), + 'created_at' => \Carbon\Carbon::now(), + 'updated_at' => \Carbon\Carbon::now(), ]; $model = new EloquentDateModelStub; \Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver = m::mock('Illuminate\Database\ConnectionResolverInterface')); @@ -384,15 +384,15 @@ public function testTimestampsAreReturnedAsObjectsOnCreate() $mockConnection->shouldReceive('getQueryGrammar')->andReturn($mockConnection); $mockConnection->shouldReceive('getDateFormat')->andReturn('Y-m-d H:i:s'); $instance = $model->newInstance($timestamps); - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $instance->updated_at); - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $instance->created_at); + $this->assertInstanceOf(\Carbon\Carbon::class, $instance->updated_at); + $this->assertInstanceOf(\Carbon\Carbon::class, $instance->created_at); } public function testDateTimeAttributesReturnNullIfSetToNull() { $timestamps = [ - 'created_at' => \Illuminate\Support\Carbon::now(), - 'updated_at' => \Illuminate\Support\Carbon::now(), + 'created_at' => \Carbon\Carbon::now(), + 'updated_at' => \Carbon\Carbon::now(), ]; $model = new EloquentDateModelStub; \Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver = m::mock('Illuminate\Database\ConnectionResolverInterface')); @@ -409,26 +409,26 @@ public function testTimestampsAreCreatedFromStringsAndIntegers() { $model = new EloquentDateModelStub; $model->created_at = '2013-05-22 00:00:00'; - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); + $this->assertInstanceOf(\Carbon\Carbon::class, $model->created_at); $model = new EloquentDateModelStub; $model->created_at = $this->currentTime(); - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); + $this->assertInstanceOf(\Carbon\Carbon::class, $model->created_at); $model = new EloquentDateModelStub; $model->created_at = 0; - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); + $this->assertInstanceOf(\Carbon\Carbon::class, $model->created_at); $model = new EloquentDateModelStub; $model->created_at = '2012-01-01'; - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->created_at); + $this->assertInstanceOf(\Carbon\Carbon::class, $model->created_at); } public function testFromDateTime() { $model = new EloquentModelStub; - $value = \Illuminate\Support\Carbon::parse('2015-04-17 22:59:01'); + $value = \Carbon\Carbon::parse('2015-04-17 22:59:01'); $this->assertEquals('2015-04-17 22:59:01', $model->fromDateTime($value)); $value = new DateTime('2015-04-17 22:59:01'); @@ -1504,8 +1504,8 @@ public function testModelAttributesAreCastedWhenPresentInCastsArray() $this->assertEquals(['foo' => 'bar'], $model->arrayAttribute); $this->assertEquals(['foo' => 'bar'], $model->jsonAttribute); $this->assertEquals('{"foo":"bar"}', $model->jsonAttributeValue()); - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->dateAttribute); - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->datetimeAttribute); + $this->assertInstanceOf(\Carbon\Carbon::class, $model->dateAttribute); + $this->assertInstanceOf(\Carbon\Carbon::class, $model->datetimeAttribute); $this->assertEquals('1969-07-20', $model->dateAttribute->toDateString()); $this->assertEquals('1969-07-20 22:56:00', $model->datetimeAttribute->toDateTimeString()); $this->assertEquals(-14173440, $model->timestampAttribute); diff --git a/tests/Database/DatabaseEloquentRelationTest.php b/tests/Database/DatabaseEloquentRelationTest.php index 5dbbf1562d89..7852c7160e8a 100755 --- a/tests/Database/DatabaseEloquentRelationTest.php +++ b/tests/Database/DatabaseEloquentRelationTest.php @@ -47,7 +47,7 @@ public function testTouchMethodUpdatesRelatedTimestamps() $relation = new HasOne($builder, $parent, 'foreign_key', 'id'); $related->shouldReceive('getTable')->andReturn('table'); $related->shouldReceive('getUpdatedAtColumn')->andReturn('updated_at'); - $now = \Illuminate\Support\Carbon::now(); + $now = \Carbon\Carbon::now(); $related->shouldReceive('freshTimestampString')->andReturn($now); $builder->shouldReceive('update')->once()->with(['updated_at' => $now]); @@ -120,7 +120,7 @@ public function testCanDisableTouchingForSpecificModel() $anotherBuilder->shouldReceive('where'); $anotherBuilder->shouldReceive('withoutGlobalScopes')->andReturnSelf(); $anotherRelation = new HasOne($anotherBuilder, $anotherParent, 'foreign_key', 'id'); - $now = \Illuminate\Support\Carbon::now(); + $now = \Carbon\Carbon::now(); $anotherRelated->shouldReceive('freshTimestampString')->andReturn($now); $anotherBuilder->shouldReceive('update')->once()->with(['updated_at' => $now]); diff --git a/tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php b/tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php index a4aab9adb13d..a733f3a8a010 100644 --- a/tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php +++ b/tests/Database/DatabaseEloquentSoftDeletesIntegrationTest.php @@ -2,7 +2,7 @@ namespace Illuminate\Tests\Database; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Pagination\Paginator; use Illuminate\Database\Query\Builder; diff --git a/tests/Database/DatabaseEloquentTimestamps.php b/tests/Database/DatabaseEloquentTimestamps.php index 9cd86c7ee8d7..f3716e5ff67a 100644 --- a/tests/Database/DatabaseEloquentTimestamps.php +++ b/tests/Database/DatabaseEloquentTimestamps.php @@ -2,7 +2,7 @@ namespace Illuminate\Tests\Database; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Database\Capsule\Manager as DB; use Illuminate\Database\Eloquent\Model as Eloquent; diff --git a/tests/Database/DatabaseSoftDeletingTraitTest.php b/tests/Database/DatabaseSoftDeletingTraitTest.php index ecd45d93600b..3ec44c57c8a6 100644 --- a/tests/Database/DatabaseSoftDeletingTraitTest.php +++ b/tests/Database/DatabaseSoftDeletingTraitTest.php @@ -24,7 +24,7 @@ public function testDeleteSetsSoftDeletedColumn() ]); $model->delete(); - $this->assertInstanceOf(\Illuminate\Support\Carbon::class, $model->deleted_at); + $this->assertInstanceOf(\Carbon\Carbon::class, $model->deleted_at); } public function testRestore() @@ -90,7 +90,7 @@ public function fireModelEvent() public function freshTimestamp() { - return \Illuminate\Support\Carbon::now(); + return \Carbon\Carbon::now(); } public function fromDateTime() diff --git a/tests/Integration/Cache/CacheLockTest.php b/tests/Integration/Cache/CacheLockTest.php index 9bb964f46b47..6b8b10e61a28 100644 --- a/tests/Integration/Cache/CacheLockTest.php +++ b/tests/Integration/Cache/CacheLockTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Integration\Cache; use Memcached; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use Orchestra\Testbench\TestCase; use Illuminate\Support\Facades\Cache; use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis; diff --git a/tests/Integration/Database/EloquentBelongsToManyTest.php b/tests/Integration/Database/EloquentBelongsToManyTest.php index 22cbe9c17e16..ae92790bcc22 100644 --- a/tests/Integration/Database/EloquentBelongsToManyTest.php +++ b/tests/Integration/Database/EloquentBelongsToManyTest.php @@ -2,7 +2,7 @@ namespace Illuminate\Tests\Integration\Database\EloquentBelongsToManyTest; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; diff --git a/tests/Integration/Database/EloquentModelTest.php b/tests/Integration/Database/EloquentModelTest.php index 143681c545ab..74b1419ade09 100644 --- a/tests/Integration/Database/EloquentModelTest.php +++ b/tests/Integration/Database/EloquentModelTest.php @@ -33,7 +33,7 @@ public function test_user_can_update_nullable_date() ]); $user->fill([ - 'nullable_date' => $now = \Illuminate\Support\Carbon::now(), + 'nullable_date' => $now = \Carbon\Carbon::now(), ]); $this->assertTrue($user->isDirty('nullable_date')); diff --git a/tests/Integration/Database/EloquentMorphManyTest.php b/tests/Integration/Database/EloquentMorphManyTest.php index 53b17182b8e7..e8f6e2c6767c 100644 --- a/tests/Integration/Database/EloquentMorphManyTest.php +++ b/tests/Integration/Database/EloquentMorphManyTest.php @@ -2,7 +2,7 @@ namespace Illuminate\Tests\Integration\Database\EloquentMorphManyTest; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; use Illuminate\Tests\Integration\Database\DatabaseTestCase; diff --git a/tests/Integration/Database/EloquentTouchParentWithGlobalScopeTest.php b/tests/Integration/Database/EloquentTouchParentWithGlobalScopeTest.php index b688ba3fc76e..140d1342c83b 100644 --- a/tests/Integration/Database/EloquentTouchParentWithGlobalScopeTest.php +++ b/tests/Integration/Database/EloquentTouchParentWithGlobalScopeTest.php @@ -2,7 +2,7 @@ namespace Illuminate\Tests\Integration\Database\EloquentTouchParentWithGlobalScopeTest; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Eloquent\Model; use Illuminate\Tests\Integration\Database\DatabaseTestCase; diff --git a/tests/Integration/Database/QueryBuilderTest.php b/tests/Integration/Database/QueryBuilderTest.php index 3c917d7f78c2..9c824e60f5fe 100644 --- a/tests/Integration/Database/QueryBuilderTest.php +++ b/tests/Integration/Database/QueryBuilderTest.php @@ -2,7 +2,7 @@ namespace Illuminate\Tests\Integration\Database\EloquentBelongsToManyTest; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Illuminate\Tests\Integration\Database\DatabaseTestCase; diff --git a/tests/Integration/Http/ThrottleRequestsTest.php b/tests/Integration/Http/ThrottleRequestsTest.php index 5c9e21d8fca5..97785d2649e4 100644 --- a/tests/Integration/Http/ThrottleRequestsTest.php +++ b/tests/Integration/Http/ThrottleRequestsTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Integration\Http; use Throwable; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use Orchestra\Testbench\TestCase; use Illuminate\Support\Facades\Route; use Illuminate\Routing\Middleware\ThrottleRequests; diff --git a/tests/Integration/Http/ThrottleRequestsWithRedisTest.php b/tests/Integration/Http/ThrottleRequestsWithRedisTest.php index 3e8b9fdbb897..0d5ee7b95083 100644 --- a/tests/Integration/Http/ThrottleRequestsWithRedisTest.php +++ b/tests/Integration/Http/ThrottleRequestsWithRedisTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Integration\Http; use Throwable; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use Orchestra\Testbench\TestCase; use Illuminate\Support\Facades\Route; use Illuminate\Routing\Middleware\ThrottleRequestsWithRedis; diff --git a/tests/Integration/Mail/Fixtures/timestamp.blade.php b/tests/Integration/Mail/Fixtures/timestamp.blade.php index 774e558b2f98..937a8799afd3 100644 --- a/tests/Integration/Mail/Fixtures/timestamp.blade.php +++ b/tests/Integration/Mail/Fixtures/timestamp.blade.php @@ -1 +1 @@ -{{__('nom')}} {{ Illuminate\Support\Carbon::tomorrow()->diffForHumans() }} +{{__('nom')}} {{ Carbon\Carbon::tomorrow()->diffForHumans() }} diff --git a/tests/Integration/Mail/SendingMailWithLocaleTest.php b/tests/Integration/Mail/SendingMailWithLocaleTest.php index fc98034677b0..c96d20023f39 100644 --- a/tests/Integration/Mail/SendingMailWithLocaleTest.php +++ b/tests/Integration/Mail/SendingMailWithLocaleTest.php @@ -3,8 +3,8 @@ namespace Illuminate\Tests\Integration\Mail; use Mockery; +use Carbon\Carbon; use Illuminate\Mail\Mailable; -use Illuminate\Support\Carbon; use Orchestra\Testbench\TestCase; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\View; diff --git a/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php b/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php index 741249e51717..46234954b754 100644 --- a/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php +++ b/tests/Integration/Notifications/SendingNotificationsWithLocaleTest.php @@ -2,8 +2,8 @@ namespace Illuminate\Tests\Integration\Notifications; +use Carbon\Carbon; use Illuminate\Mail\Mailable; -use Illuminate\Support\Carbon; use Orchestra\Testbench\TestCase; use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\Event; diff --git a/tests/Integration/Routing/UrlSigningTest.php b/tests/Integration/Routing/UrlSigningTest.php index 7a04eed2edc7..4ea9211ff563 100644 --- a/tests/Integration/Routing/UrlSigningTest.php +++ b/tests/Integration/Routing/UrlSigningTest.php @@ -2,8 +2,8 @@ namespace Illuminate\Tests\Integration\Routing; +use Carbon\Carbon; use Illuminate\Http\Request; -use Illuminate\Support\Carbon; use Orchestra\Testbench\TestCase; use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\Route; diff --git a/tests/Notifications/NotificationSlackChannelTest.php b/tests/Notifications/NotificationSlackChannelTest.php index 9903b9cc90ae..96495d80055e 100644 --- a/tests/Notifications/NotificationSlackChannelTest.php +++ b/tests/Notifications/NotificationSlackChannelTest.php @@ -179,7 +179,7 @@ public function toSlack($notifiable) ->to('#ghost-talk') ->content('Content') ->attachment(function ($attachment) { - $timestamp = Mockery::mock(\Illuminate\Support\Carbon::class); + $timestamp = Mockery::mock(\Carbon\Carbon::class); $timestamp->shouldReceive('getTimestamp')->andReturn(1234567890); $attachment->title('Laravel', 'https://laravel.com') ->content('Attachment Content') @@ -206,7 +206,7 @@ public function toSlack($notifiable) ->to('#ghost-talk') ->content('Content') ->attachment(function ($attachment) { - $timestamp = Mockery::mock(\Illuminate\Support\Carbon::class); + $timestamp = Mockery::mock(\Carbon\Carbon::class); $timestamp->shouldReceive('getTimestamp')->andReturn(1234567890); $attachment->title('Laravel', 'https://laravel.com') ->content('Attachment Content') diff --git a/tests/Queue/QueueDatabaseQueueIntegrationTest.php b/tests/Queue/QueueDatabaseQueueIntegrationTest.php index f4fa2dd327dd..495ea7848aa5 100644 --- a/tests/Queue/QueueDatabaseQueueIntegrationTest.php +++ b/tests/Queue/QueueDatabaseQueueIntegrationTest.php @@ -2,7 +2,7 @@ namespace Illuminate\Tests\Queue; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Container\Container; use Illuminate\Queue\DatabaseQueue; diff --git a/tests/Queue/QueueRedisQueueTest.php b/tests/Queue/QueueRedisQueueTest.php index 0ad436ff3042..99cc844de580 100644 --- a/tests/Queue/QueueRedisQueueTest.php +++ b/tests/Queue/QueueRedisQueueTest.php @@ -42,7 +42,7 @@ public function testDelayedPushProperlyPushesJobOntoRedis() public function testDelayedPushWithDateTimeProperlyPushesJobOntoRedis() { - $date = \Illuminate\Support\Carbon::now(); + $date = \Carbon\Carbon::now(); $queue = $this->getMockBuilder('Illuminate\Queue\RedisQueue')->setMethods(['availableAt', 'getRandomId'])->setConstructorArgs([$redis = m::mock('Illuminate\Contracts\Redis\Factory'), 'default'])->getMock(); $queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo')); $queue->expects($this->once())->method('availableAt')->with($date)->will($this->returnValue(2)); diff --git a/tests/Queue/QueueSqsQueueTest.php b/tests/Queue/QueueSqsQueueTest.php index 36637ff47c3d..c1d8e04b9fa5 100755 --- a/tests/Queue/QueueSqsQueueTest.php +++ b/tests/Queue/QueueSqsQueueTest.php @@ -85,7 +85,7 @@ public function testPopProperlyHandlesEmptyMessage() public function testDelayedPushWithDateTimeProperlyPushesJobOntoSqs() { - $now = \Illuminate\Support\Carbon::now(); + $now = \Carbon\Carbon::now(); $queue = $this->getMockBuilder('Illuminate\Queue\SqsQueue')->setMethods(['createPayload', 'secondsUntil', 'getQueue'])->setConstructorArgs([$this->sqs, $this->queueName, $this->account])->getMock(); $queue->expects($this->once())->method('createPayload')->with($this->mockedJob, $this->mockedData)->will($this->returnValue($this->mockedPayload)); $queue->expects($this->once())->method('secondsUntil')->with($now)->will($this->returnValue(5)); diff --git a/tests/Queue/QueueWorkerTest.php b/tests/Queue/QueueWorkerTest.php index e0bd890edd67..33cfc8f7a3bb 100755 --- a/tests/Queue/QueueWorkerTest.php +++ b/tests/Queue/QueueWorkerTest.php @@ -3,8 +3,8 @@ namespace Illuminate\Tests\Queue; use Mockery; +use Carbon\Carbon; use RuntimeException; -use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Container\Container; use Illuminate\Queue\WorkerOptions; diff --git a/tests/Queue/RedisQueueIntegrationTest.php b/tests/Queue/RedisQueueIntegrationTest.php index 5264ab171473..8fa66679c73d 100644 --- a/tests/Queue/RedisQueueIntegrationTest.php +++ b/tests/Queue/RedisQueueIntegrationTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Queue; use Mockery as m; -use Illuminate\Support\Carbon; +use Carbon\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Queue\RedisQueue; use Illuminate\Container\Container; diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index 620307a9af97..11aa7b74db27 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -4,8 +4,8 @@ use stdClass; use ArrayObject; +use Carbon\Carbon; use Illuminate\Support\Arr; -use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Support\Collection; diff --git a/tests/Support/SupportCarbonTest.php b/tests/Support/SupportCarbonTest.php index d37420424e9d..c3b6f2649015 100644 --- a/tests/Support/SupportCarbonTest.php +++ b/tests/Support/SupportCarbonTest.php @@ -3,15 +3,15 @@ namespace Illuminate\Tests\Support; use DateTime; +use Carbon\Carbon; use DateTimeInterface; -use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Carbon\Carbon as BaseCarbon; class SupportCarbonTest extends TestCase { /** - * @var \Illuminate\Support\Carbon + * @var \Carbon\Carbon */ protected $now; diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 98b7fee0c04d..37069121cb36 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -4,9 +4,9 @@ use DateTime; use Mockery as m; +use Carbon\Carbon; use DateTimeImmutable; use Illuminate\Support\Arr; -use Illuminate\Support\Carbon; use PHPUnit\Framework\TestCase; use Illuminate\Validation\Validator; use Illuminate\Validation\Rules\Exists; diff --git a/tests/bootstrap.php b/tests/bootstrap.php index bc3941498e01..1b463b11b9d0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,7 +14,7 @@ require __DIR__.'/../vendor/autoload.php'; -use Illuminate\Support\Carbon; +use Carbon\Carbon; /* |--------------------------------------------------------------------------