Skip to content

Commit 873eac7

Browse files
committed
Document Offset
1 parent 61f872d commit 873eac7

23 files changed

+2283
-432
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": "^8.1.17|^8.2.4",
20-
"hereldar/results": "^0.6"
20+
"hereldar/results": "^0.7"
2121
},
2222
"require-dev": {
2323
"phpunit/phpunit": "^10.1"

docs/reference/date-time.md

Lines changed: 72 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Obtains the current date-time from the system clock in the
145145
specified time-zone. If no time-zone is specified, the `UTC`
146146
time-zone will be used.
147147

148-
**Throws:**
148+
**Exceptions:**
149149

150150
`TimeZoneException` if the time-zone name cannot be found
151151

@@ -191,7 +191,7 @@ their Unix epoch value (00:00:00 UTC on 1 January 1970).
191191

192192
`$timeZone` the time-zone name or the offset from UTC/Greenwich
193193

194-
**Throws:**
194+
**Exceptions:**
195195

196196
`OutOfRangeException` if the value of any unit is out of range
197197

@@ -226,13 +226,13 @@ if something went wrong.
226226

227227
`$timeZone` the time-zone name or the offset from UTC/Greenwich
228228

229-
**Returns:**
229+
**Return Values:**
230230

231-
`Ok<string>` if no error was found
231+
`Ok<string>` if no error is found
232232

233-
`Error<ParseException>` if something went wrong
233+
`Error<ParseException>` if the text cannot be parsed
234234

235-
**Throws:**
235+
**Exceptions:**
236236

237237
`InvalidArgumentException` if an empty list of formats is passed
238238

@@ -251,7 +251,7 @@ date-time formats (e.g. `'Fri, 17 Feb 2023 17:30:09 UTC'`).
251251
The date-time is returned directly if no error is found,
252252
otherwise an exception is thrown.
253253

254-
**Throws:**
254+
**Exceptions:**
255255

256256
`ParseException` if the text cannot be parsed
257257

@@ -268,7 +268,7 @@ date-time formats (e.g. `'Fri, 17 Feb 2023 17:30:09 GMT'`).
268268
The date-time is returned directly if no error is found,
269269
otherwise an exception is thrown.
270270

271-
**Throws:**
271+
**Exceptions:**
272272

273273
`ParseException` if the text cannot be parsed
274274

@@ -294,7 +294,7 @@ It is possible to parse texts with milliseconds (e.g.
294294
The date-time is returned directly if no error is found,
295295
otherwise an exception is thrown.
296296

297-
**Throws:**
297+
**Exceptions:**
298298

299299
`ParseException` if the text cannot be parsed
300300

@@ -311,7 +311,7 @@ format (e.g. `'Fri, 17 Feb 2023 17:30:09 +0000'`).
311311
The date-time is returned directly if no error is found,
312312
otherwise an exception is thrown.
313313

314-
**Throws:**
314+
**Exceptions:**
315315

316316
`ParseException` if the text cannot be parsed
317317

@@ -337,7 +337,7 @@ It is possible to parse texts with milliseconds (e.g.
337337
The date-time is returned directly if no error is found,
338338
otherwise an exception is thrown.
339339

340-
**Throws:**
340+
**Exceptions:**
341341

342342
`ParseException` if the text cannot be parsed
343343

@@ -363,7 +363,7 @@ It is possible to parse texts with milliseconds (e.g.
363363
The date-time is returned directly if no error is found,
364364
otherwise an exception is thrown.
365365

366-
**Throws:**
366+
**Exceptions:**
367367

368368
`ParseException` if the text cannot be parsed
369369

@@ -427,11 +427,30 @@ The text is not returned directly, but a [result][php-results-doc]
427427
that will contain the text if no error was found, or an exception if
428428
something went wrong.
429429

430-
**Returns:**
430+
**Return Values:**
431431

432-
`Ok<string>` if no error was found
432+
`Ok<string>` if no error is found
433433

434-
`Error<FormatException>` if something went wrong
434+
`Error<FormatException>` if the format is incorrect
435+
436+
437+
### formatted
438+
439+
```php
440+
public function formatted(string $format = DateTime::ISO8601): string;
441+
```
442+
443+
Formats this date-time using the specified format.
444+
445+
If the format is not specified, the ISO 8601 date-time format
446+
will be used (`Y-m-d\TH:i:sp`).
447+
448+
The text is returned directly if no error is found, otherwise
449+
an exception is thrown.
450+
451+
**Exceptions:**
452+
453+
`FormatException` if the format is incorrect
435454

436455

437456
### toCookie
@@ -735,7 +754,7 @@ public function microsecondsSinceEpoch(): array;
735754
Returns the number of seconds and microseconds after the Unix
736755
epoch (00:00:00 UTC on 1 January 1970).
737756

738-
**Returns:**
757+
**Return Values:**
739758

740759
`array{0: int, 1: int}` the number of seconds and microseconds
741760

@@ -873,10 +892,12 @@ specify overflow and units other than years, months, days,
873892
hours, minutes, seconds and microseconds, since only the order
874893
of the seven first parameters is guaranteed.
875894

876-
**Throws:**
895+
**Exceptions:**
877896

878897
`InvalidArgumentException` if a `Period` is combined with some time units
879898

899+
`ArithmeticError` if any value exceeds the PHP limits for an integer
900+
880901

881902
### minus
882903

@@ -921,10 +942,12 @@ specify overflow and units other than years, months, days,
921942
hours, minutes, seconds and microseconds, since only the order
922943
of the seven first parameters is guaranteed.
923944

924-
**Throws:**
945+
**Exceptions:**
925946

926947
`InvalidArgumentException` if a `Period` is combined with some time units
927948

949+
`ArithmeticError` if any value exceeds the PHP limits for an integer
950+
928951

929952
### with
930953

@@ -962,7 +985,7 @@ day, hour, minute, second, microsecond and time-zone.
962985

963986
`$timeZone` the time-zone name or the offset from UTC/Greenwich
964987

965-
**Throws:**
988+
**Exceptions:**
966989

967990
`OutOfRangeException` if the value of any unit is out of range
968991

@@ -987,13 +1010,15 @@ public function add(
9871010
int $quarters = 0,
9881011
int $weeks = 0,
9891012
int $milliseconds = 0,
990-
): Ok;
1013+
): Ok|Error;
9911014
```
9921015

9931016
Makes a copy of this date-time with the specified amount of
9941017
years, months, days, hours, minutes, seconds and microseconds
995-
added. It works the same as the [plus()](#plus) method, but
996-
returns a [result][php-results-doc] instead of the new date-time.
1018+
added.
1019+
1020+
It works the same as the [plus()](#plus) method, but returns a
1021+
[result][php-results-doc] instead of the new date-time.
9971022

9981023
The result will contain the new date-time if no error was found,
9991024
or an exception if something went wrong.
@@ -1002,11 +1027,13 @@ However, if a `Period` is combined with any time unit, the
10021027
exception will not be captured, allowing it to be thrown
10031028
normally.
10041029

1005-
**Returns:**
1030+
**Return Values:**
10061031

1007-
`Ok<static>` if no error was found
1032+
`Ok<static>` if no error is found
10081033

1009-
**Throws:**
1034+
`Error<ArithmeticError>` if any value exceeds the PHP limits for an integer
1035+
1036+
**Exceptions:**
10101037

10111038
`InvalidArgumentException` if a `Period` is combined with some time units
10121039

@@ -1029,13 +1056,15 @@ public function subtract(
10291056
int $quarters = 0,
10301057
int $weeks = 0,
10311058
int $milliseconds = 0,
1032-
): Ok;
1059+
): Ok|Error;
10331060
```
10341061

10351062
Makes a copy of this date-time with the specified amount of
10361063
years, months, days, hours, minutes, seconds and microseconds
1037-
subtracted. It works the same as the [minus()](#minus) method, but
1038-
returns a [result][php-results-doc] instead of the new date-time.
1064+
subtracted.
1065+
1066+
It works the same as the [minus()](#minus) method, but returns
1067+
a [result][php-results-doc] instead of the new date-time.
10391068

10401069
The result will contain the new date-time if no error was found,
10411070
or an exception if something went wrong.
@@ -1044,11 +1073,13 @@ However, if a `Period` is combined with any time unit, the
10441073
exception will not be captured, allowing it to be thrown
10451074
normally.
10461075

1047-
**Returns:**
1076+
**Return Values:**
10481077

1049-
`Ok<static>` if no error was found
1078+
`Ok<static>` if no error is found
10501079

1051-
**Throws:**
1080+
`Error<ArithmeticError>` if any value exceeds the PHP limits for an integer
1081+
1082+
**Exceptions:**
10521083

10531084
`InvalidArgumentException` if a `Period` is combined with some time units
10541085

@@ -1068,10 +1099,11 @@ public function copy(
10681099
): Ok|Error;
10691100
```
10701101

1071-
Makes a copy of this date with the specified year, month, day,
1072-
hour, minute, second, microsecond and time-zone. It works the
1073-
same as the [with()](#with) method, but returns a [result][php-results-doc]
1074-
instead of the new date-time.
1102+
Makes a copy of this date-time with the specified year, month, day,
1103+
hour, minute, second, microsecond and time-zone.
1104+
1105+
It works the same as the [with()](#with) method, but returns a
1106+
[result][php-results-doc] instead of the new date-time.
10751107

10761108
The result will contain the new date-time if no error was found,
10771109
or an exception if something went wrong.
@@ -1094,11 +1126,13 @@ or an exception if something went wrong.
10941126

10951127
`$timeZone` the time-zone name or the offset from UTC/Greenwich
10961128

1097-
**Returns:**
1129+
**Return Values:**
1130+
1131+
`Ok<static>` if no error is found
10981132

1099-
`Ok<static>` if no error was found
1133+
`Error<OutOfRangeException>` if the value of any unit is out of range
11001134

1101-
`Error<OutOfRangeException|TimeZoneException>` if something went wrong
1135+
`Error<TimeZoneException>` if the time-zone name cannot be found
11021136

11031137

11041138
[php-results-doc]: https://hereldar.github.io/php-results/

0 commit comments

Comments
 (0)