Skip to content

Commit 85e21ee

Browse files
authored
Merge pull request #222 from Kharhamel/datetimeThrows
added @throws DatetimeException in DateTime and DateTimeImmutable
2 parents 1bcce53 + 9c5aaf4 commit 85e21ee

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/DateTime.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ private static function createFromRegular(\DateTime $datetime): self
2020
* @param string $format
2121
* @param string $time
2222
* @param DateTimeZone|null $timezone
23+
* @throws DatetimeException
2324
*/
2425
public static function createFromFormat($format, $time, $timezone = null): self
2526
{
@@ -34,6 +35,7 @@ public static function createFromFormat($format, $time, $timezone = null): self
3435
* @param DateTimeInterface $datetime2 The date to compare to.
3536
* @param boolean $absolute [optional] Whether to return absolute difference.
3637
* @return DateInterval The DateInterval object representing the difference between the two dates.
38+
* @throws DatetimeException
3739
*/
3840
public function diff($datetime2, $absolute = false): DateInterval
3941
{
@@ -48,6 +50,7 @@ public function diff($datetime2, $absolute = false): DateInterval
4850
/**
4951
* @param string $modify A date/time string. Valid formats are explained in <a href="https://secure.php.net/manual/en/datetime.formats.php">Date and Time Formats</a>.
5052
* @return DateTime Returns the DateTime object for method chaining.
53+
* @throws DatetimeException
5154
*/
5255
public function modify($modify): self
5356
{
@@ -64,6 +67,7 @@ public function modify($modify): self
6467
* @param int $month
6568
* @param int $day
6669
* @return DateTime
70+
* @throws DatetimeException
6771
*/
6872
public function setDate($year, $month, $day): self
6973
{

lib/DateTimeImmutable.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private static function createFromRegular(\DateTimeImmutable $datetime): self
4747
* @param string $format
4848
* @param string $time
4949
* @param DateTimeZone|null $timezone
50+
* @throws DatetimeException
5051
*/
5152
public static function createFromFormat($format, $time, $timezone = null): self
5253
{
@@ -60,6 +61,7 @@ public static function createFromFormat($format, $time, $timezone = null): self
6061
/**
6162
* @param string $format
6263
* @return string
64+
* @throws DatetimeException
6365
*/
6466
public function format($format): string
6567
{
@@ -75,6 +77,7 @@ public function format($format): string
7577
* @param DateTimeInterface $datetime2
7678
* @param bool $absolute
7779
* @return DateInterval
80+
* @throws DatetimeException
7881
*/
7982
public function diff($datetime2, $absolute = false): DateInterval
8083
{
@@ -89,6 +92,7 @@ public function diff($datetime2, $absolute = false): DateInterval
8992
/**
9093
* @param string $modify
9194
* @return DateTimeImmutable
95+
* @throws DatetimeException
9296
*/
9397
public function modify($modify): self
9498
{
@@ -105,6 +109,7 @@ public function modify($modify): self
105109
* @param int $month
106110
* @param int $day
107111
* @return DateTimeImmutable
112+
* @throws DatetimeException
108113
*/
109114
public function setDate($year, $month, $day): self
110115
{
@@ -121,6 +126,7 @@ public function setDate($year, $month, $day): self
121126
* @param int $week
122127
* @param int $day
123128
* @return DateTimeImmutable
129+
* @throws DatetimeException
124130
*/
125131
public function setISODate($year, $week, $day = 1): self
126132
{
@@ -138,6 +144,7 @@ public function setISODate($year, $week, $day = 1): self
138144
* @param int $second
139145
* @param int $microseconds
140146
* @return DateTimeImmutable
147+
* @throws DatetimeException
141148
*/
142149
public function setTime($hour, $minute, $second = 0, $microseconds = 0): self
143150
{
@@ -152,6 +159,7 @@ public function setTime($hour, $minute, $second = 0, $microseconds = 0): self
152159
/**
153160
* @param int $unixtimestamp
154161
* @return DateTimeImmutable
162+
* @throws DatetimeException
155163
*/
156164
public function setTimestamp($unixtimestamp): self
157165
{
@@ -166,6 +174,7 @@ public function setTimestamp($unixtimestamp): self
166174
/**
167175
* @param DateTimeZone $timezone
168176
* @return DateTimeImmutable
177+
* @throws DatetimeException
169178
*/
170179
public function setTimezone($timezone): self
171180
{
@@ -180,6 +189,7 @@ public function setTimezone($timezone): self
180189
/**
181190
* @param DateInterval $interval
182191
* @return DateTimeImmutable
192+
* @throws DatetimeException
183193
*/
184194
public function sub($interval): self
185195
{
@@ -191,6 +201,9 @@ public function sub($interval): self
191201
return self::createFromRegular($result);
192202
}
193203

204+
/**
205+
* @throws DatetimeException
206+
*/
194207
public function getOffset(): int
195208
{
196209
/** @var int|false $result */

0 commit comments

Comments
 (0)