Debian Codegraph @

lib/3rdParty/composer/illuminate/support/Carbon.php

raw symbols SCIP
1 <?php
2
3 namespace Illuminate\Support;
4
5 use Carbon\Carbon as BaseCarbon;
6 use Carbon\CarbonImmutable as BaseCarbonImmutable;
7 use Illuminate\Support\Traits\Conditionable;
8 use Illuminate\Support\Traits\Dumpable;
9 use Ramsey\Uuid\Uuid;
10 use Symfony\Component\Uid\Ulid;
11
12 class Carbon extends BaseCarbon
13 {
14 use Conditionable, Dumpable;
15
16 /**
17 * {@inheritdoc}
18 */
19 public static function setTestNow(mixed $testNow = null): void
20 {
21 BaseCarbon::setTestNow($testNow);
22 BaseCarbonImmutable::setTestNow($testNow);
23 }
24
25 /**
26 * Create a Carbon instance from a given ordered UUID or ULID.
27 */
28 public static function createFromId(Uuid|Ulid|string $id): static
29 {
30 if (is_string($id)) {
31 $id = Ulid::isValid($id) ? Ulid::fromString($id) : Uuid::fromString($id);
32 }
33
34 return static::createFromInterface($id->getDateTime());
35 }
36
37 /**
38 * Get the current date / time plus a given amount of time.
39 */
40 public function plus(
41 int $years = 0,
42 int $months = 0,
43 int $weeks = 0,
44 int $days = 0,
45 int $hours = 0,
46 int $minutes = 0,
47 int $seconds = 0,
48 int $microseconds = 0
49 ): static {
50 return $this->add("
51 $years years $months months $weeks weeks $days days
52 $hours hours $minutes minutes $seconds seconds $microseconds microseconds
53 ");
54 }
55
56 /**
57 * Get the current date / time minus a given amount of time.
58 */
59 public function minus(
60 int $years = 0,
61 int $months = 0,
62 int $weeks = 0,
63 int $days = 0,
64 int $hours = 0,
65 int $minutes = 0,
66 int $seconds = 0,
67 int $microseconds = 0
68 ): static {
69 return $this->sub("
70 $years years $months months $weeks weeks $days days
71 $hours hours $minutes minutes $seconds seconds $microseconds microseconds
72 ");
73 }
74 }