You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IDateTimeFormatter.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. * @package OCP
  29. * @since 8.0.0
  30. */
  31. interface IDateTimeFormatter {
  32. /**
  33. * Formats the date of the given timestamp
  34. *
  35. * @param int|\DateTime $timestamp
  36. * @param string $format Either 'full', 'long', 'medium' or 'short'
  37. * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014'
  38. * long: e.g. 'MMMM d, y' => 'August 20, 2014'
  39. * medium: e.g. 'MMM d, y' => 'Aug 20, 2014'
  40. * short: e.g. 'M/d/yy' => '8/20/14'
  41. * The exact format is dependent on the language
  42. * @param \DateTimeZone|null $timeZone The timezone to use
  43. * @param \OCP\IL10N|null $l The locale to use
  44. * @return string Formatted date string
  45. * @since 8.0.0
  46. */
  47. public function formatDate($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null);
  48. /**
  49. * Formats the date of the given timestamp
  50. *
  51. * @param int|\DateTime $timestamp
  52. * @param string $format Either 'full', 'long', 'medium' or 'short'
  53. * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014'
  54. * long: e.g. 'MMMM d, y' => 'August 20, 2014'
  55. * medium: e.g. 'MMM d, y' => 'Aug 20, 2014'
  56. * short: e.g. 'M/d/yy' => '8/20/14'
  57. * The exact format is dependent on the language
  58. * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable
  59. * @param \DateTimeZone|null $timeZone The timezone to use
  60. * @param \OCP\IL10N|null $l The locale to use
  61. * @return string Formatted relative date string
  62. * @since 8.0.0
  63. */
  64. public function formatDateRelativeDay($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null);
  65. /**
  66. * Gives the relative date of the timestamp
  67. * Only works for past dates
  68. *
  69. * @param int|\DateTime $timestamp
  70. * @param int|\DateTime|null $baseTimestamp Timestamp to compare $timestamp against, defaults to current time
  71. * @param \OCP\IL10N|null $l The locale to use
  72. * @return string Dates returned are:
  73. * < 1 month => Today, Yesterday, n days ago
  74. * < 13 month => last month, n months ago
  75. * >= 13 month => last year, n years ago
  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|null $timeZone The timezone to use
  90. * @param \OCP\IL10N|null $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|null $baseTimestamp Timestamp to compare $timestamp against, defaults to current time
  100. * @param \OCP\IL10N|null $l The locale to use
  101. * @return string Dates returned are:
  102. * < 60 sec => seconds ago
  103. * < 1 hour => n minutes ago
  104. * < 1 day => n hours ago
  105. * < 1 month => Yesterday, n days ago
  106. * < 13 month => last month, n months ago
  107. * >= 13 month => last year, n years ago
  108. * @since 8.0.0
  109. */
  110. public function formatTimeSpan($timestamp, $baseTimestamp = null, \OCP\IL10N $l = null);
  111. /**
  112. * Formats the date and time of the given timestamp
  113. *
  114. * @param int|\DateTime $timestamp
  115. * @param string $formatDate See formatDate() for description
  116. * @param string $formatTime See formatTime() for description
  117. * @param \DateTimeZone|null $timeZone The timezone to use
  118. * @param \OCP\IL10N|null $l The locale to use
  119. * @return string Formatted date and time string
  120. * @since 8.0.0
  121. */
  122. public function formatDateTime($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null);
  123. /**
  124. * Formats the date and time of the given timestamp
  125. *
  126. * @param int|\DateTime $timestamp
  127. * @param string $formatDate See formatDate() for description
  128. * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable
  129. * @param string $formatTime See formatTime() for description
  130. * @param \DateTimeZone|null $timeZone The timezone to use
  131. * @param \OCP\IL10N|null $l The locale to use
  132. * @return string Formatted relative date and time string
  133. * @since 8.0.0
  134. */
  135. public function formatDateTimeRelativeDay($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null);
  136. }