idatetimeformatter.php 4.7 KB

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