idatetimeformatter.php 5.3 KB

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