IDateTimeFormatter.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCP;
  24. /**
  25. * Interface IDateTimeFormatter
  26. *
  27. * @package OCP
  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 $timeZone The timezone to use
  42. * @param \OCP\IL10N $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 $timeZone The timezone to use
  59. * @param \OCP\IL10N $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 $baseTimestamp Timestamp to compare $timestamp against, defaults to current time
  70. * @return string Dates returned are:
  71. * < 1 month => Today, Yesterday, n days ago
  72. * < 13 month => last month, n months ago
  73. * >= 13 month => last year, n years ago
  74. * @param \OCP\IL10N $l The locale to use
  75. * @return string Formatted date span
  76. * @since 8.0.0
  77. */
  78. public function formatDateSpan($timestamp, $baseTimestamp = null, \OCP\IL10N $l = null);
  79. /**
  80. * Formats the time of the given timestamp
  81. *
  82. * @param int|\DateTime $timestamp
  83. * @param string $format Either 'full', 'long', 'medium' or 'short'
  84. * full: e.g. 'h:mm:ss a zzzz' => '11:42:13 AM GMT+0:00'
  85. * long: e.g. 'h:mm:ss a z' => '11:42:13 AM GMT'
  86. * medium: e.g. 'h:mm:ss a' => '11:42:13 AM'
  87. * short: e.g. 'h:mm a' => '11:42 AM'
  88. * The exact format is dependent on the language
  89. * @param \DateTimeZone $timeZone The timezone to use
  90. * @param \OCP\IL10N $l The locale to use
  91. * @return string Formatted time string
  92. * @since 8.0.0
  93. */
  94. public function formatTime($timestamp, $format = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null);
  95. /**
  96. * Gives the relative past time of the timestamp
  97. *
  98. * @param int|\DateTime $timestamp
  99. * @param int|\DateTime $baseTimestamp Timestamp to compare $timestamp against, defaults to current time
  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. * @param \OCP\IL10N $l The locale to use
  108. * @return string Formatted time span
  109. * @since 8.0.0
  110. */
  111. public function formatTimeSpan($timestamp, $baseTimestamp = null, \OCP\IL10N $l = null);
  112. /**
  113. * Formats the date and time of the given timestamp
  114. *
  115. * @param int|\DateTime $timestamp
  116. * @param string $formatDate See formatDate() for description
  117. * @param string $formatTime See formatTime() for description
  118. * @param \DateTimeZone $timeZone The timezone to use
  119. * @param \OCP\IL10N $l The locale to use
  120. * @return string Formatted date and time string
  121. * @since 8.0.0
  122. */
  123. public function formatDateTime($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null);
  124. /**
  125. * Formats the date and time of the given timestamp
  126. *
  127. * @param int|\DateTime $timestamp
  128. * @param string $formatDate See formatDate() for description
  129. * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable
  130. * @param string $formatTime See formatTime() for description
  131. * @param \DateTimeZone $timeZone The timezone to use
  132. * @param \OCP\IL10N $l The locale to use
  133. * @return string Formatted relative date and time string
  134. * @since 8.0.0
  135. */
  136. public function formatDateTimeRelativeDay($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null);
  137. }