IDateTimeFormatter.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCP;
  8. /**
  9. * Interface IDateTimeFormatter
  10. *
  11. * @since 8.0.0
  12. */
  13. interface IDateTimeFormatter {
  14. /**
  15. * Formats the date of the given timestamp
  16. *
  17. * @param int|\DateTime $timestamp
  18. * @param string $format Either 'full', 'long', 'medium' or 'short'
  19. * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014'
  20. * long: e.g. 'MMMM d, y' => 'August 20, 2014'
  21. * medium: e.g. 'MMM d, y' => 'Aug 20, 2014'
  22. * short: e.g. 'M/d/yy' => '8/20/14'
  23. * The exact format is dependent on the language
  24. * @param \DateTimeZone|null $timeZone The timezone to use
  25. * @param \OCP\IL10N|null $l The locale to use
  26. * @return string Formatted date string
  27. * @since 8.0.0
  28. */
  29. public function formatDate($timestamp, $format = 'long', ?\DateTimeZone $timeZone = null, ?\OCP\IL10N $l = null);
  30. /**
  31. * Formats the date of the given timestamp
  32. *
  33. * @param int|\DateTime $timestamp
  34. * @param string $format Either 'full', 'long', 'medium' or 'short'
  35. * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014'
  36. * long: e.g. 'MMMM d, y' => 'August 20, 2014'
  37. * medium: e.g. 'MMM d, y' => 'Aug 20, 2014'
  38. * short: e.g. 'M/d/yy' => '8/20/14'
  39. * The exact format is dependent on the language
  40. * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable
  41. * @param \DateTimeZone|null $timeZone The timezone to use
  42. * @param \OCP\IL10N|null $l The locale to use
  43. * @return string Formatted relative date string
  44. * @since 8.0.0
  45. */
  46. public function formatDateRelativeDay($timestamp, $format = 'long', ?\DateTimeZone $timeZone = null, ?\OCP\IL10N $l = null);
  47. /**
  48. * Gives the relative date of the timestamp
  49. * Only works for past dates
  50. *
  51. * @param int|\DateTime $timestamp
  52. * @param int|\DateTime|null $baseTimestamp Timestamp to compare $timestamp against, defaults to current time
  53. * @param \OCP\IL10N|null $l The locale to use
  54. * @return string Dates returned are:
  55. * < 1 month => Today, Yesterday, n days ago
  56. * < 13 month => last month, n months ago
  57. * >= 13 month => last year, n years ago
  58. * @since 8.0.0
  59. */
  60. public function formatDateSpan($timestamp, $baseTimestamp = null, ?\OCP\IL10N $l = null);
  61. /**
  62. * Formats the time of the given timestamp
  63. *
  64. * @param int|\DateTime $timestamp
  65. * @param string $format Either 'full', 'long', 'medium' or 'short'
  66. * full: e.g. 'h:mm:ss a zzzz' => '11:42:13 AM GMT+0:00'
  67. * long: e.g. 'h:mm:ss a z' => '11:42:13 AM GMT'
  68. * medium: e.g. 'h:mm:ss a' => '11:42:13 AM'
  69. * short: e.g. 'h:mm a' => '11:42 AM'
  70. * The exact format is dependent on the language
  71. * @param \DateTimeZone|null $timeZone The timezone to use
  72. * @param \OCP\IL10N|null $l The locale to use
  73. * @return string Formatted time string
  74. * @since 8.0.0
  75. */
  76. public function formatTime($timestamp, $format = 'medium', ?\DateTimeZone $timeZone = null, ?\OCP\IL10N $l = null);
  77. /**
  78. * Gives the relative past time of the timestamp
  79. *
  80. * @param int|\DateTime $timestamp
  81. * @param int|\DateTime|null $baseTimestamp Timestamp to compare $timestamp against, defaults to current time
  82. * @param \OCP\IL10N|null $l The locale to use
  83. * @return string Dates returned are:
  84. * < 60 sec => seconds ago
  85. * < 1 hour => n minutes ago
  86. * < 1 day => n hours ago
  87. * < 1 month => Yesterday, n days ago
  88. * < 13 month => last month, n months ago
  89. * >= 13 month => last year, n years ago
  90. * @since 8.0.0
  91. */
  92. public function formatTimeSpan($timestamp, $baseTimestamp = null, ?\OCP\IL10N $l = null);
  93. /**
  94. * Formats the date and time of the given timestamp
  95. *
  96. * @param int|\DateTime $timestamp
  97. * @param string $formatDate See formatDate() for description
  98. * @param string $formatTime See formatTime() for description
  99. * @param \DateTimeZone|null $timeZone The timezone to use
  100. * @param \OCP\IL10N|null $l The locale to use
  101. * @return string Formatted date and time string
  102. * @since 8.0.0
  103. */
  104. public function formatDateTime($timestamp, $formatDate = 'long', $formatTime = 'medium', ?\DateTimeZone $timeZone = null, ?\OCP\IL10N $l = null);
  105. /**
  106. * Formats the date and time of the given timestamp
  107. *
  108. * @param int|\DateTime $timestamp
  109. * @param string $formatDate See formatDate() for description
  110. * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable
  111. * @param string $formatTime See formatTime() for description
  112. * @param \DateTimeZone|null $timeZone The timezone to use
  113. * @param \OCP\IL10N|null $l The locale to use
  114. * @return string Formatted relative date and time string
  115. * @since 8.0.0
  116. */
  117. public function formatDateTimeRelativeDay($timestamp, $formatDate = 'long', $formatTime = 'medium', ?\DateTimeZone $timeZone = null, ?\OCP\IL10N $l = null);
  118. }