ITimeFactory.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  6. * SPDX-License-Identifier: AGPL-3.0-only
  7. */
  8. namespace OCP\AppFramework\Utility;
  9. use Psr\Clock\ClockInterface;
  10. /**
  11. * Use this to get a timestamp or DateTime object in code to remain testable
  12. *
  13. * @since 8.0.0
  14. * @since 27.0.0 Extends the \Psr\Clock\ClockInterface interface
  15. * @ref https://www.php-fig.org/psr/psr-20/#21-clockinterface
  16. */
  17. interface ITimeFactory extends ClockInterface {
  18. /**
  19. * @return int the result of a call to time()
  20. * @since 8.0.0
  21. */
  22. public function getTime(): int;
  23. /**
  24. * @param string $time
  25. * @param \DateTimeZone|null $timezone
  26. * @return \DateTime
  27. * @since 15.0.0
  28. */
  29. public function getDateTime(string $time = 'now', ?\DateTimeZone $timezone = null): \DateTime;
  30. /**
  31. * @param \DateTimeZone $timezone
  32. * @return static
  33. * @since 26.0.0
  34. */
  35. public function withTimeZone(\DateTimeZone $timezone): static;
  36. /**
  37. * @param string|null $timezone
  38. * @return \DateTimeZone Requested timezone if provided, UTC otherwise
  39. * @throws \Exception
  40. * @since 29.0.0
  41. */
  42. public function getTimeZone(?string $timezone = null): \DateTimeZone;
  43. }