Skip to content

Commit fe04b28

Browse files
authored
Merge pull request #11538 from nextcloud/enh/add-timezone-generator
enh(utility): add timezone generator method to ITimeFactory
2 parents 6416e0e + f76fc77 commit fe04b28

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

developer_manual/digging_deeper/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ Digging deeper
4444
deadlock
4545
phonenumberutil
4646
out_of_office
47+
time
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
=================
2+
Working with time
3+
=================
4+
5+
You can inject the ``\OCP\AppFramework\Utility\ITimeFactory`` which wraps commonly used time functions for easier testability.
6+
7+
Methods
8+
-------
9+
10+
The factory extends the ``\PSR\Clock\ClockInterface`` with the following methods:
11+
12+
.. code-block:: php
13+
14+
<?php
15+
16+
/**
17+
* @return int the result of a call to time()
18+
* @since 8.0.0
19+
*/
20+
public function getTime(): int;
21+
22+
/**
23+
* @param string $time
24+
* @param \DateTimeZone|null $timezone
25+
* @return \DateTime
26+
* @since 15.0.0
27+
*/
28+
public function getDateTime(string $time = 'now', \DateTimeZone $timezone = null): \DateTime;
29+
30+
/**
31+
* @param \DateTimeZone $timezone
32+
* @return static
33+
* @since 26.0.0
34+
*/
35+
public function withTimeZone(\DateTimeZone $timezone): static;
36+
37+
/**
38+
* @param string|null $timezone
39+
* @return \DateTimeZone Requested timezone if provided, UTC otherwise
40+
* @throws \Exception
41+
* @since 29.0.0
42+
*/
43+
public function getTimeZone(?string $timezone = null): \DateTimeZone;

0 commit comments

Comments
 (0)