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. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCP;
  23. /**
  24. * Interface IDateTimeFormatter
  25. *
  26. * @package OCP
  27. * @since 8.0.0
  28. */
  29. interface IDateTimeFormatter {
  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. * @param \DateTimeZone $timeZone The timezone to use
  41. * @param \OCP\IL10N $l The locale to use
  42. * @return string Formatted date string
  43. * @since 8.0.0
  44. */
  45. public function formatDate($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null);
  46. /**
  47. * Formats the date of the given timestamp
  48. *
  49. * @param int|\DateTime $timestamp
  50. * @param string $format Either 'full', 'long', 'medium' or 'short'
  51. * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014'
  52. * long: e.g. 'MMMM d, y' => 'August 20, 2014'
  53. * medium: e.g. 'MMM d, y' => 'Aug 20, 2014'
  54. * short: e.g. 'M/d/yy' => '8/20/14'
  55. * The exact format is dependent on the language
  56. * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable
  57. * @param \DateTimeZone $timeZone The timezone to use
  58. * @param \OCP\IL10N $l The locale to use
  59. * @return string Formatted relative date string
  60. * @since 8.0.0
  61. */
  62. public function formatDateRelativeDay($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null);
  63. /**
  64. * Gives the relative date of the timestamp
  65. * Only works for past dates
  66. *
  67. * @param int|\DateTime $timestamp
  68. * @param int|\DateTime $baseTimestamp Timestamp to compare $timestamp against, defaults to current time
  69. * @return string Dates returned are:
  70. * < 1 month => Today, Yesterday, n days ago
  71. * < 13 month => last month, n months ago
  72. * >= 13 month => last year, n years ago
  73. * @param \OCP\IL10N $l The locale to use
  74. * @return string Formatted date span
  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 $timeZone The timezone to use
  89. * @param \OCP\IL10N $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 $baseTimestamp Timestamp to compare $timestamp against, defaults to current time
  99. * @return string Dates returned are:
  100. * < 60 sec => seconds ago
  101. * < 1 hour => n minutes ago
  102. * < 1 day => n hours ago
  103. * < 1 month => Yesterday, n days ago
  104. * < 13 month => last month, n months ago
  105. * >= 13 month => last year, n years ago
  106. * @param \OCP\IL10N $l The locale to use
  107. * @return string Formatted time span
  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 $timeZone The timezone to use
  118. * @param \OCP\IL10N $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 $timeZone The timezone to use
  131. * @param \OCP\IL10N $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. }