1
0

IDateTimeFormatter.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCP;
  25. /**
  26. * Interface IDateTimeFormatter
  27. *
  28. * @since 8.0.0
  29. */
  30. interface IDateTimeFormatter {
  31. /**
  32. * Formats the date of the given timestamp
  33. *
  34. * @param int|\DateTime $timestamp
  35. * @param string $format Either 'full', 'long', 'medium' or 'short'
  36. * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014'
  37. * long: e.g. 'MMMM d, y' => 'August 20, 2014'
  38. * medium: e.g. 'MMM d, y' => 'Aug 20, 2014'
  39. * short: e.g. 'M/d/yy' => '8/20/14'
  40. * The exact format is dependent on the language
  41. * @param \DateTimeZone|null $timeZone The timezone to use
  42. * @param \OCP\IL10N|null $l The locale to use
  43. * @return string Formatted date string
  44. * @since 8.0.0
  45. */
  46. public function formatDate($timestamp, $format = 'long', ?\DateTimeZone $timeZone = null, ?\OCP\IL10N $l = null);
  47. /**
  48. * Formats the date of the given timestamp
  49. *
  50. * @param int|\DateTime $timestamp
  51. * @param string $format Either 'full', 'long', 'medium' or 'short'
  52. * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014'
  53. * long: e.g. 'MMMM d, y' => 'August 20, 2014'
  54. * medium: e.g. 'MMM d, y' => 'Aug 20, 2014'
  55. * short: e.g. 'M/d/yy' => '8/20/14'
  56. * The exact format is dependent on the language
  57. * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable
  58. * @param \DateTimeZone|null $timeZone The timezone to use
  59. * @param \OCP\IL10N|null $l The locale to use
  60. * @return string Formatted relative date string
  61. * @since 8.0.0
  62. */
  63. public function formatDateRelativeDay($timestamp, $format = 'long', ?\DateTimeZone $timeZone = null, ?\OCP\IL10N $l = null);
  64. /**
  65. * Gives the relative date of the timestamp
  66. * Only works for past dates
  67. *
  68. * @param int|\DateTime $timestamp
  69. * @param int|\DateTime|null $baseTimestamp Timestamp to compare $timestamp against, defaults to current time
  70. * @param \OCP\IL10N|null $l The locale to use
  71. * @return string Dates returned are:
  72. * < 1 month => Today, Yesterday, n days ago
  73. * < 13 month => last month, n months ago
  74. * >= 13 month => last year, n years ago
  75. * @since 8.0.0
  76. */
  77. public function formatDateSpan($timestamp, $baseTimestamp = null, ?\OCP\IL10N $l = null);
  78. /**
  79. * Formats the time of the given timestamp
  80. *
  81. * @param int|\DateTime $timestamp
  82. * @param string $format Either 'full', 'long', 'medium' or 'short'
  83. * full: e.g. 'h:mm:ss a zzzz' => '11:42:13 AM GMT+0:00'
  84. * long: e.g. 'h:mm:ss a z' => '11:42:13 AM GMT'
  85. * medium: e.g. 'h:mm:ss a' => '11:42:13 AM'
  86. * short: e.g. 'h:mm a' => '11:42 AM'
  87. * The exact format is dependent on the language
  88. * @param \DateTimeZone|null $timeZone The timezone to use
  89. * @param \OCP\IL10N|null $l The locale to use
  90. * @return string Formatted time string
  91. * @since 8.0.0
  92. */
  93. public function formatTime($timestamp, $format = 'medium', ?\DateTimeZone $timeZone = null, ?\OCP\IL10N $l = null);
  94. /**
  95. * Gives the relative past time of the timestamp
  96. *
  97. * @param int|\DateTime $timestamp
  98. * @param int|\DateTime|null $baseTimestamp Timestamp to compare $timestamp against, defaults to current time
  99. * @param \OCP\IL10N|null $l The locale to use
  100. * @return string Dates returned are:
  101. * < 60 sec => seconds ago
  102. * < 1 hour => n minutes ago
  103. * < 1 day => n hours ago
  104. * < 1 month => Yesterday, n days ago
  105. * < 13 month => last month, n months ago
  106. * >= 13 month => last year, n years ago
  107. * @since 8.0.0
  108. */
  109. public function formatTimeSpan($timestamp, $baseTimestamp = null, ?\OCP\IL10N $l = null);
  110. /**
  111. * Formats the date and time of the given timestamp
  112. *
  113. * @param int|\DateTime $timestamp
  114. * @param string $formatDate See formatDate() for description
  115. * @param string $formatTime See formatTime() for description
  116. * @param \DateTimeZone|null $timeZone The timezone to use
  117. * @param \OCP\IL10N|null $l The locale to use
  118. * @return string Formatted date and time string
  119. * @since 8.0.0
  120. */
  121. public function formatDateTime($timestamp, $formatDate = 'long', $formatTime = 'medium', ?\DateTimeZone $timeZone = null, ?\OCP\IL10N $l = null);
  122. /**
  123. * Formats the date and time of the given timestamp
  124. *
  125. * @param int|\DateTime $timestamp
  126. * @param string $formatDate See formatDate() for description
  127. * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable
  128. * @param string $formatTime See formatTime() for description
  129. * @param \DateTimeZone|null $timeZone The timezone to use
  130. * @param \OCP\IL10N|null $l The locale to use
  131. * @return string Formatted relative date and time string
  132. * @since 8.0.0
  133. */
  134. public function formatDateTimeRelativeDay($timestamp, $formatDate = 'long', $formatTime = 'medium', ?\DateTimeZone $timeZone = null, ?\OCP\IL10N $l = null);
  135. }