ITimeFactory.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. }