ITimeFactory.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2022, Joas Schilling <coding@schilljs.com>
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. *
  7. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCP\AppFramework\Utility;
  27. use Psr\Clock\ClockInterface;
  28. /**
  29. * Use this to get a timestamp or DateTime object in code to remain testable
  30. *
  31. * @since 8.0.0
  32. * @since 27.0.0 Extends the \Psr\Clock\ClockInterface interface
  33. * @ref https://www.php-fig.org/psr/psr-20/#21-clockinterface
  34. */
  35. interface ITimeFactory extends ClockInterface {
  36. /**
  37. * @return int the result of a call to time()
  38. * @since 8.0.0
  39. */
  40. public function getTime(): int;
  41. /**
  42. * @param string $time
  43. * @param \DateTimeZone|null $timezone
  44. * @return \DateTime
  45. * @since 15.0.0
  46. */
  47. public function getDateTime(string $time = 'now', \DateTimeZone $timezone = null): \DateTime;
  48. /**
  49. * @param \DateTimeZone $timezone
  50. * @return static
  51. * @since 26.0.0
  52. */
  53. public function withTimeZone(\DateTimeZone $timezone): static;
  54. /**
  55. * @param string|null $timezone
  56. * @return \DateTimeZone Requested timezone if provided, UTC otherwise
  57. * @throws \Exception
  58. * @since 29.0.0
  59. */
  60. public function getTimeZone(?string $timezone = null): \DateTimeZone;
  61. }