|
6 | 6 |
|
7 | 7 | use DateTimeImmutable;
|
8 | 8 | use DateTimeInterface;
|
| 9 | +use DateTimeZone; |
9 | 10 | use Stringable;
|
| 11 | +use Throwable; |
10 | 12 | use function count;
|
11 | 13 | use function is_bool;
|
12 | 14 | use function is_float;
|
@@ -65,59 +67,68 @@ public static function fromHttpValue(Stringable|string $httpValue): self
|
65 | 67 |
|
66 | 68 | /**
|
67 | 69 | * Returns a new instance from an encoded byte sequence and an iterable of key-value parameters.
|
68 |
| - * |
69 |
| - * @param iterable<string,Value|DataType> $parameters |
70 | 70 | */
|
71 |
| - public static function fromEncodedByteSequence(Stringable|string $value, iterable $parameters = []): self |
| 71 | + public static function fromEncodedByteSequence(Stringable|string $value): self |
72 | 72 | {
|
73 |
| - return self::from(ByteSequence::fromEncoded($value), $parameters); |
| 73 | + return self::from(ByteSequence::fromEncoded($value)); |
74 | 74 | }
|
75 | 75 |
|
76 | 76 | /**
|
77 | 77 | * Returns a new instance from a decoded byte sequence and an iterable of key-value parameters.
|
78 |
| - * |
79 |
| - * @param iterable<string,Value|DataType> $parameters |
80 | 78 | */
|
81 |
| - public static function fromDecodedByteSequence(Stringable|string $value, iterable $parameters = []): self |
| 79 | + public static function fromDecodedByteSequence(Stringable|string $value): self |
82 | 80 | {
|
83 |
| - return self::from(ByteSequence::fromDecoded($value), $parameters); |
| 81 | + return self::from(ByteSequence::fromDecoded($value)); |
84 | 82 | }
|
85 | 83 |
|
86 | 84 | /**
|
87 | 85 | * Returns a new instance from a Token and an iterable of key-value parameters.
|
88 |
| - * |
89 |
| - * @param iterable<string,Value|DataType> $parameters |
90 | 86 | */
|
91 |
| - public static function fromToken(Stringable|string $value, iterable $parameters = []): self |
| 87 | + public static function fromToken(Stringable|string $value): self |
92 | 88 | {
|
93 |
| - return self::from(Token::fromString($value), $parameters); |
| 89 | + return self::from(Token::fromString($value)); |
94 | 90 | }
|
95 | 91 |
|
96 | 92 | /**
|
97 | 93 | * Returns a new instance from a timestamp and an iterable of key-value parameters.
|
98 |
| - * |
99 |
| - * @param iterable<string,Value|DataType> $parameters |
100 | 94 | */
|
101 |
| - public static function fromTimestamp(int $timestamp, iterable $parameters = []): self |
| 95 | + public static function fromTimestamp(int $timestamp): self |
102 | 96 | {
|
103 |
| - return self::from((new DateTimeImmutable())->setTimestamp($timestamp), $parameters); |
| 97 | + return self::from((new DateTimeImmutable())->setTimestamp($timestamp)); |
104 | 98 | }
|
105 | 99 |
|
106 | 100 | /**
|
107 | 101 | * Returns a new instance from a date format its date string representation and an iterable of key-value parameters.
|
108 | 102 | *
|
109 |
| - * @param iterable<string,Value|DataType> $parameters |
110 |
| - * |
111 |
| - * @throws SyntaxError if the fornat is |
| 103 | + * @throws SyntaxError if the format is invalid |
112 | 104 | */
|
113 |
| - public static function fromDateFormat(string $format, string $dateString, iterable $parameters = []): self |
| 105 | + public static function fromDateFormat(string $format, string $dateString): self |
114 | 106 | {
|
115 |
| - $date = DateTimeImmutable::createFromFormat($format, $dateString); |
116 |
| - if (false === $date) { |
| 107 | + $value = DateTimeImmutable::createFromFormat($format, $dateString); |
| 108 | + if (false === $value) { |
117 | 109 | throw new SyntaxError('The date notation `'.$dateString.'` is incompatible with the date format `'.$format.'`.');
|
118 | 110 | }
|
119 | 111 |
|
120 |
| - return self::from($date, $parameters); |
| 112 | + return self::from($value); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Returns a new instance from a string parsable by DateTimeImmutable constructor, an optional timezone and an iterable of key-value parameters. |
| 117 | + * |
| 118 | + * @throws SyntaxError if the format is invalid |
| 119 | + */ |
| 120 | + public static function fromDateString(string $dateString, DateTimeZone|string|null $timezone = null): self |
| 121 | + { |
| 122 | + $timezone ??= date_default_timezone_get(); |
| 123 | + if (!$timezone instanceof DateTimeZone) { |
| 124 | + try { |
| 125 | + $timezone = new DateTimeZone($timezone); |
| 126 | + } catch (Throwable $exception) { |
| 127 | + throw new SyntaxError('The timezone could not be instantiated.', 0, $exception); |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + return self::from(new DateTimeImmutable($dateString, $timezone)); |
121 | 132 | }
|
122 | 133 |
|
123 | 134 | /**
|
|
0 commit comments